Skip to content

Commit d26f9e6

Browse files
[@mantine/dates] Fix children override not working in MonthsList/YearsList getYearProps/getMonthProps functions (#8488)
* [@mantine/dates] MonthsList/YearsList: Fix children override in getMonthControlProps and getYearControlProps * [@mantine/dates] MonthsList/YearsList: Fix children override in getMonthControlProps and getYearControlProps
1 parent ae08675 commit d26f9e6

File tree

4 files changed

+37
-2
lines changed

4 files changed

+37
-2
lines changed

packages/@mantine/dates/src/components/MonthsList/MonthsList.story.tsx

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import dayjs from 'dayjs';
22
import { useState } from 'react';
3+
import { DateStringValue } from '../../types';
34
import { MonthsList } from './MonthsList';
45

56
export default { title: 'MonthsList' };
@@ -36,6 +37,21 @@ export function MaxDate() {
3637
);
3738
}
3839

40+
export function WithGetMonthControlPropsChildren() {
41+
return (
42+
<div style={{ padding: 40, width: 320 }}>
43+
<MonthsList
44+
year="2022-01-01"
45+
getMonthControlProps={(date: DateStringValue) => {
46+
return {
47+
children: <strong>{date}</strong>,
48+
};
49+
}}
50+
/>
51+
</div>
52+
);
53+
}
54+
3955
export function WithSelection() {
4056
const [selected, setSelected] = useState<string>(dayjs().format('YYYY-MM-DD'));
4157

packages/@mantine/dates/src/components/MonthsList/MonthsList.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@ export const MonthsList = factory<MonthsListFactory>((_props, ref) => {
125125
const cells = monthsRow.map((month, cellIndex) => {
126126
const controlProps = getMonthControlProps?.(month);
127127
const isMonthInTabOrder = dayjs(month).isSame(monthInTabOrder, 'month');
128+
128129
return (
129130
<td
130131
key={cellIndex}
@@ -166,7 +167,8 @@ export const MonthsList = factory<MonthsListFactory>((_props, ref) => {
166167
}}
167168
tabIndex={__preventFocus || !isMonthInTabOrder ? -1 : 0}
168169
>
169-
{dayjs(month).locale(ctx.getLocale(locale)).format(monthsListFormat)}
170+
{controlProps?.children ??
171+
dayjs(month).locale(ctx.getLocale(locale)).format(monthsListFormat)}
170172
</PickerControl>
171173
</td>
172174
);

packages/@mantine/dates/src/components/YearsList/YearsList.story.tsx

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import dayjs from 'dayjs';
22
import { useState } from 'react';
3+
import { DateStringValue } from '../../types';
34
import { YearsList } from './YearsList';
45

56
export default { title: 'YearsList' };
@@ -36,6 +37,21 @@ export function MaxDate() {
3637
);
3738
}
3839

40+
export function WithGetYearsControlPropsChildren() {
41+
return (
42+
<div style={{ padding: 40, width: 320 }}>
43+
<YearsList
44+
decade="2022-02-01"
45+
getYearControlProps={(date: DateStringValue) => {
46+
return {
47+
children: <strong>{date}</strong>,
48+
};
49+
}}
50+
/>
51+
</div>
52+
);
53+
}
54+
3955
export function WithRange() {
4056
return (
4157
<div style={{ padding: 40, width: 320 }}>

packages/@mantine/dates/src/components/YearsList/YearsList.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,8 @@ export const YearsList = factory<YearsListFactory>((_props, ref) => {
160160
}}
161161
tabIndex={__preventFocus || !isYearInTabOrder ? -1 : 0}
162162
>
163-
{dayjs(year).locale(ctx.getLocale(locale)).format(yearsListFormat)}
163+
{controlProps?.children ??
164+
dayjs(year).locale(ctx.getLocale(locale)).format(yearsListFormat)}
164165
</PickerControl>
165166
</td>
166167
);

0 commit comments

Comments
 (0)