Skip to content
Merged
Changes from 1 commit
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
766855b
Add a function to return a text-only label.
alexstine Sep 28, 2023
3c82605
Use already defined isAppleOS function from keycodes. Remove new OS f…
alexstine Sep 28, 2023
700bb1c
Add fallback if textLabel is unavailable.
alexstine Sep 28, 2023
a6b45ab
Try combobox role to get around annoying re-rendering type effect.
alexstine Sep 29, 2023
98bbc1f
Merge branch 'trunk' of github.com:WordPress/gutenberg into fix/autoc…
alexstine Oct 2, 2023
b43d95e
Changelog entry.
alexstine Oct 2, 2023
6372f1c
Code quality and refresh.
alexstine Oct 10, 2023
96464c6
Merge branch 'trunk' of github.com:WordPress/gutenberg into fix/autoc…
alexstine Oct 14, 2023
7ecf361
Merge branch 'trunk' of github.com:WordPress/gutenberg into fix/autoc…
alexstine Oct 18, 2023
7972225
Revert Windows fix, too much scope creep.
alexstine Oct 18, 2023
7681b88
Fix Changelog.
alexstine Oct 18, 2023
1e24a70
Remove diff artifact.
alexstine Oct 18, 2023
facbe98
Fix conflict.
alexstine Oct 19, 2023
8e7ba56
Merge branch 'fix/autocomplete-voiceover' of github.com:WordPress/gut…
alexstine Oct 19, 2023
307b78e
Merge branch 'trunk' into fix/autocomplete-voiceover
alexstine Oct 19, 2023
98a845b
Remove mistaken files.
alexstine Oct 19, 2023
6e91679
Add comment linking to PR.
alexstine Oct 19, 2023
fe36a90
Revert textLabel prop.
alexstine Oct 19, 2023
607c455
Merge branch 'trunk' of github.com:WordPress/gutenberg into fix/autoc…
alexstine Oct 19, 2023
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
Prev Previous commit
Next Next commit
Try combobox role to get around annoying re-rendering type effect.
  • Loading branch information
alexstine committed Sep 29, 2023
commit a6b45abdec956d86220d70e1192410d5e2418056
2 changes: 1 addition & 1 deletion packages/components/src/autocomplete/autocompleter-ui.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ export function getAutoCompleterUI( autocompleter: WPCompleter ) {
} ) => (
<Component
id={ listBoxId }
role="listbox"
role="combobox"
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not sure how valid this is but it seems to actually work really well. Still need to test on Mac but it eliminates the re-rendering feeling. I did inspect with React Dev Tools and while there are some passed properties that do force some re-rendering, I think this issue was more related to the listbox role itself.

Copy link
Contributor

Choose a reason for hiding this comment

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

Changing this to combobox doesn't seem to make any difference on Mac, I guess because VoiceOver has no idea what it's doing anyway! Either way, it's definitely much more vocal now, announcing each option as it's selected, and debouncing appropriately.

Academically speaking, I suppose it should be the controlling "paragraph" that temporarily gets a role change, while the popup should stay as a listbox. When I hacked that together very quickly, VoiceOver announced the following...

You are currently on a Menu pop-up combo box, inside a frame. Type text or, to display a list of choices, press Control-Option-Space.

That feels somehow more "correct", in terms of what it is semantically, though confusingly pressing Control+Option+Space doesn't do anything. Project for another time!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@andrewhayward If I keep the role="listbox", every time I press Up or Down Arrow, it has this re-render effect. I think its because the passed selected index prop changes.

Voiceover, now that I think about it, won't work at all even with this change due to Apple not supporting aria-owns.

https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Attributes/aria-owns

Warning: At the time of this writing, aria-owns is not supported on MacOS and iOS with VoiceOver.

I might try switching with aria-controls.

https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Attributes/aria-controls

You should look at how we implemented the post author combo box if there are more than 25 users on the site. You can find that in the editor package, I think it uses Combobox component which wraps around part of FormTokenInput.

Copy link
Member

Choose a reason for hiding this comment

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

Technically speaking, this change shouldn't affect how React re-renders items. As you said, there's probably a different change that triggers re-render.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@andrewhayward Okay, after doing some more debugging, we could improve a little more. It would be possible to keep role="combobox" and role="listbox" on the correct elements if we could prevent listBox from re-rendering every time. Every time I press Up or Down Arrow keys, the AutocompleterUI triggers a re-render of the ListBox and React Dev Tools says the cause is:

Props changed: (selectedIndex, onChangeOptions, onSelect, reset)

Is it possible to useCallback or useMemo the onChangeOptions callback to only change if needed? Up or Down Arrow keys should only adjust the selectedIndex, not re-render the entire options tree.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

From what I can tell, the re-render is being caused by the changing props returned on the hook. Not sure how to go about fixing this so the suggestions list only re-renders when the filter is used. This doesn't appear to be a problem in the Combobox component. In theory, the props would simply update the existing component but it seems like the whole component is being replaced which also forces ListBox to re-render.

className="components-autocomplete__results"
>
{ items.map( ( option, index ) => (
Expand Down