Skip to content

fix: Highlight the first select option by default if none are selected #3546

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

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

avinashbot
Copy link
Member

@avinashbot avinashbot commented Jun 2, 2025

Description

NVDA borks if there's no aria-activedescendant on a focused listbox. So we select the first one by default.

Had to modify a bunch of tests because of the "screen reader text" internal implementation logic that leads to .textContent being duplicated. Thankfully .toHaveTextContent() seems to be immune to that, so I just switched to that instead.

Related links, issue #, if available: AWSUI-60825

How has this been tested?

Fought and defeated the unit tests.

Review checklist

The following items are to be evaluated by the author(s) and the reviewer(s).

Correctness

  • Changes include appropriate documentation updates.
  • Changes are backward-compatible if not indicated, see CONTRIBUTING.md.
  • Changes do not include unsupported browser features, see CONTRIBUTING.md.
  • Changes were manually tested for accessibility, see accessibility guidelines.

Security

Testing

  • Changes are covered with new/existing unit tests?
  • Changes are covered with new/existing integration tests?

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

@avinashbot avinashbot force-pushed the option-list-highlight-first branch from 35fc74e to 2826d18 Compare June 3, 2025 13:46
@avinashbot avinashbot changed the title fix: Highlight the first multiselect option on open if none are selected fix: Highlight the first select option on open if none are selected Jun 3, 2025
@avinashbot avinashbot changed the title fix: Highlight the first select option on open if none are selected fix: Highlight the first select option by default if none are selected Jun 3, 2025
@@ -73,6 +74,7 @@ export function useHighlightedOption<OptionType>({
{
setHighlightedIndexWithMouse: (index: number, moveFocus = false) =>
setHighlightedIndex(index, new HighlightType('mouse', moveFocus)),
highlightFirstOptionWithMouse: () => moveHighlightFrom(1, -1, new HighlightType('mouse', true)),
Copy link
Member Author

Choose a reason for hiding this comment

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

We need this because index 0 may not be focusable. So we need to walk from the beginning to find the first one, which is what moveHighlightFrom does.

@avinashbot avinashbot force-pushed the option-list-highlight-first branch 3 times, most recently from 9686381 to a3a7b77 Compare June 3, 2025 15:26
Copy link

codecov bot commented Jun 3, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 96.55%. Comparing base (bdfe392) to head (05a88fe).
Report is 10 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff            @@
##             main    #3546    +/-   ##
========================================
  Coverage   96.55%   96.55%            
========================================
  Files         804      807     +3     
  Lines       23439    23474    +35     
  Branches     7753     8188   +435     
========================================
+ Hits        22631    22666    +35     
+ Misses        801      754    -47     
- Partials        7       54    +47     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@avinashbot avinashbot marked this pull request as ready for review June 3, 2025 15:36
@avinashbot avinashbot requested a review from a team as a code owner June 3, 2025 15:36
@avinashbot avinashbot requested review from just-boris and removed request for a team June 3, 2025 15:36
@avinashbot avinashbot marked this pull request as draft June 3, 2025 15:49
@avinashbot avinashbot removed the request for review from just-boris June 3, 2025 15:49
@avinashbot avinashbot force-pushed the option-list-highlight-first branch 2 times, most recently from 2d1a4a1 to fc5fe55 Compare June 11, 2025 14:57
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.

1 participant