Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(NcActions): Pressing escape should always close the actions #6037

Merged
merged 1 commit into from
Sep 2, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 18 additions & 4 deletions src/components/NcActions/NcActions.vue
Original file line number Diff line number Diff line change
Expand Up @@ -1335,6 +1335,14 @@

opened() {
this.intersectIntoCurrentFocusTrapStack()

// Ensure that pressing escape will close the menu even if the menu is not hovered
// and not currently active, e.g. because user opened the context menu
if (this.opened) {
document.body.addEventListener('keydown', this.handleEscapePressed)
susnux marked this conversation as resolved.
Show resolved Hide resolved
} else {
document.body.removeEventListener('keydown', this.handleEscapePressed)
}
},
},

Expand Down Expand Up @@ -1502,7 +1510,7 @@
return this.$refs.menu.querySelector('li.active')
},
/**
* @return {NodeListOf<HTMLElement>}

Check warning on line 1513 in src/components/NcActions/NcActions.vue

View workflow job for this annotation

GitHub Actions / NPM lint

The type 'NodeListOf' is undefined
*/
getFocusableMenuItemElements() {
return this.$refs.menu.querySelectorAll(focusableSelector)
Expand Down Expand Up @@ -1594,11 +1602,9 @@
}
}

if (event.key === 'Escape') {
this.closeMenu()
event.preventDefault()
}
this.handleEscapePressed(event)
},

onTriggerKeydown(event) {
if (event.key === 'Escape') {
// Tooltip has no focusable elements and the focus remains on the trigger button.
Expand All @@ -1609,6 +1615,14 @@
}
}
},

handleEscapePressed(event) {
if (event.key === 'Escape') {
this.closeMenu()
event.preventDefault()
}
},

removeCurrentActive() {
const currentActiveElement = this.$refs.menu.querySelector('li.active')
if (currentActiveElement) {
Expand Down
Loading