-
Notifications
You must be signed in to change notification settings - Fork 174
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #688 from strapi/fix/datepicker-locale
DatePicker: Allow to pass in a locale
- Loading branch information
Showing
5 changed files
with
383 additions
and
71 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
39 changes: 39 additions & 0 deletions
39
packages/strapi-design-system/src/DatePicker/__tests__/DatePicker.spec.js
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,39 @@ | ||
import * as React from 'react'; | ||
import { render, screen } from '@testing-library/react'; | ||
|
||
import { DatePicker } from '../DatePicker'; | ||
|
||
import { lightTheme } from '../../themes'; | ||
import { ThemeProvider } from '../../ThemeProvider'; | ||
|
||
describe('DatePicker', () => { | ||
describe('Locale prop', () => { | ||
const renderDate = (locale) => | ||
render( | ||
<ThemeProvider theme={lightTheme}> | ||
<DatePicker | ||
label="date" | ||
locale={locale} | ||
selectedDateLabel={(formattedDate) => `Date picker, current is ${formattedDate}`} | ||
selectedDate={new Date('Tue Sep 06 2022')} | ||
/> | ||
</ThemeProvider>, | ||
); | ||
|
||
it('should format by EN locale by default', () => { | ||
renderDate(); | ||
|
||
const input = screen.getByRole('textbox'); | ||
|
||
expect(input.value).toMatchInlineSnapshot('"9/6/2022"'); | ||
}); | ||
|
||
it('should format by the DE locale when passed', () => { | ||
renderDate('de-DE'); | ||
|
||
const input = screen.getByRole('textbox'); | ||
|
||
expect(input.value).toMatchInlineSnapshot('"6.9.2022"'); | ||
}); | ||
}); | ||
}); |
4 changes: 2 additions & 2 deletions
4
packages/strapi-design-system/src/DatePicker/utils/formatDate.js
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 |
---|---|---|
@@ -1,5 +1,5 @@ | ||
export const formatDate = (date) => { | ||
const langFormatter = new Intl.DateTimeFormat(); | ||
export const formatDate = (date, locale) => { | ||
const langFormatter = new Intl.DateTimeFormat(locale); | ||
|
||
return langFormatter.format(date); | ||
}; |
Oops, something went wrong.