react-focus-bounder
Version:
Focus looping component based on focus bounders.
1 lines • 1.98 kB
JavaScript
(()=>{"use strict";var e={629:function(e,t,n){var r=this&&this.__createBinding||(Object.create?function(e,t,n,r){void 0===r&&(r=n),Object.defineProperty(e,r,{enumerable:!0,get:function(){return t[n]}})}:function(e,t,n,r){void 0===r&&(r=n),e[r]=t[n]}),o=this&&this.__setModuleDefault||(Object.create?function(e,t){Object.defineProperty(e,"default",{enumerable:!0,value:t})}:function(e,t){e.default=t}),u=this&&this.__importStar||function(e){if(e&&e.__esModule)return e;var t={};if(null!=e)for(var n in e)"default"!==n&&Object.prototype.hasOwnProperty.call(e,n)&&r(t,e,n);return o(t,e),t};t.__esModule=!0;var i=u(n(689)),a="FocusBounder-link",l=["a[href]:not(.FocusBounder-link):not([disabled])","[tabindex]:not([tabindex='-1']):not([disabled])","[contenteditable]","button:not([disabled]), input:not([disabled])","select:not([disabled]), textarea:not([disabled])"],d={color:"transparent",opacity:0,position:"absolute",width:"1px",height:"1px",overflow:"hidden"};t.default=function(e){var t=e.children,n=e.firstElementIndex,r=void 0===n?0:n,o=e.focusTimeoutDelay,u=void 0===o?0:o,c=e.isEnabled,s=void 0===c||c,f=(0,i.createRef)(),b=(0,i.useCallback)((function(e){if(s&&f.current){var t=f.current.parentNode,n=null==t?void 0:t.querySelectorAll(l.join(",")),r=n[e<0?n.length+e:e];r&&(r.focus(),u&&document.activeElement!==r&&setTimeout((function(){return r.focus()}),u))}}),[s,f,u]);return(0,i.useEffect)((function(){return b(r)}),[b,r]),i.default.createElement(i.default.Fragment,null,i.default.createElement("a",{ref:f,href:"#bounder",onFocus:function(){return b(-1)},className:a,style:d,"aria-hidden":"true",rel:"nofollow"}," "),t,i.default.createElement("a",{href:"#bounder",onFocus:function(){return b(0)},className:a,style:d,"aria-hidden":"true",rel:"nofollow"}," "))}},689:e=>{e.exports=require("react")}},t={},n=function n(r){var o=t[r];if(void 0!==o)return o.exports;var u=t[r]={exports:{}};return e[r].call(u.exports,u,u.exports,n),u.exports}(629);module.exports=n})();