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 <[email protected]>
  • Loading branch information
susnux committed Sep 2, 2024
1 parent 06179fa commit 48ffbfd
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions src/components/NcActions/NcActions.vue
Original file line number Diff line number Diff line change
Expand Up @@ -1335,6 +1335,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 @@ -1595,10 +1603,10 @@ 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 @@ -1609,6 +1617,12 @@ export default {
}
}
},

handleEscapePressed(event) {
this.closeMenu()
event.preventDefault()
},

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

0 comments on commit 48ffbfd

Please sign in to comment.