You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This PR exposes a ref to the activeDescendantImperative api so that consumers can control the focus for Combobox, Dropdown, and Listbox programmatically.
Previous Behavior
If a consumer wanted to move focus to an option, they usually would use the native .focus() api on their target element. This however was a pitfall for Combobox, Dropdown, and Listbox as they own their own focus state for the options via useActiveDescendant. Meaning any attempts at using the .focus() api would get overwritten or seemingly ignored because it's the wrong tool to begin with.
Open the combobox and select an option far down the list (e.g. Option 500).
Close the combobox
a. You might have to lose focus by tabbing away and back to the combobox. See GIF.
Reopen the combobox with keyboard
See the virtual window scrolled into view Option 500
Press the down arrow but notice the focus moves to Option 489 for example (it might differ based on viewport size)
The expected behavior there is for it to move the focus down to Option 501. The reason this is occuring is because the virtual window is only rendering into the DOM Options 489-570 for example and there is no way to sync what item to focus in the active descendant.
GIF of buggy behavior
Note: I did notice if you re-open the combobox again, the 2nd time the focus is properly moved.
New Behavior
Consumers can now use the activeDescendantImperativeRef prop to get at the same underlying focus state and can correctly move focus to a target of their choice.
Going back to the Combobox + Virtualizer example, the consumer would need to update their code so that on open they use the activeDescendantImperativeRef.focus(targetHtmlid) method to sync focus.
I can confirm that I can reproduce the bug @Weffe, but I don't get why making the internal active descendant API to be the solution. The bug is a problem to be resolved for sure, but it does not require exposing internals for that AFAIU
What would be the alternative? In the virtual-window situation, the active descendant state is internal and we need a way to expose it so there's a programmatic way to change that internal state. Without it, there's no way to make Dropdown, Combobox, or Menus keyboard accessible if a Dev chooses to virtualize them.
I personally tried using the useObservedElement hook and also just manually focusing the target html option but those don't update the aria-activedescendant attribute on the trigger. In this case, you'd be out of sync with what the focus outline is visibly on vs what the trigger's activedescendant is pointing to.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR exposes a ref to the activeDescendantImperative api so that consumers can control the focus for Combobox, Dropdown, and Listbox programmatically.
Previous Behavior
If a consumer wanted to move focus to an option, they usually would use the native
.focus()api on their target element. This however was a pitfall for Combobox, Dropdown, and Listbox as they own their own focus state for the options viauseActiveDescendant. Meaning any attempts at using the.focus()api would get overwritten or seemingly ignored because it's the wrong tool to begin with.You can see the issue on the Storybook for Combobox + Virtualizer: https://storybooks.fluentui.dev/react/?path=/docs/components-combobox--docs#virtualizer
a. You might have to lose focus by tabbing away and back to the combobox. See GIF.
The expected behavior there is for it to move the focus down to Option 501. The reason this is occuring is because the virtual window is only rendering into the DOM Options 489-570 for example and there is no way to sync what item to focus in the active descendant.
GIF of buggy behavior
Note: I did notice if you re-open the combobox again, the 2nd time the focus is properly moved.
New Behavior
Consumers can now use the
activeDescendantImperativeRefprop to get at the same underlying focus state and can correctly move focus to a target of their choice.Going back to the Combobox + Virtualizer example, the consumer would need to update their code so that on open they use the
activeDescendantImperativeRef.focus(targetHtmlid)method to sync focus.Related Issue(s)