mirror of
https://github.com/primefaces/primevue.git
synced 2025-05-09 00:42:36 +00:00
fix #4620 Overlaypanel: Overlay panel doesnot close on escape button click
This commit is contained in:
parent
c0bf815e92
commit
02cbc1e98d
3 changed files with 31 additions and 0 deletions
|
@ -58,6 +58,7 @@ export default {
|
|||
container: null,
|
||||
styleElement: null,
|
||||
overlayEventListener: null,
|
||||
documentKeydownListener: null,
|
||||
beforeUnmount() {
|
||||
if (this.dismissable) {
|
||||
this.unbindOutsideClickListener();
|
||||
|
@ -129,6 +130,10 @@ export default {
|
|||
this.focus();
|
||||
OverlayEventBus.on('overlay-click', this.overlayEventListener);
|
||||
this.$emit('show');
|
||||
|
||||
if (this.closeOnEscape) {
|
||||
this.bindDocumentKeyDownListener();
|
||||
}
|
||||
},
|
||||
onLeave() {
|
||||
this.unbindOutsideClickListener();
|
||||
|
@ -186,6 +191,23 @@ export default {
|
|||
focusTarget.focus();
|
||||
}
|
||||
},
|
||||
onKeyDown(event) {
|
||||
if (event.code === 'Escape' && this.closeOnEscape) {
|
||||
this.visible = false;
|
||||
}
|
||||
},
|
||||
bindDocumentKeyDownListener() {
|
||||
if (!this.documentKeydownListener) {
|
||||
this.documentKeydownListener = this.onKeyDown.bind(this);
|
||||
window.document.addEventListener('keydown', this.documentKeydownListener);
|
||||
}
|
||||
},
|
||||
unbindDocumentKeyDownListener() {
|
||||
if (this.documentKeydownListener) {
|
||||
window.document.removeEventListener('keydown', this.documentKeydownListener);
|
||||
this.documentKeydownListener = null;
|
||||
}
|
||||
},
|
||||
bindOutsideClickListener() {
|
||||
if (!this.outsideClickListener && DomHandler.isClient()) {
|
||||
this.outsideClickListener = (event) => {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue