-
Notifications
You must be signed in to change notification settings - Fork 85
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
feat: added language selector #2531
Conversation
This uses links per USWDS' implementation, but I think it's also likely that people will want to implement in-page with buttons using |
- added both buttons and links, depending on given click action - added missing click action to 2-lang button - added custom class story
Latest commit adds this, so ready for review (pending styles |
Fixed styling now that 3.3 styles are merged, and filed an issue to let us remove that later if merged. This is fully ready for review now |
Hm, not sure I'm interpreting the build rule correctly, but given my |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks great! Just left a couple of minor questions. Didn't feel like they were big enough to request changes.
}: LanguageSelectorButtonProps & | ||
JSX.IntrinsicElements['button']): React.ReactElement => { | ||
const classes = classnames('usa-button', 'usa-language__link', className) | ||
const labelNotEn = labelAttr && <span lang={labelAttr}>{label}</span> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since you removed the curLangNotEn
variable in LanguageSelector
and are no longer using the labelAttr
prop from there, do we still need this labelNotEn
variable? Looking at the test coverage, the <span>
here is not checked, and it just made me wonder if it is still needed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd still keep it on the button so that the button contents get the same lang attr treatment. I just updated it to handle that better if you want to see those changes
|
||
type LanguageSelectorButtonProps = { | ||
label: string | ||
labelAttr?: string |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we still need the labelAttr
prop? It seems that in order for this prop to be utilized, LanguageSelectorButton
would need to be used outside of the LanguageSelector
component.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it's still useful for the 2 language variant, where the language's text should be tagged. I've updated it a bit to reflect that
so what I have gathered so far is the lint tool is mad at how you used @extend because it can cause specificity issues. I personally don't feel this particular instance carries much of that risk, especially as a temporary solution parked in the index file. I'm seeing if there is a way to push the link styles from uswds dynamically that doesn't use @extend. I'm pretty sure those styles are stored in a mixin already which we can call with @include for a similarly elegant solution that does not make us have to override lint rules |
im now seeing that the styles for this particular link instance are pretty custom. maybe our quickest path forward is just grabbing the scss and pasting it where @extend would have output it. not as sleek but it is a temp solution. im trying that now to see if it works |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@use 'uswds-core' as *;
would need to be added up top for the suggestion to work
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@werdnanoslen did you include this change too when you tested the utilities? You need to have uswds-core in scope for utilities to work
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried, but i kept getting build errors
src/styles/index.scss
Outdated
// This just allows buttons as well as links in the LanguageSelector | ||
// It can be removed when https://github.com/uswds/uswds/issues/5409 is fixed | ||
.usa-language__submenu .usa-language__submenu-item button { | ||
@extend a; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@extend a; | |
color: color('white'); | |
display: block; | |
line-height: line-height($theme-navigation-font-family, 3); | |
padding: 0; | |
padding: units(1); | |
text-decoration: none; | |
width: 100%; /* this is something that was actually missing when we were doing the extend because button widths hve different default widths than block element links */ | |
&:focus { | |
outline-offset: units('neg-05'); | |
} | |
&:hover { | |
color: color('white'); | |
text-decoration: underline; | |
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this just grips the scss right out of the package, replicating the @extend output.
only advantage of this over using @extend is it stops us from overriding lint rules, and it makes sure the focus indicator behaves the same with with width assignment I added, but you could also add that using the @extend.
I would defer to the app eng folks on how they feel about overriding lint rules, but if you are looking to get this going this is how I'd get around it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks! committed that
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hm, we don't seem to be using utilities anywhere, and I couldn't get it to work, so I've just copied the compiled styles over here for now.
) | ||
|
||
if (langs.length > 2) { | ||
const [isOpen, setIsOpen] = useState(false) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thought i'd jump the gun a bit and try this in IRS project. Getting the following eslint error there:
React Hook "useState" is called conditionally. React Hooks must be called in the exact same order in every component render.eslint[react-hooks/rules-of-hooks](https://reactjs.org/docs/hooks-rules.html)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
) | ||
} | ||
const [langIndex, setLangIndex] = useState(false) | ||
const curLang = langs[Number(langIndex)] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Getting the same eslint error about this instance ofuseState
as well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
also cannot reproduce the safari issue
Summary
Related Issues or PRs
Resolves #2516
How To Test
Open the stories for LanguageSelector
Screenshots (optional)
Two languages just toggles:
More than two language shows a dropdown: