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): focus first checked item on open #5313

Merged
merged 1 commit into from
Feb 27, 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
10 changes: 6 additions & 4 deletions src/components/NcActions/NcActions.vue
Original file line number Diff line number Diff line change
Expand Up @@ -1353,7 +1353,7 @@
return this.$refs.menu.querySelector('li.active')
},
/**
* @return {NodeListOf<HTMLElement>}

Check warning on line 1356 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 @@ -1504,11 +1504,13 @@
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
Loading