primevue
Version:
[](https://opensource.org/licenses/MIT) [](https://badge.fury.io/js/primevue) [ • 2.57 kB
JavaScript
import{DomHandler as e,ObjectUtils as t}from"primevue/utils";function s(e){e.$_pfocustrap_mutationobserver&&e.$_pfocustrap_mutationobserver.disconnect(),e.$_pfocustrap_focusinlistener&&e.removeEventListener("focusin",e.$_pfocustrap_focusinlistener)&&(e.$_pfocustrap_focusinlistener=null),e.$_pfocustrap_focusoutlistener&&e.removeEventListener("focusout",e.$_pfocustrap_focusoutlistener)&&(e.$_pfocustrap_focusoutlistener=null)}function o(t){const{currentTarget:s,relatedTarget:o}=t,n=o===s.$_pfocustrap_lasthiddenfocusableelement?e.getFirstFocusableElement(s.parentElement,`:not(.p-hidden-focusable)${s.$_pfocustrap_focusableselector}`):s.$_pfocustrap_lasthiddenfocusableelement;e.focus(n)}function n(t){const{currentTarget:s,relatedTarget:o}=t,n=o===s.$_pfocustrap_firsthiddenfocusableelement?e.getLastFocusableElement(s.parentElement,`:not(.p-hidden-focusable)${s.$_pfocustrap_focusableselector}`):s.$_pfocustrap_firsthiddenfocusableelement;e.focus(n)}const u={mounted(s,u){const{disabled:c}=u.value||{};c||(function(e,t){const{tabIndex:s=0,firstFocusableSelector:u="",lastFocusableSelector:c=""}=t.value||{},r=e=>{const t=document.createElement("span");return t.classList="p-hidden-accessible p-hidden-focusable",t.tabIndex=s,t.setAttribute("aria-hidden","true"),t.setAttribute("role","presentation"),t.addEventListener("focus",e),t},a=r(o),l=r(n);a.$_pfocustrap_lasthiddenfocusableelement=l,a.$_pfocustrap_focusableselector=u,l.$_pfocustrap_firsthiddenfocusableelement=a,l.$_pfocustrap_focusableselector=c,e.prepend(a),e.append(l)}(s,u),function(s,o){const{onFocusIn:n,onFocusOut:u}=o.value||{};s.$_pfocustrap_mutationobserver=new MutationObserver((o=>{o.forEach((o=>{if("childList"===o.type&&!s.contains(document.activeElement)){const s=o=>{const n=e.isFocusableElement(o)?o:e.getFirstFocusableElement(o);return t.isNotEmpty(n)?n:s(o.nextSibling)};e.focus(s(o.nextSibling))}}))})),s.$_pfocustrap_mutationobserver.disconnect(),s.$_pfocustrap_mutationobserver.observe(s,{childList:!0}),s.$_pfocustrap_focusinlistener=e=>n&&n(e),s.$_pfocustrap_focusoutlistener=e=>u&&u(e),s.addEventListener("focusin",s.$_pfocustrap_focusinlistener),s.addEventListener("focusout",s.$_pfocustrap_focusoutlistener)}(s,u),function(t,s){const{autoFocusSelector:o="",firstFocusableSelector:n="",autoFocus:u=!1}=s.value||{};let c=e.getFirstFocusableElement(t,`[autofocus]:not(.p-hidden-focusable)${o}`);u&&!c&&(c=e.getFirstFocusableElement(t,`:not(.p-hidden-focusable)${n}`)),e.focus(c)}(s,u))},updated(e,t){const{disabled:o}=t.value||{};o&&s(e)},unmounted(e){s(e)}};export{u as default};