Skip to content

Commit

Permalink
accessibility(Materialbox) implement remove event listener for keyboa…
Browse files Browse the repository at this point in the history
…rd interaction
  • Loading branch information
gselderslaghs committed Dec 14, 2024
1 parent e794f02 commit 0ed1584
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/materialbox.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,23 +135,26 @@ export class Materialbox extends Component<MaterialboxOptions> {

private _removeEventHandlers() {
this.el.removeEventListener('click', this._handleMaterialboxClick);
this.el.removeEventListener('keypress', this._handleMaterialboxKeypress);
}

private _handleMaterialboxClick = () => {
this._handleMaterialboxToggle();
};

private _handleMaterialboxKeypress = (e: KeyboardEvent) => {
if (Utils.keys.ENTER.includes(e.key)) {
this._handleMaterialboxToggle();
}
};

private _handleMaterialboxToggle = () => {
// If already modal, return to original
if (this.doneAnimating === false || (this.overlayActive && this.doneAnimating))
this.close();
else
this.open();
}
};

private _handleWindowScroll = () => {
if (this.overlayActive) this.close();
Expand Down

0 comments on commit 0ed1584

Please sign in to comment.