Skip to content
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

fix: Language selector: add prop for display lang for bug fix #2622

Merged
merged 3 commits into from
Oct 18, 2023

Conversation

kleinschmidtj
Copy link
Contributor

@kleinschmidtj kleinschmidtj commented Oct 6, 2023

Summary

  • Added a new optional prop to handle cases where the current language is persisted and the component should know which language to display. Defaults to setting the displayed language as the first item in the langs array.
  • Broken out the drop down part of the selector into a separate file.
  • Dropdown prefers to set the label with the new prop's label.

Related Issues or PRs

closes #2621

How To Test

Use the new prop and confirm it overrides the existing behavior where the label is pulled from the first item in the langs array.

Screenshots (optional)

Screenshot 2023-10-06 at 6 36 05 AM Screenshot 2023-10-06 at 6 36 26 AM

@kleinschmidtj kleinschmidtj requested review from a team as code owners October 6, 2023 11:36
@kleinschmidtj kleinschmidtj changed the title Language selector: add prop for display lang for bug fix [fix] Language selector: add prop for display lang for bug fix Oct 6, 2023
@kleinschmidtj kleinschmidtj changed the title [fix] Language selector: add prop for display lang for bug fix fix: Language selector: add prop for display lang for bug fix Oct 6, 2023
@github-actions
Copy link
Contributor

github-actions bot commented Oct 6, 2023

Warnings
⚠️ This PR does not include changes to tests, even though it affects source code.
⚠️ It looks like there are new component (JSX/TSX) files, but the entrypoint (index.ts) has not changed. - Did you forget to export new components from the library entrypoint?

Generated by 🚫 dangerJS against 480c2e3

Copy link
Contributor

@werdnanoslen werdnanoslen left a comment

Choose a reason for hiding this comment

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

I can't get the 2-lang variant to toggle (tested on Mac Firefox)
Oct-06-2023 11-46-16

@kleinschmidtj
Copy link
Contributor Author

@werdnanoslen Yeah, these stories are misleading. That prop would be used with a saved i18n locale. So instead of passing a static value as in the story, it would use i18n.language in conjunction with onClick() handlers that would use i18n.changeLanguage().

I'll make sure to write unit tests with this in mind, but maybe we consider getting rid of the stories.

@brandonlenz
Copy link
Contributor

@werdnanoslen Yeah, these stories are misleading. That prop would be used with a saved i18n locale. So instead of passing a static value as in the story, it would use i18n.language in conjunction with onClick() handlers that would use i18n.changeLanguage().

I'll make sure to write unit tests with this in mind, but maybe we consider getting rid of the stories.

@kleinschmidtj if I'm understanding correctly, it should be possible to give your storybook example a useState (see Pagination.stories.tsx as an example), where the react state can serve as a mock for "saving and pulling the value from somewhere"

@kleinschmidtj
Copy link
Contributor Author

@werdnanoslen Yeah, these stories are misleading. That prop would be used with a saved i18n locale. So instead of passing a static value as in the story, it would use i18n.language in conjunction with onClick() handlers that would use i18n.changeLanguage().
I'll make sure to write unit tests with this in mind, but maybe we consider getting rid of the stories.

@kleinschmidtj if I'm understanding correctly, it should be possible to give your storybook example a useState (see Pagination.stories.tsx as an example), where the react state can serve as a mock for "saving and pulling the value from somewhere"

Oh excellent @brandonlenz ! I have never done that and wasn't sure that was something I could do. I will look there. Thank you.

@kleinschmidtj
Copy link
Contributor Author

Copy link
Contributor

@werdnanoslen werdnanoslen left a comment

Choose a reason for hiding this comment

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

Approving conceptually but I haven't reviewed the code. Good addition!

@brandonlenz
Copy link
Contributor

@kleinschmidtj Nice! 🚢

@kleinschmidtj kleinschmidtj enabled auto-merge (squash) October 18, 2023 14:10
@kleinschmidtj kleinschmidtj merged commit df68d0d into main Oct 18, 2023
5 checks passed
@kleinschmidtj kleinschmidtj deleted the jfk-language-selector-bug branch October 18, 2023 14:19
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] LanguageSelector toggle broken when locale is persistent
3 participants