-
Notifications
You must be signed in to change notification settings - Fork 3
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
Implement LocaleSwitcher Component #273
base: main
Are you sure you want to change the base?
Conversation
- this wraps the `react-uswds` `LanguageSelector` component - it is functional, but I have some UX concerns - we will likely want to tweak styling
added test for LocaleSwitcher
this currently fails due to issue w/ `react-uswds` component
// This won't actually work because the NextIntlProvider relies on middleware that isn't available in tests | ||
// expect( | ||
// await screen.findByRole("button", { name: "English" }) | ||
// ).toBeInTheDocument(); | ||
}); |
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.
Left this in to note an a11y issue with the current version of the react-uswds
component.
import { LanguageDefinition, LanguageSelector } from "@trussworks/react-uswds"; | ||
|
||
// Currently, the `react-uswds` component erroneously sets 'usa-language-container' class | ||
// on both the container and the button, which causes incorrect positioning relative to nav items |
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.
Could we open a PR to fix that for them? They're usually pretty open to contributions.
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.
app/src/i18n/navigation.ts
Outdated
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.
Is this file needed? I think the middleware handles prefixing and automatically redirecting to the expected locale prefix based on the preferred locale. The localePrefix
setting in this file also looks different than what's set in the middleware.
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 file is for re-exporting some enhanced versions of NextJS navigation functions. Its usage is documented here:
https://next-intl-docs.vercel.app/docs/routing/navigation#shared-pathnames
That said, I totally forgot to update to our actual locales and instead just copy-pasted what they had in the docs. 😓
I'm updating it to just pull locales
from the existing export so they are only defined once.
I'm not entirely certain of their reasons for keeping this as its own file vs simply adding these exports to config.ts
. My guess is that it is largely for slightly clearer code since it's specifically re-exporting stuff from next/navigation
. I'm sort of ambivalent as to where we'd prefer to put it. 🤷 Thoughts?
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.
Is it accurate to say that these utilities are only needed for the locale switcher component?
It seems like the language is preserved fine when using next/navigation
for routing elsewhere, so am wondering if these could be co-located in the component's file.
I was able to test usage of normal next/navigation
routing by adding the following to the homepage and observing the URL and header's translated text. Seems to work:
// TestButton.tsx
"use client";
import { useRouter } from "next/navigation";
export default function TestButton() {
const router = useRouter();
return (
<button onClick={() => router.push("/health")}>Go to health page</button>
);
}
Ticket
Resolves #237
Changes
LocaleSwitcher
component and added it as the final item in the nav inHeader
react-uswds
LanguageSelector
componentreact-uswds
component erroneously applying.usa-language-container
class to button as well as wrapping divreact-uswds
component erroneously applying aaria-controls
prop even in dual-language mode when the corresponding element isn't present (it is in dropdown/multiple-language mode)Context for reviewers
This can be seen in the nav when running the app in localhost. However, there are multiple issues with the implementation from
react-uswds
that make me think we may want to re-implement our own until such time as that version gets updated. I do also still have some UX concerns over both the basic USWDS implementation and the specific one fromreact-uswds
.Testing