accessibleprimevue
Version:
Note: This is the forked version of the Primefaces/PrimeVue repository. Since V3 has reached its EOL this is use to fix identified accessibility bugs in the v3 version of primevue. PrimeVue is an open source UI library for Vue featuring a rich set of 80+
2 lines (1 loc) • 8.86 kB
JavaScript
this.primevue=this.primevue||{},this.primevue.overlaypanel=function(e,t,n,i,o,s,l,r,c){"use strict";function a(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var u=a(e),d=a(t),h=a(n),v=a(i),f=a(o),p={name:"OverlayPanel",extends:{name:"BaseOverlayPanel",extends:a(l).default,props:{dismissable:{type:Boolean,default:!0},showCloseIcon:{type:Boolean,default:!1},appendTo:{type:[String,Object],default:"body"},baseZIndex:{type:Number,default:0},autoZIndex:{type:Boolean,default:!0},breakpoints:{type:Object,default:null},closeIcon:{type:String,default:void 0},closeOnEscape:{type:Boolean,default:!0}},style:a(r).default,provide:function(){return{$parentInstance:this}}},inheritAttrs:!1,emits:["show","hide"],data:function(){return{visible:!1}},watch:{dismissable:{immediate:!0,handler:function(e){e?this.bindOutsideClickListener():this.unbindOutsideClickListener()}}},selfClick:!1,target:null,eventTarget:null,outsideClickListener:null,scrollHandler:null,resizeListener:null,container:null,styleElement:null,overlayEventListener:null,documentKeydownListener:null,beforeUnmount:function(){this.dismissable&&this.unbindOutsideClickListener(),this.scrollHandler&&(this.scrollHandler.destroy(),this.scrollHandler=null),this.destroyStyle(),this.unbindResizeListener(),this.target=null,this.container&&this.autoZIndex&&s.ZIndexUtils.clear(this.container),this.overlayEventListener&&(h.default.off("overlay-click",this.overlayEventListener),this.overlayEventListener=null),this.container=null},mounted:function(){this.breakpoints&&this.createStyle()},methods:{toggle:function(e,t){this.visible?this.hide():this.show(e,t)},show:function(e,t){this.visible=!0,this.eventTarget=e.currentTarget,this.target=t||e.currentTarget},hide:function(){this.visible=!1},onContentClick:function(){this.selfClick=!0},onEnter:function(e){var t=this;this.container.setAttribute(this.attributeSelector,""),s.DomHandler.addStyles(e,{position:"absolute",top:"0",left:"0"}),this.alignOverlay(),this.dismissable&&this.bindOutsideClickListener(),this.bindScrollListener(),this.bindResizeListener(),this.autoZIndex&&s.ZIndexUtils.set("overlay",e,this.baseZIndex+this.$primevue.config.zIndex.overlay),this.overlayEventListener=function(e){t.container.contains(e.target)&&(t.selfClick=!0)},this.focus(),h.default.on("overlay-click",this.overlayEventListener),this.$emit("show"),this.closeOnEscape&&this.bindDocumentKeyDownListener()},onLeave:function(){this.unbindOutsideClickListener(),this.unbindScrollListener(),this.unbindResizeListener(),this.unbindDocumentKeyDownListener(),h.default.off("overlay-click",this.overlayEventListener),this.overlayEventListener=null,this.$emit("hide")},onAfterLeave:function(e){this.autoZIndex&&s.ZIndexUtils.clear(e)},alignOverlay:function(){s.DomHandler.absolutePosition(this.container,this.target,!1);var e=s.DomHandler.getOffset(this.container),t=s.DomHandler.getOffset(this.target),n=0;e.left<t.left&&(n=t.left-e.left),this.container.style.setProperty("--overlayArrowLeft","".concat(n,"px")),e.top<t.top&&(this.container.setAttribute("data-p-overlaypanel-flipped","true"),!this.isUnstyled&&s.DomHandler.addClass(this.container,"p-overlaypanel-flipped"))},onContentKeydown:function(e){"Escape"===e.code&&this.closeOnEscape&&(this.hide(),s.DomHandler.focus(this.target))},onButtonKeydown:function(e){switch(e.code){case"ArrowDown":case"ArrowUp":case"ArrowLeft":case"ArrowRight":e.preventDefault()}},focus:function(){var e=this.container.querySelector("[autofocus]");e&&e.focus()},onKeyDown:function(e){"Escape"===e.code&&this.closeOnEscape&&(this.visible=!1)},bindDocumentKeyDownListener:function(){this.documentKeydownListener||(this.documentKeydownListener=this.onKeyDown.bind(this),window.document.addEventListener("keydown",this.documentKeydownListener))},unbindDocumentKeyDownListener:function(){this.documentKeydownListener&&(window.document.removeEventListener("keydown",this.documentKeydownListener),this.documentKeydownListener=null)},bindOutsideClickListener:function(){var e=this;!this.outsideClickListener&&s.DomHandler.isClient()&&(this.outsideClickListener=function(t){!e.visible||e.selfClick||e.isTargetClicked(t)||(e.visible=!1),e.selfClick=!1},document.addEventListener("click",this.outsideClickListener))},unbindOutsideClickListener:function(){this.outsideClickListener&&(document.removeEventListener("click",this.outsideClickListener),this.outsideClickListener=null,this.selfClick=!1)},bindScrollListener:function(){var e=this;this.scrollHandler||(this.scrollHandler=new s.ConnectedOverlayScrollHandler(this.target,(function(){e.visible&&(e.visible=!1)}))),this.scrollHandler.bindScrollListener()},unbindScrollListener:function(){this.scrollHandler&&this.scrollHandler.unbindScrollListener()},bindResizeListener:function(){var e=this;this.resizeListener||(this.resizeListener=function(){e.visible&&!s.DomHandler.isTouchDevice()&&(e.visible=!1)},window.addEventListener("resize",this.resizeListener))},unbindResizeListener:function(){this.resizeListener&&(window.removeEventListener("resize",this.resizeListener),this.resizeListener=null)},isTargetClicked:function(e){return this.eventTarget&&(this.eventTarget===e.target||this.eventTarget.contains(e.target))},containerRef:function(e){this.container=e},createStyle:function(){if(!this.styleElement&&!this.isUnstyled){var e;this.styleElement=document.createElement("style"),this.styleElement.type="text/css",s.DomHandler.setAttribute(this.styleElement,"nonce",null===(e=this.$primevue)||void 0===e||null===(e=e.config)||void 0===e||null===(e=e.csp)||void 0===e?void 0:e.nonce),document.head.appendChild(this.styleElement);var t="";for(var n in this.breakpoints)t+="\n @media screen and (max-width: ".concat(n,") {\n .p-overlaypanel[").concat(this.attributeSelector,"] {\n width: ").concat(this.breakpoints[n]," !important;\n }\n }\n ");this.styleElement.innerHTML=t}},destroyStyle:function(){this.styleElement&&(document.head.removeChild(this.styleElement),this.styleElement=null)},onOverlayClick:function(e){h.default.emit("overlay-click",{originalEvent:e,target:this.target})}},computed:{attributeSelector:function(){return s.UniqueComponentId()},closeAriaLabel:function(){return this.$primevue.config.locale.aria?this.$primevue.config.locale.aria.close:void 0}},directives:{focustrap:u.default,ripple:f.default},components:{Portal:v.default,TimesIcon:d.default}},m=["aria-modal"],y=["aria-label"];return p.render=function(e,t,n,i,o,s){var l=c.resolveComponent("Portal"),r=c.resolveDirective("ripple"),a=c.resolveDirective("focustrap");return c.openBlock(),c.createBlock(l,{appendTo:e.appendTo},{default:c.withCtx((function(){return[c.createVNode(c.Transition,c.mergeProps({name:"p-overlaypanel",onEnter:s.onEnter,onLeave:s.onLeave,onAfterLeave:s.onAfterLeave},e.ptm("transition")),{default:c.withCtx((function(){return[o.visible?c.withDirectives((c.openBlock(),c.createElementBlock("div",c.mergeProps({key:0,ref:s.containerRef,role:"dialog","aria-modal":o.visible,onClick:t[5]||(t[5]=function(){return s.onOverlayClick&&s.onOverlayClick.apply(s,arguments)}),class:e.cx("root")},e.ptmi("root")),[e.$slots.container?c.renderSlot(e.$slots,"container",{key:0,onClose:s.hide,onKeydown:function(e){return s.onButtonKeydown(e)},closeCallback:s.hide,keydownCallback:function(e){return s.onButtonKeydown(e)}}):(c.openBlock(),c.createElementBlock(c.Fragment,{key:1},[c.createElementVNode("div",c.mergeProps({class:e.cx("content"),onClick:t[0]||(t[0]=function(){return s.onContentClick&&s.onContentClick.apply(s,arguments)}),onMousedown:t[1]||(t[1]=function(){return s.onContentClick&&s.onContentClick.apply(s,arguments)}),onKeydown:t[2]||(t[2]=function(){return s.onContentKeydown&&s.onContentKeydown.apply(s,arguments)})},e.ptm("content")),[c.renderSlot(e.$slots,"default")],16),e.showCloseIcon?c.withDirectives((c.openBlock(),c.createElementBlock("button",c.mergeProps({key:0,class:e.cx("closeButton"),"aria-label":s.closeAriaLabel,type:"button",autofocus:"",onClick:t[3]||(t[3]=function(){return s.hide&&s.hide.apply(s,arguments)}),onKeydown:t[4]||(t[4]=function(){return s.onButtonKeydown&&s.onButtonKeydown.apply(s,arguments)})},e.ptm("closeButton")),[c.renderSlot(e.$slots,"closeicon",{},(function(){return[(c.openBlock(),c.createBlock(c.resolveDynamicComponent(e.closeIcon?"span":"TimesIcon"),c.mergeProps({class:[e.cx("closeIcon"),e.closeIcon]},e.ptm("closeIcon")),null,16,["class"]))]}))],16,y)),[[r]]):c.createCommentVNode("",!0)],64))],16,m)),[[a]]):c.createCommentVNode("",!0)]})),_:3},16,["onEnter","onLeave","onAfterLeave"])]})),_:3},8,["appendTo"])},p}(primevue.focustrap,primevue.icons.times,primevue.overlayeventbus,primevue.portal,primevue.ripple,primevue.utils,primevue.basecomponent,primevue.overlaypanel.style,Vue);