Skip to content

Commit 1a9ccca

Browse files
fucadzidevadula-nandanheloiselui
authored
fix(DatePicker): date picker month label with "year first" locales (#21174)
* fix: localised month name insertion * docs: contributors list * chore: merge conflict * test(datepicker): cover locale month-label regression --------- Co-authored-by: Nandan Devadula <47176249+devadula-nandan@users.noreply.github.com> Co-authored-by: “heloiselui” <helolui27@gmail.com> Co-authored-by: Heloise Lui <71858203+heloiselui@users.noreply.github.com>
1 parent efcbaa2 commit 1a9ccca

4 files changed

Lines changed: 43 additions & 1 deletion

File tree

.all-contributorsrc

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2171,6 +2171,15 @@
21712171
"doc",
21722172
"code"
21732173
]
2174+
},
2175+
{
2176+
"login": "fucadzi",
2177+
"name": "Natalija Fucadzi",
2178+
"avatar_url": "https://avatars.githubusercontent.com/u/8070263?v=4",
2179+
"profile": "https://github.com/fucadzi",
2180+
"contributions": [
2181+
"code"
2182+
]
21742183
}
21752184
],
21762185
"commitConvention": "none"

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -387,6 +387,7 @@ check out our [Contributing Guide](/.github/CONTRIBUTING.md) and our
387387
<td align="center"><a href="https://github.com/suniltc-ibm"><img src="https://avatars.githubusercontent.com/u/186133269?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Sunil TC</b></sub></a><br /><a href="https://github.com/carbon-design-system/carbon/commits?author=suniltc-ibm" title="Code">💻</a></td>
388388
<td align="center"><a href="https://github.com/baadhira"><img src="https://avatars.githubusercontent.com/u/69342013?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Badira P P</b></sub></a><br /><a href="https://github.com/carbon-design-system/carbon/commits?author=baadhira" title="Code">💻</a></td>
389389
<td align="center"><a href="https://github.com/harishjanardhanan"><img src="https://avatars.githubusercontent.com/u/32760275?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Harish</b></sub></a><br /><a href="https://github.com/carbon-design-system/carbon/commits?author=harishjanardhanan" title="Documentation">📖</a> <a href="https://github.com/carbon-design-system/carbon/commits?author=harishjanardhanan" title="Code">💻</a></td>
390+
<td align="center"><a href="https://github.com/fucadzi"><img src="https://avatars.githubusercontent.com/u/8070263?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Natalija Fucadzi</b></sub></a><br /><a href="https://github.com/carbon-design-system/carbon/commits?author=fucadzi" title="Code">💻</a></td>
390391
</tr>
391392
</table>
392393

packages/react/src/components/DatePicker/DatePicker-test.js

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1428,9 +1428,41 @@ describe('Date picker with locale', () => {
14281428
await userEvent.click(screen.getByTestId('input'));
14291429
const year = screen.getByDisplayValue('2022');
14301430
const month = screen.getByText('1月');
1431+
const monthYearContainer = year.closest('.flatpickr-current-month');
14311432
expect(year).toBeInTheDocument();
14321433
expect(month).toBeInTheDocument();
14331434
expect(month.compareDocumentPosition(year)).toBe(2);
1435+
expect(monthYearContainer).toContainElement(month);
1436+
});
1437+
1438+
it('should update month label on navigation for year-month locales', async () => {
1439+
render(
1440+
<DatePicker
1441+
onChange={() => {}}
1442+
datePickerType="single"
1443+
locale="lv"
1444+
value="01/01/2022">
1445+
<DatePickerInput
1446+
id="date-picker-input-id"
1447+
placeholder="mm/dd/yyyy"
1448+
labelText="Date picker label"
1449+
data-testid="input"
1450+
/>
1451+
</DatePicker>
1452+
);
1453+
1454+
await userEvent.click(screen.getByTestId('input'));
1455+
const year = screen.getByDisplayValue('2022');
1456+
const monthYearContainer = year.closest('.flatpickr-current-month');
1457+
// eslint-disable-next-line testing-library/no-node-access
1458+
const monthElement = monthYearContainer.querySelector('.cur-month');
1459+
const initialMonthLabel = monthElement.textContent;
1460+
// eslint-disable-next-line testing-library/no-node-access
1461+
const nextMonthButton = document.querySelector('.flatpickr-next-month');
1462+
1463+
await userEvent.click(nextMonthButton);
1464+
1465+
expect(monthElement.textContent).not.toBe(initialMonthLabel);
14341466
});
14351467
});
14361468

packages/react/src/components/DatePicker/DatePicker.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ const carbonFlatpickrMonthSelectPlugin = (config) => (fp) => {
110110
} else {
111111
fp.yearElements[0]
112112
.closest(config.selectorFlatpickrMonthYearContainer)
113-
.insertAdjacentElement('afterend', monthElement);
113+
.insertAdjacentElement('beforeend', monthElement);
114114
}
115115

116116
return monthElement;

0 commit comments

Comments
 (0)