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