Skip to content

fix: Close language selector dropdown on selection or outside click#3528

Open
abbyoung wants to merge 1 commit into
mainfrom
ay-close-language-selector-3170
Open

fix: Close language selector dropdown on selection or outside click#3528
abbyoung wants to merge 1 commit into
mainfrom
ay-close-language-selector-3170

Conversation

@abbyoung

@abbyoung abbyoung commented Jul 2, 2026

Copy link
Copy Markdown
Contributor

Summary

❗Note to reviewers: Code in this PR was written using Codex.

Fixes a bug in the language selector dropdown menu that's used when more than two languages are present.

  • Language selector dropdown menu closes when a user clicks outside the menu
  • Language selector dropdown menu closes when a user clicks a menu item
  • Adds tests

Related Issues or PRs

Closes #3170

How To Test

  1. Run storybook for this repo yarn storybook
  2. Review the story MoreThanTwoLanguagesAsALink and confirm behavior
    • Click Language link > click outside the menu. It should close.
    • Click Language link > click a language. You will be redirected (existing behavior).
    • In the new page, click the Language link again > click a language > Confirm the menu closes as expected.
  3. Review the story MoreThan Two LanguagesAsAButton and confirm behavior
    • Click Language link > click outside the menu. It should close.
    • Click Language link > click a language > menu should close.
  4. Review the story Custom Class and confirm behavior.
    • Click Language link > click outside the menu. It should close.
    • Click Language link > click a language > menu should close.

Screenshots (optional)

Author & Maintainer checklist

  • Is this is a breaking change?
    • Yes, and I accounted for the breaking changes according to the linked documentation
    • No
  • Once merged, add the PR and Issue author(s) as a contributor(s) via the all-contributors bot

Close the language selector menu when a language option is selected or the user clicks outside the selector. Add coverage for display language labels and closing behavior.

closes: #3170
@abbyoung abbyoung requested a review from a team as a code owner July 2, 2026 19:57
@github-actions

github-actions Bot commented Jul 2, 2026

Copy link
Copy Markdown
Contributor
Warnings
⚠️ This PR does not include changes to storybook, even though it affects component code.

Generated by 🚫 dangerJS against ba3052e

@brandonlenz brandonlenz left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This looks good to me! A couple of minor things I'd normally recommend for this PR, but since I found enough (unrelated) stuff to build out #3534, I think this is good to go!

We can merge #3534 into this PR before merging this to main, or merge it directly to main after. Your call, I'd love eyes/gut check on that PR though either way, if you have a chance.

Comment on lines +70 to +73
document.addEventListener('click', closeOnOutsideClick)

return () => {
document.removeEventListener('click', closeOnOutsideClick)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

We probably want to add { capture: true } for these.

Done in #3534

<LanguageSelector langs={localLanguagesButton} label="Languages" />
)

fireEvent.click(getByTestId('languageSelectorButton'))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think its worth swapping the test over to userEvent.

Done in #3534

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.

[fix] Language selector does not blur on selection or blur when configured with more than 2 languages

2 participants