Skip to content

Commit

Permalink
Merge pull request #6037 from nextcloud-libraries/fix/actions-escape
Browse files Browse the repository at this point in the history
fix(NcActions): Pressing escape should always close the actions
  • Loading branch information
susnux committed Sep 2, 2024
2 parents 0bc96ff + 1f2a788 commit 7889144
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 @@ -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 @@ -1594,11 +1602,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 @@ -1609,6 +1615,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 7889144

Please sign in to comment.