UNPKG

@visa/nova-react

Version:

Visa Product Design System Nova React library. Compatible with React ^19.

2 lines (1 loc) 667 B
import{useRef as e}from"react";const t={querySelector:"a[href], button:not([disabled]), textarea:not([disabled]), input:not([disabled]), select:not([disabled])"},n=(n=t)=>{const o=e(null),r={document:"undefined"!=typeof window?document:void 0,...t,...n},u=r.ref||o;return{onKeyNavigation:(e,t=!1)=>{if(!t||!u.current?.querySelectorAll)return;const n=u.current?.querySelectorAll(r.querySelector||""),o=n[0],l=n[n.length-1];t&&"Tab"===e.key&&(e.shiftKey&&r.document?.activeElement===o?(e.preventDefault(),l.focus()):e.shiftKey||r.document?.activeElement!==l||(e.preventDefault(),o.focus()))},ref:u}};n.displayName="useFocusTrap";export{n as default,n as useFocusTrap};