PIMS/public/build/assets/useArrowNavigation-C6Y-ieo6.js

2 lines
977 B
JavaScript

const I=["INPUT","TEXTAREA"];function v(r,n,e,l={}){if(!n||l.enableIgnoredElement&&I.includes(n.nodeName))return null;const{arrowKeyOptions:o="both",attributeName:i="[data-reka-collection-item]",itemsArray:c=[],loop:t=!0,dir:s="ltr",preventScroll:k=!0,focus:x=!1}=l,[g,w,N,A,h,b]=[r.key==="ArrowRight",r.key==="ArrowLeft",r.key==="ArrowUp",r.key==="ArrowDown",r.key==="Home",r.key==="End"],u=N||A,f=g||w;if(!h&&!b&&(!u&&!f||o==="vertical"&&f||o==="horizontal"&&u))return null;const d=e?Array.from(e.querySelectorAll(i)):c;if(!d.length)return null;k&&r.preventDefault();let a=null;return f||u?a=y(d,n,{goForward:u?A:s==="ltr"?g:w,loop:t}):h?a=d.at(0)||null:b&&(a=d.at(-1)||null),x&&a?.focus(),a}function y(r,n,e,l=r.length){if(--l===0)return null;const o=r.indexOf(n),i=e.goForward?o+1:o-1;if(!e.loop&&(i<0||i>=r.length))return null;const c=(i+r.length)%r.length,t=r[c];return t?t.hasAttribute("disabled")&&t.getAttribute("disabled")!=="false"?y(r,t,e,l):t:null}export{v as u};