[Menu][base] Add the resetHighlight action #37392
Merged
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 change enables solving the problem described in #36857 (review).
The issue was that after resetting the filter, the highlight remained at the first filtered item.
There are cases where this behavior is desired - for example, when lazy loading more options, we don't want the highlight to jump to the beginning. That's why I decided to leave the decision to reset the highlight to the developer. See https://codesandbox.io/s/cranky-jennings-954ghk?file=/demo.tsx for an example of how to solve it.
Initially, we discussed exposing just the high-level functions in the
actions
ref of the Menu (resetHighlight
). However, this may not be enough as we need more actions to be dispatched, such as keyDown and buttonClick (they are used to implement our demos, so developers will likely need to use them). When we implement the MenuButton, we probably won't have to expose so many actions.I ended up exposing both
resetHighlight
(for ease of use) anddispatch
(for completeness). Let me know if you think it's redundant. I'm not sure what's the best option here.Closes #36800