-
Notifications
You must be signed in to change notification settings - Fork 66
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(datepickers): Enable setting locale from prop. (#3626)
* feat(datepickers): Enable setting locale from prop. Resolves #3596 * feat(datepickers): Check for navigator-existence to work with SSR * docs(datepickers): Document how to specify locale
- Loading branch information
Showing
6 changed files
with
138 additions
and
98 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
packages/eds-core-react/src/components/Datepicker/utils/useGetLocale.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { useLocale } from 'react-aria' | ||
|
||
export const useGetLocale = (locale?: string) => { | ||
const { locale: externalLocale } = useLocale() | ||
// react-aria defaults to navigator.language if no locale is provided. If these are equal, we override by using the system default locale | ||
const defaultLocale = | ||
(typeof navigator !== 'undefined' && navigator.language) || 'en-US' | ||
const fallbackLocale = new Intl.DateTimeFormat().resolvedOptions().locale | ||
return ( | ||
locale ?? | ||
(externalLocale === defaultLocale ? undefined : externalLocale) ?? | ||
fallbackLocale | ||
) | ||
} |