UNPKG

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.84 kB
this.primevue=this.primevue||{},this.primevue.confirmpopup=function(e,t,n,i,o,c,r,s,l){"use strict";function a(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var u=a(e),f=a(t),d=a(n),m=a(i),p=a(o),h={name:"ConfirmPopup",extends:{name:"BaseConfirmPopup",extends:a(r).default,props:{group:String},style:a(s).default,provide:function(){return{$parentInstance:this}}},inheritAttrs:!1,data:function(){return{visible:!1,confirmation:null,autoFocusAccept:null,autoFocusReject:null,target:null}},target:null,outsideClickListener:null,scrollHandler:null,resizeListener:null,container:null,confirmListener:null,closeListener:null,mounted:function(){var e=this;this.confirmListener=function(t){t&&t.group===e.group&&(e.confirmation=t,e.target=t.target,e.confirmation.onShow&&e.confirmation.onShow(),e.visible=!0)},this.closeListener=function(){e.visible=!1,e.confirmation=null},f.default.on("confirm",this.confirmListener),f.default.on("close",this.closeListener)},beforeUnmount:function(){f.default.off("confirm",this.confirmListener),f.default.off("close",this.closeListener),this.unbindOutsideClickListener(),this.scrollHandler&&(this.scrollHandler.destroy(),this.scrollHandler=null),this.unbindResizeListener(),this.container&&(c.ZIndexUtils.clear(this.container),this.container=null),this.target=null,this.confirmation=null},methods:{accept:function(){this.confirmation.accept&&this.confirmation.accept(),this.visible=!1},reject:function(){this.confirmation.reject&&this.confirmation.reject(),this.visible=!1},onHide:function(){this.confirmation.onHide&&this.confirmation.onHide(),this.visible=!1},onAcceptKeydown:function(e){"Space"!==e.code&&"Enter"!==e.code&&"NumpadEnter"!==e.code||(this.accept(),c.DomHandler.focus(this.target),e.preventDefault())},onRejectKeydown:function(e){"Space"!==e.code&&"Enter"!==e.code&&"NumpadEnter"!==e.code||(this.reject(),c.DomHandler.focus(this.target),e.preventDefault())},onEnter:function(e){this.autoFocusAccept=void 0===this.confirmation.defaultFocus||"accept"===this.confirmation.defaultFocus,this.autoFocusReject="reject"===this.confirmation.defaultFocus,this.target=document.activeElement,this.bindOutsideClickListener(),this.bindScrollListener(),this.bindResizeListener(),c.ZIndexUtils.set("overlay",e,this.$primevue.config.zIndex.overlay)},onAfterEnter:function(){this.focus()},onLeave:function(){this.autoFocusAccept=null,this.autoFocusReject=null,c.DomHandler.focus(this.target),this.target=null,this.unbindOutsideClickListener(),this.unbindScrollListener(),this.unbindResizeListener()},onAfterLeave:function(e){c.ZIndexUtils.clear(e)},alignOverlay:function(){c.DomHandler.absolutePosition(this.container,this.target,!1);var e=c.DomHandler.getOffset(this.container),t=c.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-confirm-popup-flipped","true"),!this.isUnstyled&&c.DomHandler.addClass(this.container,"p-confirm-popup-flipped"))},bindOutsideClickListener:function(){var e=this;this.outsideClickListener||(this.outsideClickListener=function(t){e.visible&&e.container&&!e.container.contains(t.target)&&!e.isTargetClicked(t)?(e.confirmation.onHide&&e.confirmation.onHide(),e.visible=!1):e.alignOverlay()},document.addEventListener("click",this.outsideClickListener))},unbindOutsideClickListener:function(){this.outsideClickListener&&(document.removeEventListener("click",this.outsideClickListener),this.outsideClickListener=null)},bindScrollListener:function(){var e=this;this.scrollHandler||(this.scrollHandler=new c.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&&!c.DomHandler.isTouchDevice()&&(e.visible=!1)},window.addEventListener("resize",this.resizeListener))},unbindResizeListener:function(){this.resizeListener&&(window.removeEventListener("resize",this.resizeListener),this.resizeListener=null)},focus:function(){var e=this.container.querySelector("[autofocus]");e&&e.focus({preventScroll:!0})},isTargetClicked:function(e){return this.target&&(this.target===e.target||this.target.contains(e.target))},containerRef:function(e){this.container=e},onOverlayClick:function(e){m.default.emit("overlay-click",{originalEvent:e,target:this.target})},onOverlayKeydown:function(e){"Escape"===e.code&&(f.default.emit("close",this.closeListener),c.DomHandler.focus(this.target))},getCXOptions:function(e,t){return{contenxt:{icon:e,iconClass:t.class}}}},computed:{message:function(){return this.confirmation?this.confirmation.message:null},acceptLabel:function(){return this.confirmation?this.confirmation.acceptLabel||this.$primevue.config.locale.accept:null},rejectLabel:function(){return this.confirmation?this.confirmation.rejectLabel||this.$primevue.config.locale.reject:null},acceptIcon:function(){return this.confirmation?this.confirmation.acceptIcon:null},rejectIcon:function(){return this.confirmation?this.confirmation.rejectIcon:null}},components:{CPButton:u.default,Portal:p.default},directives:{focustrap:d.default}},v=["aria-modal"];return h.render=function(e,t,n,i,o,c){var r=l.resolveComponent("CPButton"),s=l.resolveComponent("Portal"),a=l.resolveDirective("focustrap");return l.openBlock(),l.createBlock(s,null,{default:l.withCtx((function(){return[l.createVNode(l.Transition,l.mergeProps({name:"p-confirm-popup",onEnter:c.onEnter,onAfterEnter:c.onAfterEnter,onLeave:c.onLeave,onAfterLeave:c.onAfterLeave},e.ptm("transition")),{default:l.withCtx((function(){return[o.visible?l.withDirectives((l.openBlock(),l.createElementBlock("div",l.mergeProps({key:0,ref:c.containerRef,role:"alertdialog",class:e.cx("root"),"aria-modal":o.visible,onClick:t[2]||(t[2]=function(){return c.onOverlayClick&&c.onOverlayClick.apply(c,arguments)}),onKeydown:t[3]||(t[3]=function(){return c.onOverlayKeydown&&c.onOverlayKeydown.apply(c,arguments)})},e.ptmi("root")),[e.$slots.container?l.renderSlot(e.$slots,"container",{key:0,message:o.confirmation,onAccept:c.accept,onReject:c.reject,acceptCallback:c.accept,rejectCallback:c.reject}):(l.openBlock(),l.createElementBlock(l.Fragment,{key:1},[e.$slots.message?(l.openBlock(),l.createBlock(l.resolveDynamicComponent(e.$slots.message),{key:1,message:o.confirmation},null,8,["message"])):(l.openBlock(),l.createElementBlock("div",l.mergeProps({key:0,class:e.cx("content")},e.ptm("content")),[l.renderSlot(e.$slots,"icon",{},(function(){return[e.$slots.icon?(l.openBlock(),l.createBlock(l.resolveDynamicComponent(e.$slots.icon),{key:0,class:l.normalizeClass(e.cx("icon"))},null,8,["class"])):o.confirmation.icon?(l.openBlock(),l.createElementBlock("span",l.mergeProps({key:1,class:[o.confirmation.icon,e.cx("icon")]},e.ptm("icon")),null,16)):l.createCommentVNode("",!0)]})),l.createElementVNode("span",l.mergeProps({class:e.cx("message")},e.ptm("message")),l.toDisplayString(o.confirmation.message),17)],16)),l.createElementVNode("div",l.mergeProps({class:e.cx("footer")},e.ptm("footer")),[l.createVNode(r,{label:c.rejectLabel,onClick:t[0]||(t[0]=function(e){return c.reject()}),onKeydown:c.onRejectKeydown,autofocus:o.autoFocusReject,class:l.normalizeClass([e.cx("rejectButton"),o.confirmation.rejectClass]),unstyled:e.unstyled,pt:e.ptm("rejectButton")},l.createSlots({_:2},[c.rejectIcon||e.$slots.rejecticon?{name:"icon",fn:l.withCtx((function(t){return[l.renderSlot(e.$slots,"rejecticon",{},(function(){return[l.createElementVNode("span",l.mergeProps({class:[c.rejectIcon,t.class]},e.ptm("rejectButton").icon,{"data-pc-section":"rejectbuttonicon"}),null,16)]}))]})),key:"0"}:void 0]),1032,["label","onKeydown","autofocus","class","unstyled","pt"]),l.createVNode(r,{label:c.acceptLabel,onClick:t[1]||(t[1]=function(e){return c.accept()}),onKeydown:c.onAcceptKeydown,autofocus:o.autoFocusAccept,class:l.normalizeClass([e.cx("acceptButton"),o.confirmation.acceptClass]),unstyled:e.unstyled,pt:e.ptm("acceptButton")},l.createSlots({_:2},[c.acceptIcon||e.$slots.accepticon?{name:"icon",fn:l.withCtx((function(t){return[l.renderSlot(e.$slots,"accepticon",{},(function(){return[l.createElementVNode("span",l.mergeProps({class:[c.acceptIcon,t.class]},e.ptm("acceptButton").icon,{"data-pc-section":"acceptbuttonicon"}),null,16)]}))]})),key:"0"}:void 0]),1032,["label","onKeydown","autofocus","class","unstyled","pt"])],16)],64))],16,v)),[[a]]):l.createCommentVNode("",!0)]})),_:3},16,["onEnter","onAfterEnter","onLeave","onAfterLeave"])]})),_:3})},h}(primevue.button,primevue.confirmationeventbus,primevue.focustrap,primevue.overlayeventbus,primevue.portal,primevue.utils,primevue.basecomponent,primevue.confirmpopup.style,Vue);