Skip to content

Commit

Permalink
Merge pull request #5313 from nextcloud-libraries/fix/NcActions--focu…
Browse files Browse the repository at this point in the history
…s-selected-button-for-radio

fix(NcActions): focus first checked item on open
  • Loading branch information
susnux authored Feb 27, 2024
2 parents 4ab1b2b + db6e1d7 commit 5436cd6
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/components/NcActions/NcActions.vue
Original file line number Diff line number Diff line change
Expand Up @@ -1504,11 +1504,13 @@ export default {
focusFirstAction(event) {
if (this.opened) {
this.preventIfEvent(event)
// In case a button is considered aria-selected we will use this one as a initial focus
const firstSelectedIndex = [...this.getFocusableMenuItemElements()].findIndex((button) => {
return button.parentElement.getAttribute('aria-selected')
// In case a NcActionButton is considered checked we will use this one as a initial focus
// Having aria-checked is the simplest way to determine the checked state of a button
// TODO: determine when we need to focus the first checked item and when we not, for example, if menu has many radio groups
const firstCheckedIndex = [...this.getFocusableMenuItemElements()].findIndex((button) => {
return button.getAttribute('aria-checked') === 'true' && button.getAttribute('role') === 'menuitemradio'
})
this.focusIndex = firstSelectedIndex > -1 ? firstSelectedIndex : 0
this.focusIndex = firstCheckedIndex > -1 ? firstCheckedIndex : 0
this.focusAction()
}
},
Expand Down

0 comments on commit 5436cd6

Please sign in to comment.