UNPKG

@dialpad/dialtone

Version:

Dialpad's Dialtone design system monorepo

3 lines (2 loc) 1.69 kB
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const r=require("../utils/index.cjs"),o=':not(:disabled):not([aria-disabled="true"]):not([role="presentation"])',a=`${o}:not([tabindex="-1"])`,u="button,[href],input,select,textarea,details,[tabindex]",c={methods:{async getFirstFocusableElement(e){await this.$nextTick();const t=this._getFocusableElements(e,!0);return this._getFirstFocusElement(t)},async focusFirstElement(e=this.$el){const t=await this.getFirstFocusableElement(r.returnFirstEl(e));t==null||t.focus({preventScroll:!0})},async focusElementById(e){var s;await this.$nextTick();const t=(s=r.returnFirstEl(this.$el))==null?void 0:s.querySelector(e);if(t){t.focus();return}console.warn('Could not find the element specified in dt-modal prop "initialFocusElement". Defaulting to focusing the first element.'),await this.focusFirstElement()},_getFirstFocusElement(e){if(!e.length)return;let t=e[0];return t.matches('[type="radio"]:not(:checked)')&&(t=e.find(s=>s.checked&&s.name===t.name)||t),t},_getFocusableElements(e=this.$el,t=!1){return e=r.returnFirstEl(e),e?[...e.querySelectorAll(u)].filter(n=>{const i=window.getComputedStyle(n);return i.getPropertyValue("display")!=="none"&&i.getPropertyValue("visibility")!=="hidden"&&n.matches(t?o:a)}):[]},focusTrappedTabPress(e,t){if(!(e.key==="Tab"))return;const n=this._getFocusableElements(t);if(!n.length){e.preventDefault();return}const i=this._getFirstFocusElement(n),l=n[n.length-1];e.shiftKey?document.activeElement===i&&(l.focus(),e.preventDefault()):document.activeElement===l&&(i.focus(),e.preventDefault())}}};exports.default=c; //# sourceMappingURL=modal.cjs.map