Skip to content

Commit

Permalink
fix(NcActions): Pressing escape should always close the actions
Browse files Browse the repository at this point in the history
1. Opening actions, then e.g. right-click for context menu.
2. Now press escape -> context menu closes
3. Press escape again -> nothing happens
4. (with this commit): Pressing it a second time will close the actions as expected

Signed-off-by: Ferdinand Thiessen <opensource@fthiessen.de>
  • Loading branch information
susnux authored and backportbot[bot] committed Sep 2, 2024
1 parent bbbe4a7 commit 96fa62c
Showing 1 changed file with 18 additions and 4 deletions.
22 changes: 18 additions & 4 deletions src/components/NcActions/NcActions.vue
Original file line number Diff line number Diff line change
Expand Up @@ -1205,6 +1205,14 @@ export default {
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)
} else {
document.body.removeEventListener('keydown', this.handleEscapePressed)
}
},
},
Expand Down Expand Up @@ -1465,11 +1473,9 @@ export default {
}
}
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 @@ -1480,6 +1486,14 @@ export default {
}
}
},
handleEscapePressed(event) {
if (event.key === 'Escape') {
this.closeMenu()
event.preventDefault()
}
},
removeCurrentActive() {
const currentActiveElement = this.$refs.menu.querySelector('li.active')
if (currentActiveElement) {
Expand Down

0 comments on commit 96fa62c

Please sign in to comment.