Skip to content

Move focusgroup functionality to a separate polyfill#51

Merged
ai merged 8 commits intoai:polyfillfrom
echo-vladimir:refactor/focusgroup
Dec 11, 2024
Merged

Move focusgroup functionality to a separate polyfill#51
ai merged 8 commits intoai:polyfillfrom
echo-vladimir:refactor/focusgroup

Conversation

@echo-vladimir
Copy link
Copy Markdown
Contributor

Separated focusgroup attribute functionality from roles and implemented it as an independent polyfill.

Comment thread hotkey.js Outdated

let insideFocusGroup =
event.target.role === 'menuitem' ||
event.target.role === 'button' ||
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why we added all of these?

Should we also add focusgroup?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When focus is on an element within a focusgroup, hotkeys are restricted to that group only.
The filtering of elements follows the same logic as implemented in the getItems

function getItems(group) {
  if (group.hasAttribute('focusgroup')) {
    let items = [...group.querySelectorAll('*:not([focusgroup="none"])')]
    return items.filter(item => {
      return (
        item.role === 'button' ||
        item.type === 'button' ||
        item.role === 'checkbox' ||
        item.type === 'checkbox'
      )
    })
  }
}

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should disable one-letter hotkeys only for cases where we will have a conflict.

In menuitem we have a search to find next element. This is why we disable only one-letter hot keys, because they will conflict with this search.

As I understand focusgroup has no search, so there will be no conflicts.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like you're right, there's nothing about search in the spec. In that case, I'll remove all search-related functionality from the polyfill and update the API to focusGroupPolyfill() without the FocusGroupKeyUXOptions.

@@ -0,0 +1,477 @@
import { JSDOM } from 'jsdom'
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we add a few tests for focusGroupPolyfill and focusGroupKeyUX to be sure that there are no conflicts between them?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, sure!

@ai ai merged commit 62e3ef3 into ai:polyfill Dec 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants