UNPKG

fe-essential-utils

Version:
1 lines 1.54 kB
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.AccessibilityUtils=void 0;var _this=void 0,state={cursor:0},searchStr="";String.prototype.startsWith||Object.defineProperty(String.prototype,"startsWith",{value:function(t,e){var r=e>0?0|e:0;return _this.substring(r,r+t.length)===t}});var focusTrap=function(t,e){if(t&&9===e.keyCode){var r=t.querySelectorAll('a[href], area[href], input:not([disabled]), select:not([disabled]), textarea:not([disabled]), button:not([disabled]), [tabindex="0"]');r[r.length-1]===e.target?(e.preventDefault(),r[0].focus()):e.shiftKey&&r[0]===e.target&&(e.preventDefault(),r[r.length-1].focus())}},resetDropdownCursor=function(){state.cursor=0},dropDownNavigation=function(t,e,r,s){var o=e.querySelectorAll(r);if(t.keyCode>=48&&t.keyCode<=90){searchStr+=t.key;var a=Array.from(o).findIndex((function(t){return t.innerHTML.toLowerCase().startsWith(searchStr.toLowerCase())&&t}));return state.cursor=a>=0&&a,o[state.cursor]&&o[state.cursor].focus(),void setTimeout((function(){searchStr=""}),100)}27===t.keyCode&&s(t),9===t.keyCode&&(t.shiftKey?state.cursor-=1:state.cursor+=1),38===t.keyCode&&state.cursor>0?(state.cursor-=1,o[state.cursor]&&o[state.cursor].focus()):40===t.keyCode&&state.cursor<o.length-1&&(state.cursor+=1,o[state.cursor]&&o[state.cursor].focus()),38!==t.keyCode&&40!==t.keyCode||t.preventDefault()},AccessibilityUtils={focusTrap:focusTrap,resetDropdownCursor:resetDropdownCursor,dropDownNavigation:dropDownNavigation};exports.AccessibilityUtils=AccessibilityUtils;