fix #4620 Overlaypanel: Overlay panel doesnot close on escape button click
parent
c0bf815e92
commit
02cbc1e98d
|
@ -33,6 +33,10 @@ export default {
|
||||||
closeIcon: {
|
closeIcon: {
|
||||||
type: String,
|
type: String,
|
||||||
default: undefined
|
default: undefined
|
||||||
|
},
|
||||||
|
closeOnEscape: {
|
||||||
|
type: Boolean,
|
||||||
|
default: true
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
style: OverlayPanelStyle,
|
style: OverlayPanelStyle,
|
||||||
|
|
|
@ -163,6 +163,11 @@ export interface OverlayPanelProps {
|
||||||
* @defaultValue false
|
* @defaultValue false
|
||||||
*/
|
*/
|
||||||
unstyled?: boolean;
|
unstyled?: boolean;
|
||||||
|
/**
|
||||||
|
* Specifies if pressing escape key should hide the dialog.
|
||||||
|
* @defaultValue true
|
||||||
|
*/
|
||||||
|
closeOnEscape?: boolean | undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -58,6 +58,7 @@ export default {
|
||||||
container: null,
|
container: null,
|
||||||
styleElement: null,
|
styleElement: null,
|
||||||
overlayEventListener: null,
|
overlayEventListener: null,
|
||||||
|
documentKeydownListener: null,
|
||||||
beforeUnmount() {
|
beforeUnmount() {
|
||||||
if (this.dismissable) {
|
if (this.dismissable) {
|
||||||
this.unbindOutsideClickListener();
|
this.unbindOutsideClickListener();
|
||||||
|
@ -129,6 +130,10 @@ export default {
|
||||||
this.focus();
|
this.focus();
|
||||||
OverlayEventBus.on('overlay-click', this.overlayEventListener);
|
OverlayEventBus.on('overlay-click', this.overlayEventListener);
|
||||||
this.$emit('show');
|
this.$emit('show');
|
||||||
|
|
||||||
|
if (this.closeOnEscape) {
|
||||||
|
this.bindDocumentKeyDownListener();
|
||||||
|
}
|
||||||
},
|
},
|
||||||
onLeave() {
|
onLeave() {
|
||||||
this.unbindOutsideClickListener();
|
this.unbindOutsideClickListener();
|
||||||
|
@ -186,6 +191,23 @@ export default {
|
||||||
focusTarget.focus();
|
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() {
|
bindOutsideClickListener() {
|
||||||
if (!this.outsideClickListener && DomHandler.isClient()) {
|
if (!this.outsideClickListener && DomHandler.isClient()) {
|
||||||
this.outsideClickListener = (event) => {
|
this.outsideClickListener = (event) => {
|
||||||
|
|
Loading…
Reference in New Issue