Skip to content

Commit

Permalink
feat: set document lang attribute
Browse files Browse the repository at this point in the history
  • Loading branch information
KaiVandivier committed Jan 25, 2024
1 parent 1d62c34 commit 0c48e4f
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
1 change: 1 addition & 0 deletions adapter/src/utils/useLocale.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export const useLocale = ({ userSettings, configDirection }) => {
// Intl.Locale dir utils aren't supported in firefox, so use i18n
const localeDirection = i18n.dir(locale.language)
setDocumentDirection({ localeDirection, configDirection })
document.documentElement.setAttribute('lang', locale.baseName)

setResult({ locale, direction: localeDirection })
}, [userSettings, configDirection])
Expand Down
17 changes: 17 additions & 0 deletions adapter/src/utils/useLocale.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -301,3 +301,20 @@ describe('config direction is respected for the document direction', () => {
)
})
})

test('document `lang` attribute is set', () => {
jest.spyOn(document.documentElement, 'setAttribute')
const userSettings = { keyUiLocale: 'pt-BR' }

renderHook(() =>
useLocale({
userSettings,
configDirection: undefined,
})
)

expect(document.documentElement.setAttribute).toHaveBeenCalledWith(
'lang',
'pt-BR'
)
})

0 comments on commit 0c48e4f

Please sign in to comment.