Skip to content

feat: Additional Language Selector updates and fixes#3534

Open
brandonlenz wants to merge 3 commits into
ay-close-language-selector-3170from
3528-suggestions
Open

feat: Additional Language Selector updates and fixes#3534
brandonlenz wants to merge 3 commits into
ay-close-language-selector-3170from
3528-suggestions

Conversation

@brandonlenz

Copy link
Copy Markdown
Contributor

Summary

Was reviewing #3528, which works and looks great. It did cause me to deep dive on the USWDS implementation, which I noticed has additional close conditions we were not capturing:

  • Close on pressing escape
  • Close onBlur

So I added those.

There was also weird behavior in Safari that I just happened to stumble on. Safari does not focus the element on click, and our click listener to close the modal was pinned to the container div (which spans horizontally across the screen). So in Safari, if you were to click next to the language selector, it would not close. The USWDS implementation works in Safari just fine, so I updated the click event listener to match their implementation more closely and look for clicks outside of the button itself.

While updating the tests, also moved us from fireEvent to userEvent to take care of a little tech debt there.

Finally, the language-options dropdown previously had a static id, meaning that if (for whatever reason) someone included 2 language selectors on a single page, they'd run into some potential issues not being able to set unique ids. Now, if an id is passed to the LanguageSelector, the dropdown will use the id as a prefix.

Related Issues or PRs

#3528

How To Test

Added unit tests

Tested via storybook. Importantly, in Safari

Author & Maintainer checklist

  • Is this is a breaking change?
    • Yes, and I accounted for the breaking changes according to the linked documentation
    • No (arguably the id change could be in rare circumstances where someone was passing an id and relying on the hardcoded dropdown options id, but I'm going to make a judgment call and call this non-breaking still.

…s USWDS more closely:

* Close on blur
* Close on escape
* Update click listener container condition so that clicking "outside" the element in Safari still works
* Update tests to use userEvent across the board
* Use the id to allow unique ids for multiple language selectors on a single page
* Do not recompute the className in LanguageSelectorDropdown
@brandonlenz brandonlenz requested a review from abbyoung July 8, 2026 16:18
@brandonlenz brandonlenz self-assigned this Jul 8, 2026
@brandonlenz brandonlenz requested a review from a team as a code owner July 8, 2026 16:18
expect(getByTestId(languages[0].attr)).not.toBeVisible()
})

it('closes the list when an outside click handler stops propagation', async () => {

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.

This test validates and confirms the { capture: true } addition to the click event listener

Comment on lines -77 to -83
const classes = classnames(
'usa-language-container',
{
[`usa-language--small`]: small !== undefined,
},
className
)

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.

This was previously repeated twice. Now just passing the classes in from LanguageSelector

Comment on lines +107 to +108
onBlur={closeOnFocusOut}
onKeyDown={closeOnEscape}

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.

For the additional ways that the USWDS LanguageSelector closes

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