reakit-utils
Advanced tools
Comparing version 0.6.3 to 0.6.4
@@ -6,2 +6,14 @@ # Change Log | ||
## [0.6.4](https://github.com/reakit/reakit/tree/master/packages/reakit-utils/compare/reakit-utils@0.6.3...reakit-utils@0.6.4) (2019-09-19) | ||
### Bug Fixes | ||
* Fix `Dialog` initial focus ([#433](https://github.com/reakit/reakit/tree/master/packages/reakit-utils/issues/433)) ([a0916c7](https://github.com/reakit/reakit/tree/master/packages/reakit-utils/commit/a0916c7)) | ||
* Fix `Dialog` with `tabIndex={0}` not being included in the tab order ([#426](https://github.com/reakit/reakit/tree/master/packages/reakit-utils/issues/426)) ([bfb1d05](https://github.com/reakit/reakit/tree/master/packages/reakit-utils/commit/bfb1d05)) | ||
## [0.6.3](https://github.com/reakit/reakit/tree/master/packages/reakit-utils/compare/reakit-utils@0.6.2...reakit-utils@0.6.3) (2019-08-25) | ||
@@ -8,0 +20,0 @@ |
@@ -1,1 +0,1 @@ | ||
!function(e,n){"object"==typeof exports&&"undefined"!=typeof module?n(exports,require("react")):"function"==typeof define&&define.amd?define(["exports","react"],n):n((e=e||self).ReakitUtils={},e.React)}(this,function(e,n){"use strict";function t(e){return"object"==typeof e&&null!=e}function r(e,n){return-1===n?e:[].concat(e.slice(0,n),e.slice(n+1))}var o="input, select, textarea, a[href], button, [tabindex], audio[controls], video[controls], [contenteditable]:not([contenteditable=false])";function u(e){return e instanceof HTMLElement}function i(e){return e.hasAttribute("tabindex")}function a(e){if(!u(e))return!1;if(function e(n){return!(!n.parentElement||!e(n.parentElement))||n.hidden}(e))return!1;if(function(e){return Boolean(e.disabled)}(e))return!1;var n=e.localName;if(["input","select","textarea","button"].indexOf(n)>=0)return!0;var t={a:function(){return e.hasAttribute("href")},audio:function(){return e.hasAttribute("controls")},video:function(){return e.hasAttribute("controls")}};return n in t?t[n]():!!function(e){var n=e.getAttribute("contenteditable");return"false"!==n&&null!=n}(e)||i(e)}function f(e){return!!u(e)&&(!!a(e)&&!function(e){return i(e)&&e.tabIndex<0}(e))}function c(e){return Array.from(e.querySelectorAll(o)).filter(a)}function l(e,n){var t=Array.from(e.querySelectorAll(o)),r=t.filter(f);return!r.length&&n?t:r}function s(e,n){var t=c(e),r=t.indexOf(document.activeElement),o=t.slice(r+1);return o.find(f)||t.find(f)||(n?o[0]:null)}function v(e,n){var t=c(e).reverse(),r=t.indexOf(document.activeElement),o=t.slice(r+1);return o.find(f)||t.find(f)||(n?o[0]:null)}var d="id-",b=n.createContext(function(e){return void 0===e&&(e=d),""+e+Math.random().toString(32).substr(2,6)});e.IdProvider=function(e){var t=e.children,r=e.unstable_prefix,o=void 0===r?"":r,u=n.useRef(0),i=n.useMemo(function(){return function(e){return void 0===e&&(e=d),""+o+e+ ++u.current}},[o]);return n.createElement(b.Provider,{value:i},t)},e.createOnKeyDown=function(e){var n=void 0===e?{}:e,t=n.keyMap,r=n.onKey,o=n.stopPropagation,u=n.onKeyDown,i=n.shouldKeyDown,a=void 0===i?function(){return!0}:i,f=n.preventDefault,c=void 0===f||f;return function(e){if(t){var n="function"==typeof t?t(e):t,i="function"==typeof c?c(e):c,f="function"==typeof o?o(e):o;if(e.key in n){var l=n[e.key];if("function"==typeof l&&a(e))return i&&e.preventDefault(),f&&e.stopPropagation(),r&&r(e),void l(e)}u&&u(e)}}},e.cx=function(){for(var e=arguments.length,n=new Array(e),t=0;t<e;t++)n[t]=arguments[t];return n.filter(Boolean).join(" ")||void 0},e.focusNextTabbableIn=function(e,n){var t=s(e,n);t&&u(t)&&t.focus()},e.focusPreviousTabbableIn=function(e,n){var t=v(e,n);t&&u(t)&&t.focus()},e.getAllFocusableIn=c,e.getAllTabbableIn=l,e.getFirstFocusableIn=function(e){var n=c(e);return n.length?n[0]:null},e.getFirstTabbableIn=function(e,n){return l(e,n)[0]||null},e.getLastTabbableIn=function(e,n){var t=l(e,n);return t[t.length-1]||null},e.getNextTabbableIn=s,e.getPreviousTabbableIn=v,e.hasFocusWithin=function(e){return!!document.activeElement&&e.contains(document.activeElement)},e.isEmpty=function(e){return Array.isArray(e)?!e.length:t(e)?!Object.keys(e).length:null==e||""===e},e.isFocusable=a,e.isInteger=function(e){return"number"==typeof e?Math.floor(e)===e:String(Math.floor(Number(e)))===e},e.isObject=t,e.isPromise=function(e){return Boolean(e&&e.then)},e.isTabbable=f,e.mergeRefs=function(){for(var e=arguments.length,n=new Array(e),t=0;t<e;t++)n[t]=arguments[t];var r=n.filter(Boolean);return r.length?0===r.length?r[0]:function(e){var n=r,t=Array.isArray(n),o=0;for(n=t?n:n[Symbol.iterator]();;){var u;if(t){if(o>=n.length)break;u=n[o++]}else{if((o=n.next()).done)break;u=o.value}var i=u;"function"==typeof i?i(e):i&&(i.current=e)}}:null},e.omit=function(e,n){for(var t=Object.keys(e),r={},o=0;o<t.length;o+=1){var u=t[o];-1===n.indexOf(u)&&(r[u]=e[u])}return r},e.pick=function(e,n){for(var t=Object.keys(e),r={},o=0;o<t.length;o+=1){var u=t[o];n.indexOf(u)>=0&&(r[u]=e[u])}return r},e.removeIndexFromArray=r,e.removeItemFromArray=function(e,n){var t=e.indexOf(n);return r(e,t)},e.splitProps=function(e,n){for(var t={},r={},o=0,u=Object.keys(e);o<u.length;o++){var i=u[o];n.indexOf(i)>=0?t[i]=e[i]:r[i]=e[i]}return[t,r]},e.toArray=function(e){return Array.isArray(e)?e:void 0!==e?[e]:[]},e.useAllCallbacks=function(){for(var e=arguments.length,t=new Array(e),r=0;r<e;r++)t[r]=arguments[r];return n.useCallback(function(){var e=t.filter(Boolean),n=e,r=Array.isArray(n),o=0;for(n=r?n:n[Symbol.iterator]();;){var u;if(r){if(o>=n.length)break;u=n[o++]}else{if((o=n.next()).done)break;u=o.value}var i=u;i.apply(void 0,arguments)}},t)},e.useId=function(e){void 0===e&&(e=d);var t=n.useContext(b);return n.useState(function(){return t(e)})[0]},e.useLiveRef=function(e){var t=n.useRef(e);return n.useEffect(function(){t.current=e}),t},e.usePipe=function(){for(var e=arguments.length,t=new Array(e),r=0;r<e;r++)t[r]=arguments[r];return n.useCallback(function(e){return t.filter(Boolean).reduce(function(e,n){return n(e)},e)},t)},e.useSealedState=function(e){return n.useState(e)[0]},e.useUpdateEffect=function(e,t){var r=n.useRef(!1);n.useEffect(function(){if(r.current)return e();r.current=!0},t)},e.warning=function(e,n){},Object.defineProperty(e,"__esModule",{value:!0})}); | ||
!function(e,n){"object"==typeof exports&&"undefined"!=typeof module?n(exports,require("react")):"function"==typeof define&&define.amd?define(["exports","react"],n):n((e=e||self).ReakitUtils={},e.React)}(this,function(e,n){"use strict";function t(e){return"object"==typeof e&&null!=e}function r(e,n){return-1===n?e:[].concat(e.slice(0,n),e.slice(n+1))}var o="input, select, textarea, a[href], button, [tabindex], audio[controls], video[controls], [contenteditable]:not([contenteditable=false])";function u(e){return e instanceof HTMLElement}function i(e){return e.hasAttribute("tabindex")}function a(e){if(!u(e))return!1;if(function e(n){return!(!n.parentElement||!e(n.parentElement))||n.hidden}(e))return!1;if(function(e){return Boolean(e.disabled)}(e))return!1;var n=e.localName;if(["input","select","textarea","button"].indexOf(n)>=0)return!0;var t={a:function(){return e.hasAttribute("href")},audio:function(){return e.hasAttribute("controls")},video:function(){return e.hasAttribute("controls")}};return n in t?t[n]():!!function(e){var n=e.getAttribute("contenteditable");return"false"!==n&&null!=n}(e)||i(e)}function f(e){return u(e)&&a(e)&&!function(e){return i(e)&&e.tabIndex<0}(e)}function c(e){var n=Array.from(e.querySelectorAll(o));return n.unshift(e),n.filter(a)}function l(e,n){var t=Array.from(e.querySelectorAll(o)),r=t.filter(f);return f(e)&&r.unshift(e),!r.length&&n?t:r}function s(e,n){var t=c(e),r=t.indexOf(document.activeElement),o=t.slice(r+1);return o.find(f)||t.find(f)||(n?o[0]:null)}function v(e,n){var t=c(e).reverse(),r=t.indexOf(document.activeElement),o=t.slice(r+1);return o.find(f)||t.find(f)||(n?o[0]:null)}function d(e){return document.activeElement===e}var b="id-",y=n.createContext(function(e){return void 0===e&&(e=b),""+e+Math.random().toString(32).substr(2,6)});e.IdProvider=function(e){var t=e.children,r=e.unstable_prefix,o=void 0===r?"":r,u=n.useRef(0),i=n.useMemo(function(){return function(e){return void 0===e&&(e=b),""+o+e+ ++u.current}},[o]);return n.createElement(y.Provider,{value:i},t)},e.createOnKeyDown=function(e){var n=void 0===e?{}:e,t=n.keyMap,r=n.onKey,o=n.stopPropagation,u=n.onKeyDown,i=n.shouldKeyDown,a=void 0===i?function(){return!0}:i,f=n.preventDefault,c=void 0===f||f;return function(e){if(t){var n="function"==typeof t?t(e):t,i="function"==typeof c?c(e):c,f="function"==typeof o?o(e):o;if(e.key in n){var l=n[e.key];if("function"==typeof l&&a(e))return i&&e.preventDefault(),f&&e.stopPropagation(),r&&r(e),void l(e)}u&&u(e)}}},e.cx=function(){for(var e=arguments.length,n=new Array(e),t=0;t<e;t++)n[t]=arguments[t];return n.filter(Boolean).join(" ")||void 0},e.focusNextTabbableIn=function(e,n){var t=s(e,n);t&&u(t)&&t.focus()},e.focusPreviousTabbableIn=function(e,n){var t=v(e,n);t&&u(t)&&t.focus()},e.forceFocus=function(e,n){var t=void 0===n?{}:n,r=t.isActive,o=void 0===r?d:r,u=t.preventScroll;return o(e)?-1:(e.focus({preventScroll:u}),o(e)?-1:requestAnimationFrame(function(){e.focus({preventScroll:u})}))},e.getAllFocusableIn=c,e.getAllTabbableIn=l,e.getFirstFocusableIn=function(e){var n=c(e);return n.length?n[0]:null},e.getFirstTabbableIn=function(e,n){return l(e,n)[0]||null},e.getLastTabbableIn=function(e,n){var t=l(e,n);return t[t.length-1]||null},e.getNextTabbableIn=s,e.getPreviousTabbableIn=v,e.hasFocusWithin=function(e){return!!document.activeElement&&e.contains(document.activeElement)},e.isEmpty=function(e){return Array.isArray(e)?!e.length:t(e)?!Object.keys(e).length:null==e||""===e},e.isFocusable=a,e.isInteger=function(e){return"number"==typeof e?Math.floor(e)===e:String(Math.floor(Number(e)))===e},e.isObject=t,e.isPromise=function(e){return Boolean(e&&e.then)},e.isTabbable=f,e.mergeRefs=function(){for(var e=arguments.length,n=new Array(e),t=0;t<e;t++)n[t]=arguments[t];var r=n.filter(Boolean);return r.length?0===r.length?r[0]:function(e){var n=r,t=Array.isArray(n),o=0;for(n=t?n:n[Symbol.iterator]();;){var u;if(t){if(o>=n.length)break;u=n[o++]}else{if((o=n.next()).done)break;u=o.value}var i=u;"function"==typeof i?i(e):i&&(i.current=e)}}:null},e.omit=function(e,n){for(var t=Object.keys(e),r={},o=0;o<t.length;o+=1){var u=t[o];-1===n.indexOf(u)&&(r[u]=e[u])}return r},e.pick=function(e,n){for(var t=Object.keys(e),r={},o=0;o<t.length;o+=1){var u=t[o];n.indexOf(u)>=0&&(r[u]=e[u])}return r},e.removeIndexFromArray=r,e.removeItemFromArray=function(e,n){var t=e.indexOf(n);return r(e,t)},e.splitProps=function(e,n){for(var t={},r={},o=0,u=Object.keys(e);o<u.length;o++){var i=u[o];n.indexOf(i)>=0?t[i]=e[i]:r[i]=e[i]}return[t,r]},e.toArray=function(e){return Array.isArray(e)?e:void 0!==e?[e]:[]},e.useAllCallbacks=function(){for(var e=arguments.length,t=new Array(e),r=0;r<e;r++)t[r]=arguments[r];return n.useCallback(function(){var e=t.filter(Boolean),n=e,r=Array.isArray(n),o=0;for(n=r?n:n[Symbol.iterator]();;){var u;if(r){if(o>=n.length)break;u=n[o++]}else{if((o=n.next()).done)break;u=o.value}var i=u;i.apply(void 0,arguments)}},t)},e.useId=function(e){void 0===e&&(e=b);var t=n.useContext(y);return n.useState(function(){return t(e)})[0]},e.useLiveRef=function(e){var t=n.useRef(e);return n.useEffect(function(){t.current=e}),t},e.usePipe=function(){for(var e=arguments.length,t=new Array(e),r=0;r<e;r++)t[r]=arguments[r];return n.useCallback(function(e){return t.filter(Boolean).reduce(function(e,n){return n(e)},e)},t)},e.useSealedState=function(e){return n.useState(e)[0]},e.useUpdateEffect=function(e,t){var r=n.useRef(!1);n.useEffect(function(){if(r.current)return e();r.current=!0},t)},e.warning=function(e,n){},Object.defineProperty(e,"__esModule",{value:!0})}); |
@@ -10,3 +10,3 @@ export { warning } from './warning.js'; | ||
export { toArray } from './toArray.js'; | ||
export { focusNextTabbableIn, focusPreviousTabbableIn, getAllFocusableIn, getAllTabbableIn, getFirstFocusableIn, getFirstTabbableIn, getLastTabbableIn, getNextTabbableIn, getPreviousTabbableIn, isFocusable, isTabbable } from './tabbable.js'; | ||
export { focusNextTabbableIn, focusPreviousTabbableIn, forceFocus, getAllFocusableIn, getAllTabbableIn, getFirstFocusableIn, getFirstTabbableIn, getLastTabbableIn, getNextTabbableIn, getPreviousTabbableIn, isFocusable, isTabbable } from './tabbable.js'; | ||
export { splitProps } from './splitProps.js'; | ||
@@ -13,0 +13,0 @@ export { removeIndexFromArray } from './removeIndexFromArray.js'; |
@@ -56,9 +56,7 @@ var selector = "input, select, textarea, a[href], button, [tabindex], audio[controls], video[controls], [contenteditable]:not([contenteditable=false])"; | ||
function isTabbable(element) { | ||
if (!isHTMLElement(element)) return false; | ||
if (!isFocusable(element)) return false; | ||
if (hasNegativeTabIndex(element)) return false; | ||
return true; | ||
return isHTMLElement(element) && isFocusable(element) && !hasNegativeTabIndex(element); | ||
} | ||
function getAllFocusableIn(container) { | ||
var allFocusable = Array.from(container.querySelectorAll(selector)); | ||
allFocusable.unshift(container); | ||
return allFocusable.filter(isFocusable); | ||
@@ -74,2 +72,6 @@ } | ||
if (isTabbable(container)) { | ||
allTabbable.unshift(container); | ||
} | ||
if (!allTabbable.length && fallbackToFocusable) { | ||
@@ -118,2 +120,24 @@ return allFocusable; | ||
export { focusNextTabbableIn, focusPreviousTabbableIn, getAllFocusableIn, getAllTabbableIn, getFirstFocusableIn, getFirstTabbableIn, getLastTabbableIn, getNextTabbableIn, getPreviousTabbableIn, isFocusable, isTabbable }; | ||
function defaultIsActive(element) { | ||
return document.activeElement === element; | ||
} | ||
function forceFocus(element, _temp) { | ||
var _ref = _temp === void 0 ? {} : _temp, | ||
_ref$isActive = _ref.isActive, | ||
isActive = _ref$isActive === void 0 ? defaultIsActive : _ref$isActive, | ||
preventScroll = _ref.preventScroll; | ||
if (isActive(element)) return -1; | ||
element.focus({ | ||
preventScroll: preventScroll | ||
}); | ||
if (isActive(element)) return -1; | ||
return requestAnimationFrame(function () { | ||
element.focus({ | ||
preventScroll: preventScroll | ||
}); | ||
}); | ||
} | ||
export { focusNextTabbableIn, focusPreviousTabbableIn, forceFocus, getAllFocusableIn, getAllTabbableIn, getFirstFocusableIn, getFirstTabbableIn, getLastTabbableIn, getNextTabbableIn, getPreviousTabbableIn, isFocusable, isTabbable }; |
@@ -42,2 +42,3 @@ 'use strict'; | ||
exports.focusPreviousTabbableIn = tabbable.focusPreviousTabbableIn; | ||
exports.forceFocus = tabbable.forceFocus; | ||
exports.getAllFocusableIn = tabbable.getAllFocusableIn; | ||
@@ -44,0 +45,0 @@ exports.getAllTabbableIn = tabbable.getAllTabbableIn; |
@@ -60,9 +60,7 @@ 'use strict'; | ||
function isTabbable(element) { | ||
if (!isHTMLElement(element)) return false; | ||
if (!isFocusable(element)) return false; | ||
if (hasNegativeTabIndex(element)) return false; | ||
return true; | ||
return isHTMLElement(element) && isFocusable(element) && !hasNegativeTabIndex(element); | ||
} | ||
function getAllFocusableIn(container) { | ||
var allFocusable = Array.from(container.querySelectorAll(selector)); | ||
allFocusable.unshift(container); | ||
return allFocusable.filter(isFocusable); | ||
@@ -78,2 +76,6 @@ } | ||
if (isTabbable(container)) { | ||
allTabbable.unshift(container); | ||
} | ||
if (!allTabbable.length && fallbackToFocusable) { | ||
@@ -122,4 +124,27 @@ return allFocusable; | ||
function defaultIsActive(element) { | ||
return document.activeElement === element; | ||
} | ||
function forceFocus(element, _temp) { | ||
var _ref = _temp === void 0 ? {} : _temp, | ||
_ref$isActive = _ref.isActive, | ||
isActive = _ref$isActive === void 0 ? defaultIsActive : _ref$isActive, | ||
preventScroll = _ref.preventScroll; | ||
if (isActive(element)) return -1; | ||
element.focus({ | ||
preventScroll: preventScroll | ||
}); | ||
if (isActive(element)) return -1; | ||
return requestAnimationFrame(function () { | ||
element.focus({ | ||
preventScroll: preventScroll | ||
}); | ||
}); | ||
} | ||
exports.focusNextTabbableIn = focusNextTabbableIn; | ||
exports.focusPreviousTabbableIn = focusPreviousTabbableIn; | ||
exports.forceFocus = forceFocus; | ||
exports.getAllFocusableIn = getAllFocusableIn; | ||
@@ -126,0 +151,0 @@ exports.getAllTabbableIn = getAllTabbableIn; |
{ | ||
"name": "reakit-utils", | ||
"version": "0.6.3", | ||
"version": "0.6.4", | ||
"description": "Reakit utils", | ||
@@ -36,4 +36,3 @@ "sideEffects": false, | ||
"react-dom": "^16.8.0" | ||
}, | ||
"gitHead": "c2fb790b3a92211382c7e7a2bf751d0d723f62c3" | ||
} | ||
} |
@@ -56,6 +56,7 @@ const selector = | ||
export function isTabbable(element: Element) { | ||
if (!isHTMLElement(element)) return false; | ||
if (!isFocusable(element)) return false; | ||
if (hasNegativeTabIndex(element)) return false; | ||
return true; | ||
return ( | ||
isHTMLElement(element) && | ||
isFocusable(element) && | ||
!hasNegativeTabIndex(element) | ||
); | ||
} | ||
@@ -65,2 +66,3 @@ | ||
const allFocusable = Array.from(container.querySelectorAll<T>(selector)); | ||
allFocusable.unshift(container); | ||
return allFocusable.filter(isFocusable); | ||
@@ -80,2 +82,7 @@ } | ||
const allTabbable = allFocusable.filter(isTabbable); | ||
if (isTabbable(container)) { | ||
allTabbable.unshift(container); | ||
} | ||
if (!allTabbable.length && fallbackToFocusable) { | ||
@@ -153,1 +160,24 @@ return allFocusable; | ||
} | ||
function defaultIsActive(element: Element) { | ||
return document.activeElement === element; | ||
} | ||
type ForceFocusOptions = FocusOptions & { | ||
isActive?: typeof defaultIsActive; | ||
}; | ||
export function forceFocus( | ||
element: HTMLElement, | ||
{ isActive = defaultIsActive, preventScroll }: ForceFocusOptions = {} | ||
) { | ||
if (isActive(element)) return -1; | ||
element.focus({ preventScroll }); | ||
if (isActive(element)) return -1; | ||
return requestAnimationFrame(() => { | ||
element.focus({ preventScroll }); | ||
}); | ||
} |
@@ -12,1 +12,7 @@ export declare function isFocusable(element: Element): boolean; | ||
export declare function focusPreviousTabbableIn<T extends Element>(container: T, fallbackToFocusable?: boolean): void; | ||
declare function defaultIsActive(element: Element): boolean; | ||
declare type ForceFocusOptions = FocusOptions & { | ||
isActive?: typeof defaultIsActive; | ||
}; | ||
export declare function forceFocus(element: HTMLElement, { isActive, preventScroll }?: ForceFocusOptions): number; | ||
export {}; |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
1962
268356