Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[pickers] Remove PickersMonth and PickersYear from the theme and remove the div wrapping each button #15806

Merged
merged 21 commits into from
Dec 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import { LocalizationProvider } from '@mui/x-date-pickers/LocalizationProvider';
import { DateCalendar } from '@mui/x-date-pickers/DateCalendar';

const CustomMonthButton = styled('button')({
margin: '8px 0',
height: 36,
width: 72,
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import { LocalizationProvider } from '@mui/x-date-pickers/LocalizationProvider';
import { DateCalendar } from '@mui/x-date-pickers/DateCalendar';

const CustomMonthButton = styled('button')({
margin: '8px 0',
height: 36,
width: 72,
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import { LocalizationProvider } from '@mui/x-date-pickers/LocalizationProvider';
import { DateCalendar } from '@mui/x-date-pickers/DateCalendar';

const CustomYearButton = styled('button')({
margin: '8px 0',
height: 36,
width: 72,
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import { LocalizationProvider } from '@mui/x-date-pickers/LocalizationProvider';
import { DateCalendar } from '@mui/x-date-pickers/DateCalendar';

const CustomYearButton = styled('button')({
margin: '8px 0',
height: 36,
width: 72,
});
Expand Down
24 changes: 3 additions & 21 deletions docs/data/date-pickers/date-picker/examplesConfig.styling.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -115,25 +115,7 @@ export const staticDatePickerExamples: PickersSubcomponentType = {
componentProps: { views: ['month'] },
},
},
slots: ['root'],
},
PickersMonth: {
examples: {
customTheme: {
type: 'success',
componentProps: { views: ['month'] },
},
sxProp: {
type: 'success',
componentProps: { views: ['month'] },
},

styledComponents: {
type: 'success',
componentProps: { views: ['month'] },
},
},
slots: ['root', 'monthButton'],
slots: ['root', 'button'],
},
};

Expand Down Expand Up @@ -240,7 +222,7 @@ export const datePickerExamples: PickersSubcomponentType = {
},
slots: ['root', 'today'],
},
PickersMonth: {
MonthCalendar: {
examples: {
customTheme: {
type: 'success',
Expand All @@ -263,7 +245,7 @@ export const datePickerExamples: PickersSubcomponentType = {
componentProps: { views: ['month'] },
},
},
slots: ['root', 'monthButton'],
slots: ['button'],
},
PickersTextField: {
examples: {
Expand Down
98 changes: 91 additions & 7 deletions docs/data/migration/migration-pickers-v7/migration-pickers-v7.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,9 @@ After running the codemods, make sure to test your application and that you don'
Feel free to [open an issue](https://github.com/mui/mui-x/issues/new/choose) for support if you need help to proceed with your migration.
:::

## New DOM structure for the field
## Components breaking changes

### New DOM structure for the field

Before version `v7.x`, the fields' DOM structure consisted of an `<input />`, which held the whole value for the component.
Unfortunately it presented accessibility limitations, which are impossible to resolve.
Expand All @@ -78,15 +80,15 @@ This approach is recommended in [W3C ARIA](https://www.w3.org/WAI/ARIA/apg/patte

Starting with version `v8.x`, the new DOM structure is the default for all fields.

### Fallback to the non-accessible DOM structure
#### Fallback to the non-accessible DOM structure

```tsx
<DateField enableAccessibleFieldDOMStructure={false} />
<DatePicker enableAccessibleFieldDOMStructure={false} />
<DateRangePicker enableAccessibleFieldDOMStructure={false} />
```

### Migrate `slotProps.field`
#### Migrate `slotProps.field`

When using `slotProps.field` to pass props to your field component,
the field consumes some props (for example `shouldRespectLeadingZeros`) and forwards the rest to the `TextField`.
Expand Down Expand Up @@ -120,7 +122,7 @@ the field consumes some props (for example `shouldRespectLeadingZeros`) and forw
/>
```

### Migrate `slotProps.textField`
#### Migrate `slotProps.textField`

If you are passing props to `slotProps.textField`,
these props will now be received by `PickersTextField` and should keep working the same way as before.
Expand All @@ -142,14 +144,14 @@ If you are passing `inputProps` to `slotProps.textField`,
these props will now be passed to the hidden `<input />` element.
:::

### Migrate `slots.field`
#### Migrate `slots.field`

If you are passing a custom field component to your pickers, you need to create a new one that is using the accessible DOM structure.
This new component will need to use the `PickersSectionList` component instead of an `<input />` HTML element.

You can have a look at the [Using a custom input](/x/react-date-pickers/custom-field/#using-a-custom-input) section to have a concrete example.

### Migrate `slots.textField`
#### Migrate `slots.textField`

If you are passing a custom `TextField` component to your fields and pickers,
you need to create a new one that is using the accessible DOM structure.
Expand All @@ -162,7 +164,7 @@ please consider having a look at the [Using a custom input](/x/react-date-picker
This approach can be more appropriate for deeper changes.
:::

### Migrate the theme
#### Migrate the theme

If you are using the theme to customize `MuiTextField`,
you need to pass the same config to `MuiPickersTextField`:
Expand Down Expand Up @@ -260,6 +262,88 @@ const theme = createTheme({
});
```

### Month Calendar

To simplify the theme and class structure, the `<PickersMonth />` component has been moved inside the Month Calendar component.
This change causes a few breaking changes:

- The classes from `pickersMonthClasses` have been moved inside `monthCalendarClasses`:

```diff
-import { pickersMonthClasses } from '@mui/x-date-pickers/MonthCalendar';
+import { monthCalendarClasses } from '@mui/x-date-pickers/MonthCalendar';

-const buttonClassName = pickersMonthClasses.monthButton;
+const buttonClassName = monthCalendarClasses.button;

-const selectedButtonClassName = pickersMonthClasses.selected;
+const selectedButtonClassName = monthCalendarClasses.selected;

-const disabledButtonClassName = pickersMonthClasses.disabled;
+const disabledButtonClassName = monthCalendarClasses.disabled;
```

- The `monthButton` slot of the `PickersMonth` style overrides has been replaced by the `button` slot of the `MonthCalendar` theme entry:

```diff
const theme = createTheme({
components: {
- PickersMonth: {
+ MonthCalendar: {
styleOverrides: {
- monthButton: {
+ button: {
color: 'red',
},
},
},
},
});
```

- The button to render a single month is no longer wrapped in a `<div />`, the spacing are instead defined inside the `root` slot of the Month Calendar.

### Year Calendar

To simplify the theme and class structure, the `<PickersYear />` component has been moved inside the Year Calendar component.
This change causes a few breaking changes:

- The classes from `pickersYearClasses` have been moved inside `yearCalendarClasses`:

```diff
-import { pickersYearClasses } from '@mui/x-date-pickers/YearCalendar';
+import { yearCalendarClasses } from '@mui/x-date-pickers/YearCalendar';

-const buttonClassName = pickersYearClasses.monthButton;
+const buttonClassName = yearCalendarClasses.button;

-const selectedButtonClassName = pickersYearClasses.selected;
+const selectedButtonClassName = yearCalendarClasses.selected;

-const disabledButtonClassName = pickersYearClasses.disabled;
+const disabledButtonClassName = yearCalendarClasses.disabled;
```

- The `yearButton` slot of the `PickersYear` style overrides has been replaced by the `button` slot of the `YearCalendar` theme entry:

```diff
const theme = createTheme({
components: {
- PickersYear: {
+ YearCalendar: {
styleOverrides: {
- yearButton: {
+ button: {
color: 'red',
},
},
},
},
});
```

- The button to render a single year is no longer wrapped in a `<div />`, the spacing are instead defined inside the `root` slot of the Year Calendar.

## Slots breaking changes

### Slot: `layout`
Expand Down
18 changes: 18 additions & 0 deletions docs/pages/x/api/date-pickers/month-calendar.json
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,29 @@
}
],
"classes": [
{
"key": "button",
"className": "MuiMonthCalendar-button",
"description": "Styles applied to the button element that represents a single month",
"isGlobal": false
},
{
"key": "disabled",
"className": "Mui-disabled",
"description": "Styles applied to a disabled button element.",
"isGlobal": true
},
{
"key": "root",
"className": "MuiMonthCalendar-root",
"description": "Styles applied to the root element.",
"isGlobal": false
},
{
"key": "selected",
"className": "Mui-selected",
"description": "Styles applied to a selected button element.",
"isGlobal": true
}
],
"spread": true,
Expand Down
18 changes: 18 additions & 0 deletions docs/pages/x/api/date-pickers/year-calendar.json
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,29 @@
}
],
"classes": [
{
"key": "button",
"className": "MuiYearCalendar-button",
"description": "Styles applied to the button element that represents a single year",
"isGlobal": false
},
{
"key": "disabled",
"className": "Mui-disabled",
"description": "Styles applied to a disabled button element.",
"isGlobal": true
},
{
"key": "root",
"className": "MuiYearCalendar-root",
"description": "Styles applied to the root element.",
"isGlobal": false
},
{
"key": "selected",
"className": "Mui-selected",
"description": "Styles applied to a selected button element.",
"isGlobal": true
}
],
"spread": true,
Expand Down
8 changes: 4 additions & 4 deletions docs/src/modules/components/overview/MainDemo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ const components: Components<Theme> = {
}),
},
},
MuiPickersMonth: {
MuiMonthCalendar: {
styleOverrides: {
monthButton: ({ theme }) => ({
button: ({ theme }) => ({
fontWeight: 400,
fontSize: '0.875rem',
borderRadius: theme.shape.borderRadius,
Expand All @@ -37,9 +37,9 @@ const components: Components<Theme> = {
}),
},
},
MuiPickersYear: {
MuiYearCalendar: {
styleOverrides: {
yearButton: ({ theme }) => ({
button: ({ theme }) => ({
fontWeight: 400,
fontSize: '0.875rem',
borderRadius: theme.shape.borderRadius,
Expand Down
8 changes: 4 additions & 4 deletions docs/src/modules/components/overview/themes/customTheme.ts
Original file line number Diff line number Diff line change
Expand Up @@ -371,16 +371,16 @@ export const getCustomTheme = (mode: PaletteMode, config: Config): ThemeOptions
}),
},
},
MuiPickersMonth: {
MuiMonthCalendar: {
styleOverrides: {
monthButton: ({ theme }) => ({
button: ({ theme }) => ({
borderRadius: theme.shape.borderRadius,
}),
},
},
MuiPickersYear: {
MuiYearCalendar: {
styleOverrides: {
yearButton: ({ theme }) => ({
button: ({ theme }) => ({
borderRadius: theme.shape.borderRadius,
}),
},
Expand Down
15 changes: 5 additions & 10 deletions docs/src/modules/components/overview/themes/md3.ts
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,6 @@ export const getMD3Theme = (mode: PaletteMode, config: Config): ThemeOptions =>
height: 'fit-content',
maxHeight: 'initial',
},

viewTransitionContainer: ({ theme }) => ({
height: theme.mixins.density.height * 7 + theme.mixins.density.spacing * 6,
}),
Expand All @@ -258,6 +257,11 @@ export const getMD3Theme = (mode: PaletteMode, config: Config): ThemeOptions =>
borderBottom: `1px solid ${theme.palette.divider}`,
alignContent: 'flex-start',
width: theme.mixins.density.width * 7 + theme.mixins.density.spacing * 6 + 40,
columnGap: '12px',
}),
flaviendelangle marked this conversation as resolved.
Show resolved Hide resolved
button: ({ theme }) => ({
borderRadius: theme.shape.borderRadius,
height: theme.mixins.density.height,
}),
},
},
Expand Down Expand Up @@ -298,15 +302,6 @@ export const getMD3Theme = (mode: PaletteMode, config: Config): ThemeOptions =>
}),
},
},
MuiPickersYear: {
styleOverrides: {
yearButton: ({ theme, ownerState }) => ({
borderRadius: theme.shape.borderRadius,
height: theme.mixins.density.height,
...(!ownerState.selected && { color: theme.palette.text.secondary }),
}),
},
},
MuiCard: {
styleOverrides: {
root: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,20 @@
},
"value": { "description": "The selected value. Used when the component is controlled." }
},
"classDescriptions": { "root": { "description": "Styles applied to the root element." } },
"classDescriptions": {
"button": {
"description": "Styles applied to the button element that represents a single month"
},
"disabled": {
"description": "Styles applied to {{nodeName}}.",
"nodeName": "a disabled button element"
},
"root": { "description": "Styles applied to the root element." },
"selected": {
"description": "Styles applied to {{nodeName}}.",
"nodeName": "a selected button element"
}
},
"slotDescriptions": {
"monthButton": "Button displayed to render a single month in the <code>month</code> view."
}
Expand Down
Loading
Loading