@radix-ui/react-focus-scope
Advanced tools
Comparing version 0.0.11 to 0.0.12
@@ -1,25 +0,9 @@ | ||
import * as React from "react"; | ||
type FocusScopeProps = { | ||
children: (args: { | ||
ref: React.RefObject<any>; | ||
}) => React.ReactElement; | ||
/** | ||
* Whether focus should be trapped within the FocusScope | ||
* (default: false) | ||
*/ | ||
trapped?: boolean; | ||
/** | ||
* Event handler called when auto-focusing on mount. | ||
* Can be prevented. | ||
*/ | ||
onMountAutoFocus?: (event: Event) => void; | ||
/** | ||
* Event handler called when auto-focusing on unmount. | ||
* Can be prevented. | ||
*/ | ||
onUnmountAutoFocus?: (event: Event) => void; | ||
export function FocusScope(props: FocusScopeProps): React.ReactElement<any, string | ((props: any) => React.ReactElement<any, any> | null) | (new (props: any) => React.Component<any, any, any>)>; | ||
export type FocusScope = { | ||
paused: boolean; | ||
pause(): void; | ||
resume(): void; | ||
}; | ||
export function FocusScope(props: FocusScopeProps): React.ReactElement<any, string | ((props: any) => React.ReactElement<any, any> | null) | (new (props: any) => React.Component<any, any, any>)>; | ||
export const Root: typeof FocusScope; | ||
//# sourceMappingURL=index.d.ts.map |
@@ -1,2 +0,2 @@ | ||
var e,t,n=require("@radix-ui/react-use-callback-ref").useCallbackRef,o=(e={},t=require("react"),Object.keys(t).forEach((function(n){"default"!==n&&"__esModule"!==n&&Object.defineProperty(e,n,{enumerable:!0,get:function(){return t[n]}})})),e);function u(e){const t=document.activeElement;function n(t){if(o.paused)return;const n="focusout"===t.type?t.relatedTarget:t.target;e.contains(n)||r(e,n)}const o={paused:!1,pause:()=>o.paused=!0,resume:()=>o.paused=!1,trap:function(){document.addEventListener("focusout",n,{capture:!0}),document.addEventListener("focusin",n,{capture:!0})},untrap:function(){document.removeEventListener("focusout",n,{capture:!0}),document.removeEventListener("focusin",n,{capture:!0})},destroy:()=>{!function(e){e.removeAttribute("tabIndex")}(e),o.untrap(),function(){const n=new Event("focusScope.autoFocusOnDestroy",{bubbles:!1,cancelable:!0});e.dispatchEvent(n),n.defaultPrevented||c(t)}(),s.remove(o)}};return s.add(o),function(e){if(e.tabIndex>-1)return;e.tabIndex=-1}(e),function(){const t=new Event("focusScope.autoFocusOnCreate",{bubbles:!1,cancelable:!0});e.dispatchEvent(t),t.defaultPrevented||r(e,null)}(),o}function r(e,t){const n=function(e){return document.createTreeWalker(e,NodeFilter.SHOW_ELEMENT,{acceptNode:e=>e.tabIndex>=0&&!e.disabled?NodeFilter.FILTER_ACCEPT:NodeFilter.FILTER_SKIP})}(e),o=t?t.compareDocumentPosition(e):Node.DOCUMENT_POSITION_PRECEDING;var u;if(o&Node.DOCUMENT_POSITION_PRECEDING)c(null!==(u=n.firstChild())&&void 0!==u?u:e);else if(o&Node.DOCUMENT_POSITION_FOLLOWING){var r;c(null!==(r=n.lastChild())&&void 0!==r?r:e)}}function c(e){e&&e.focus&&(e.focus({preventScroll:!0}),function(e){return e instanceof HTMLInputElement&&"select"in e}(e)&&e.select())}const s=function(){let e=[];return{add(t){const n=e[0];t!==n&&(null==n||n.pause()),e=a(e,t),e.unshift(t)},remove(t){var n;e=a(e,t),null===(n=e[0])||void 0===n||n.resume()},size:()=>e.length}}();function a(e,t){const n=[...e],o=n.indexOf(t);return-1!==o&&n.splice(o,1),n}function i(e){const{children:t,trapped:r=!1}=e,c=o.useRef(null),s=o.useRef(),a=n(e.onMountAutoFocus),i=n(e.onUnmountAutoFocus);return o.useEffect((()=>{const e=c.current;if(e)return e.addEventListener("focusScope.autoFocusOnCreate",a),e.addEventListener("focusScope.autoFocusOnDestroy",i),s.current=u(e),()=>{e.removeEventListener("focusScope.autoFocusOnCreate",a),setTimeout((()=>{var t;null===(t=s.current)||void 0===t||t.destroy(),e.removeEventListener("focusScope.autoFocusOnDestroy",i)}),0)}}),[c,a,i]),o.useEffect((()=>{var e;if(r)return null===(e=s.current)||void 0===e||e.trap(),()=>{var e;return null===(e=s.current)||void 0===e?void 0:e.untrap()}}),[r]),t({ref:c})}exports.FocusScope=i;const d=i;exports.Root=d; | ||
var e,t,n=require("@radix-ui/react-use-callback-ref").useCallbackRef,u=(e={},t=require("react"),Object.keys(t).forEach((function(n){"default"!==n&&"__esModule"!==n&&Object.defineProperty(e,n,{enumerable:!0,get:function(){return t[n]}})})),e);const o={bubbles:!1,cancelable:!0};function c(e){const{children:t,trapped:c=!1}=e,[i,f]=u.useState(null),l=n(e.onMountAutoFocus),p=n(e.onUnmountAutoFocus),m=u.useRef(null),v=c,E=c,b=u.useRef({paused:!1,pause(){this.paused=!0},resume(){this.paused=!1}}).current;u.useEffect((()=>{if(i){d.add(b);const e=document.activeElement;i.addEventListener("focusScope.autoFocusOnMount",l),i.addEventListener("focusScope.autoFocusOnUnmount",p);const t=new Event("focusScope.autoFocusOnMount",o);return i.dispatchEvent(t),t.defaultPrevented||(!function(e,{select:t=!1}={}){const n=document.activeElement;for(const u of e)if(a(u,{select:t}),document.activeElement!==n)return}(r(i),{select:!0}),document.activeElement===e&&a(i)),()=>{i.removeEventListener("focusScope.autoFocusOnMount",l),setTimeout((()=>{const t=new Event("focusScope.autoFocusOnUnmount",o);i.dispatchEvent(t),t.defaultPrevented||a(null!=e?e:document.body,{select:!0}),i.removeEventListener("focusScope.autoFocusOnUnmount",p),d.remove(b)}),0)}}}),[i,l,p,b]);const F=u.useCallback((e=>{if(!v&&!E)return;if(b.paused)return;const t="Tab"===e.key&&!e.altKey&&!e.ctrlKey&&!e.metaKey,n=document.activeElement;if(t&&n){const t=e.currentTarget,[u,o]=function(e){const t=r(e),n=s(t,e),u=s(t.reverse(),e);return[n,u]}(t);u&&o?e.shiftKey||n!==o?e.shiftKey&&n===u&&(e.preventDefault(),v&&a(o,{select:!0})):(e.preventDefault(),v&&a(u,{select:!0})):n===t&&e.preventDefault()}}),[v,E,b.paused]);return u.useEffect((()=>{if(E){function e(e){if(b.paused||!i)return;const t=e.target;i.contains(t)?m.current=t:a(m.current,{select:!0})}function t(e){!b.paused&&i&&(i.contains(e.relatedTarget)||a(m.current,{select:!0}))}return document.addEventListener("focusin",e),document.addEventListener("focusout",t),()=>{document.removeEventListener("focusin",e),document.removeEventListener("focusout",t)}}}),[E,i,b.paused]),t({ref:u.useCallback((e=>f(e)),[]),tabIndex:-1,onKeyDown:F})}function r(e){const t=[],n=document.createTreeWalker(e,NodeFilter.SHOW_ELEMENT,{acceptNode:e=>{const t="INPUT"===e.tagName&&"hidden"===e.type;return e.disabled||e.hidden||t?NodeFilter.FILTER_SKIP:e.tabIndex>=0?NodeFilter.FILTER_ACCEPT:NodeFilter.FILTER_SKIP}});for(;n.nextNode();)t.push(n.currentNode);return t}function s(e,t){for(const n of e)if(!i(n,{upTo:t}))return n}function i(e,{upTo:t}){if("hidden"===getComputedStyle(e).visibility)return!0;for(;e;){if(void 0!==t&&e===t)return!1;if("none"===getComputedStyle(e).display)return!0;e=e.parentElement}return!1}function a(e,{select:t=!1}={}){if(e&&e.focus){const n=document.activeElement;e.focus({preventScroll:!0}),e!==n&&function(e){return e instanceof HTMLInputElement&&"select"in e}(e)&&t&&e.select()}}exports.FocusScope=c;const d=function(){let e=[];return{add(t){const n=e[0];t!==n&&(null==n||n.pause()),e=f(e,t),e.unshift(t)},remove(t){var n;e=f(e,t),null===(n=e[0])||void 0===n||n.resume()}}}();function f(e,t){const n=[...e],u=n.indexOf(t);return-1!==u&&n.splice(u,1),n}const l=c;exports.Root=l; | ||
//# sourceMappingURL=index.js.map |
@@ -1,2 +0,2 @@ | ||
import{useCallbackRef as e}from"@radix-ui/react-use-callback-ref";import*as t from"react";function n(e){const t=document.activeElement;function n(t){if(c.paused)return;const n="focusout"===t.type?t.relatedTarget:t.target;e.contains(n)||o(e,n)}const c={paused:!1,pause:()=>c.paused=!0,resume:()=>c.paused=!1,trap:function(){document.addEventListener("focusout",n,{capture:!0}),document.addEventListener("focusin",n,{capture:!0})},untrap:function(){document.removeEventListener("focusout",n,{capture:!0}),document.removeEventListener("focusin",n,{capture:!0})},destroy:()=>{!function(e){e.removeAttribute("tabIndex")}(e),c.untrap(),function(){const n=new Event("focusScope.autoFocusOnDestroy",{bubbles:!1,cancelable:!0});e.dispatchEvent(n),n.defaultPrevented||u(t)}(),r.remove(c)}};return r.add(c),function(e){if(e.tabIndex>-1)return;e.tabIndex=-1}(e),function(){const t=new Event("focusScope.autoFocusOnCreate",{bubbles:!1,cancelable:!0});e.dispatchEvent(t),t.defaultPrevented||o(e,null)}(),c}function o(e,t){const n=function(e){return document.createTreeWalker(e,NodeFilter.SHOW_ELEMENT,{acceptNode:e=>e.tabIndex>=0&&!e.disabled?NodeFilter.FILTER_ACCEPT:NodeFilter.FILTER_SKIP})}(e),o=t?t.compareDocumentPosition(e):Node.DOCUMENT_POSITION_PRECEDING;var r;if(o&Node.DOCUMENT_POSITION_PRECEDING)u(null!==(r=n.firstChild())&&void 0!==r?r:e);else if(o&Node.DOCUMENT_POSITION_FOLLOWING){var c;u(null!==(c=n.lastChild())&&void 0!==c?c:e)}}function u(e){e&&e.focus&&(e.focus({preventScroll:!0}),function(e){return e instanceof HTMLInputElement&&"select"in e}(e)&&e.select())}const r=function(){let e=[];return{add(t){const n=e[0];t!==n&&(null==n||n.pause()),e=c(e,t),e.unshift(t)},remove(t){var n;e=c(e,t),null===(n=e[0])||void 0===n||n.resume()},size:()=>e.length}}();function c(e,t){const n=[...e],o=n.indexOf(t);return-1!==o&&n.splice(o,1),n}export function FocusScope(o){const{children:u,trapped:r=!1}=o,c=t.useRef(null),s=t.useRef(),a=e(o.onMountAutoFocus),i=e(o.onUnmountAutoFocus);return t.useEffect((()=>{const e=c.current;if(e)return e.addEventListener("focusScope.autoFocusOnCreate",a),e.addEventListener("focusScope.autoFocusOnDestroy",i),s.current=n(e),()=>{e.removeEventListener("focusScope.autoFocusOnCreate",a),setTimeout((()=>{var t;null===(t=s.current)||void 0===t||t.destroy(),e.removeEventListener("focusScope.autoFocusOnDestroy",i)}),0)}}),[c,a,i]),t.useEffect((()=>{var e;if(r)return null===(e=s.current)||void 0===e||e.trap(),()=>{var e;return null===(e=s.current)||void 0===e?void 0:e.untrap()}}),[r]),u({ref:c})}export const Root=FocusScope; | ||
import{useCallbackRef as e}from"@radix-ui/react-use-callback-ref";import*as t from"react";const n={bubbles:!1,cancelable:!0};export function FocusScope(c){const{children:i,trapped:a=!1}=c,[d,f]=t.useState(null),l=e(c.onMountAutoFocus),m=e(c.onUnmountAutoFocus),p=t.useRef(null),v=a,E=a,F=t.useRef({paused:!1,pause(){this.paused=!0},resume(){this.paused=!1}}).current;t.useEffect((()=>{if(d){s.add(F);const e=document.activeElement;d.addEventListener("focusScope.autoFocusOnMount",l),d.addEventListener("focusScope.autoFocusOnUnmount",m);const t=new Event("focusScope.autoFocusOnMount",n);return d.dispatchEvent(t),t.defaultPrevented||(!function(e,{select:t=!1}={}){const n=document.activeElement;for(const o of e)if(r(o,{select:t}),document.activeElement!==n)return}(o(d),{select:!0}),document.activeElement===e&&r(d)),()=>{d.removeEventListener("focusScope.autoFocusOnMount",l),setTimeout((()=>{const t=new Event("focusScope.autoFocusOnUnmount",n);d.dispatchEvent(t),t.defaultPrevented||r(null!=e?e:document.body,{select:!0}),d.removeEventListener("focusScope.autoFocusOnUnmount",m),s.remove(F)}),0)}}}),[d,l,m,F]);const S=t.useCallback((e=>{if(!v&&!E)return;if(F.paused)return;const t="Tab"===e.key&&!e.altKey&&!e.ctrlKey&&!e.metaKey,n=document.activeElement;if(t&&n){const t=e.currentTarget,[c,s]=function(e){const t=o(e),n=u(t,e),c=u(t.reverse(),e);return[n,c]}(t);c&&s?e.shiftKey||n!==s?e.shiftKey&&n===c&&(e.preventDefault(),v&&r(s,{select:!0})):(e.preventDefault(),v&&r(c,{select:!0})):n===t&&e.preventDefault()}}),[v,E,F.paused]);return t.useEffect((()=>{if(E){function e(e){if(F.paused||!d)return;const t=e.target;d.contains(t)?p.current=t:r(p.current,{select:!0})}function t(e){!F.paused&&d&&(d.contains(e.relatedTarget)||r(p.current,{select:!0}))}return document.addEventListener("focusin",e),document.addEventListener("focusout",t),()=>{document.removeEventListener("focusin",e),document.removeEventListener("focusout",t)}}}),[E,d,F.paused]),i({ref:t.useCallback((e=>f(e)),[]),tabIndex:-1,onKeyDown:S})}function o(e){const t=[],n=document.createTreeWalker(e,NodeFilter.SHOW_ELEMENT,{acceptNode:e=>{const t="INPUT"===e.tagName&&"hidden"===e.type;return e.disabled||e.hidden||t?NodeFilter.FILTER_SKIP:e.tabIndex>=0?NodeFilter.FILTER_ACCEPT:NodeFilter.FILTER_SKIP}});for(;n.nextNode();)t.push(n.currentNode);return t}function u(e,t){for(const n of e)if(!c(n,{upTo:t}))return n}function c(e,{upTo:t}){if("hidden"===getComputedStyle(e).visibility)return!0;for(;e;){if(void 0!==t&&e===t)return!1;if("none"===getComputedStyle(e).display)return!0;e=e.parentElement}return!1}function r(e,{select:t=!1}={}){if(e&&e.focus){const n=document.activeElement;e.focus({preventScroll:!0}),e!==n&&function(e){return e instanceof HTMLInputElement&&"select"in e}(e)&&t&&e.select()}}const s=function(){let e=[];return{add(t){const n=e[0];t!==n&&(null==n||n.pause()),e=i(e,t),e.unshift(t)},remove(t){var n;e=i(e,t),null===(n=e[0])||void 0===n||n.resume()}}}();function i(e,t){const n=[...e],o=n.indexOf(t);return-1!==o&&n.splice(o,1),n}export const Root=FocusScope; | ||
//# sourceMappingURL=index.module.js.map |
{ | ||
"name": "@radix-ui/react-focus-scope", | ||
"version": "0.0.11", | ||
"version": "0.0.12", | ||
"license": "MIT", | ||
@@ -5,0 +5,0 @@ "source": "src/index.ts", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
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
41710
35