Skip to content

Commit

Permalink
Merge pull request #1120 from DDMAL/rename-focus
Browse files Browse the repository at this point in the history
Remove redundant event listener after closing modal window
  • Loading branch information
yinanazhou authored Oct 24, 2023
2 parents c4d8bbd + 0197df0 commit 67a6e5f
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions src/utils/ModalWindow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,26 @@ export class ModalWindow implements ModalWindowInterface {
constructor (neonView?: NeonView) {
this.neonView = neonView;
this.modalWindowState = ModalWindowState.CLOSED;
this.setupEventListeners();
}

// set event listeners that apply to all modal windows
/**
* Set event listeners that apply to all modal windows
*/
private setupEventListeners() {
document.getElementById('neon-modal-window-header-close').addEventListener('click', this.hideModalWindow.bind(this));
document.getElementById('neon-modal-window').addEventListener('keydown', this.keydownListener.bind(this));
document.getElementById('neon-modal-window-container').addEventListener('click', this.focusModalWindow.bind(this));
}


/**
* Remove event listeners associated with this modal window
*/
private removeEventListeners() {
document.getElementById('neon-modal-window-header-close').removeEventListener('click', this.hideModalWindow.bind(this));
document.getElementById('neon-modal-window').removeEventListener('keydown', this.keydownListener.bind(this));
document.getElementById('neon-modal-window-container').removeEventListener('click', this.focusModalWindow.bind(this));
}


/**
Expand Down Expand Up @@ -141,6 +153,7 @@ export class ModalWindow implements ModalWindowInterface {
document.body.style.overflowX = 'hidden';
document.body.style.overflowY = 'scroll';
this.modalWindowState = ModalWindowState.CLOSED;
this.removeEventListeners();
}


Expand Down Expand Up @@ -329,6 +342,7 @@ export class ModalWindow implements ModalWindowInterface {
case ModalWindowView.EDIT_TEXT:
(<HTMLInputElement> document.getElementById('neon-modal-window-edit-text-input')).select();
break;
case ModalWindowView.DOCUMENT_UPLOAD:
case ModalWindowView.NEW_FOLDER:
case ModalWindowView.RENAME:
break;
Expand Down

0 comments on commit 67a6e5f

Please sign in to comment.