trap-focus-svelte
Advanced tools
Comparing version 1.0.1 to 1.0.2
@@ -1,1 +0,1 @@ | ||
import{listen as t}from"svelte/internal";let e=[];function o(o,n=1){let c=0;const u=t(document,"keydown",(t=>c=t.shiftKey&&"Tab"==t.key));function f(){const t=[...o.querySelectorAll("*")].filter((t=>t.tabIndex>=0));return[t.at(0)??o,t.at(-1)??o]}let s;function r(){e.push(o),s=document.activeElement,f().at(0).focus()}function i(){e=e.filter((t=>t!=o)),s.focus()}n&&r();const a=t=>e.at(-1)?.contains(t),l=t(o,"focusout",(t=>{if(a(o)){const[e,o]=f();t.target==e&&c?o.focus():t.target!=o||c||e.focus()}})),d=t(document,"focusin",(t=>{if(a(o)&&!a(t.target)){const[t,e]=f();(c?e:t).focus()}}));return{update(t){t?r():i()},destroy(){u(),d(),l(),i()}}}export{o as trapFocus}; | ||
let t=[];function e(t,e,n){return t.addEventListener(e,n),()=>t.removeEventListener(e,n)}function n(n,o=1){let c=0;const u=e(document,"keydown",(t=>c=t.shiftKey&&"Tab"==t.key));function r(){const t=[...n.querySelectorAll("*")].filter((t=>t.tabIndex>=0));return[t.at(0)??n,t.at(-1)??n]}let s;function f(){t.push(n),s=document.activeElement,r().at(0).focus()}function i(){t=t.filter((t=>t!=n)),s.focus()}o&&f();const a=e=>t.at(-1)?.contains(e),d=e(n,"focusout",(t=>{if(a(n)){const[e,n]=r();t.target==e&&c?n.focus():t.target!=n||c||e.focus()}})),l=e(document,"focusin",(t=>{if(a(n)&&!a(t.target)){const[t,e]=r();(c?e:t).focus()}}));return{update(t){t?f():i()},destroy(){u(),l(),d(),i()}}}export{n as trapFocus}; |
@@ -1,5 +0,9 @@ | ||
import { listen } from 'svelte/internal' | ||
let stack: HTMLElement[] = [] | ||
/** adds event listener to node and returns function that removes the listener */ | ||
function listen(node: Node, event: string, handler: EventListenerOrEventListenerObject) { | ||
node.addEventListener(event, handler) | ||
return () => node.removeEventListener(event, handler) | ||
} | ||
/** Traps focus within a wrapper element */ | ||
@@ -6,0 +10,0 @@ function trapFocus(wrap: HTMLElement, active = true) { |
{ | ||
"name": "trap-focus-svelte", | ||
"version": "1.0.1", | ||
"version": "1.0.2", | ||
"license": "MIT", | ||
@@ -5,0 +5,0 @@ "description": "Small 0.4kB focus trap that supports stacking, toggling, and dynamic content. Compatible with any framework.", |
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
12255
166