You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/data/migration/migration-pickers-v7/migration-pickers-v7.md
+66-13Lines changed: 66 additions & 13 deletions
Original file line number
Diff line number
Diff line change
@@ -142,7 +142,7 @@ the field consumes some props (for example `shouldRespectLeadingZeros`) and forw
142
142
143
143
- For the props consumed by the field, the behavior should remain exactly the same with both DOM structures.
144
144
145
-
Both components below will respect the leading zeroes on digit sections:
145
+
Both components below respect the leading zeroes on digit sections:
146
146
147
147
```js
148
148
<DatePicker
@@ -157,7 +157,7 @@ the field consumes some props (for example `shouldRespectLeadingZeros`) and forw
157
157
- For the props forwarded to the `TextField`,
158
158
you can have a look at the next section to see how the migration impact them.
159
159
160
-
Both components below will render a small size UI:
160
+
Both components below render a small size UI:
161
161
162
162
```js
163
163
<DatePicker
@@ -172,9 +172,9 @@ the field consumes some props (for example `shouldRespectLeadingZeros`) and forw
172
172
#### Migrate `slotProps.textField`
173
173
174
174
If you are passing props to `slotProps.textField`,
175
-
these props will now be received by `PickersTextField`and should keep working the same way as before.
175
+
the `PickersTextField` component now receives these props and should keep working the same as before.
176
176
177
-
Both components below will render a small size UI:
177
+
Both components below render a small size UI:
178
178
179
179
```js
180
180
<DatePicker
@@ -188,13 +188,13 @@ Both components below will render a small size UI:
188
188
189
189
:::info
190
190
If you are passing `inputProps` to `slotProps.textField`,
191
-
these props will now be passed to the hidden `<input />` element.
191
+
these props are now passed to the hidden `<input />` element.
192
192
:::
193
193
194
194
#### Migrate `slots.field`
195
195
196
196
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.
197
-
This new component will need to use the `PickersSectionList` component instead of an `<input />` HTML element.
197
+
This new component needs to use the `PickersSectionList` component instead of an `<input />` HTML element.
198
198
199
199
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.
200
200
@@ -309,6 +309,59 @@ const theme = createTheme({
309
309
});
310
310
```
311
311
312
+
### Clean the `ownerState`
313
+
314
+
The `ownerState` is an object describing the current state of a given component to let you do more advanced customization.
315
+
It is used in two different APIs:
316
+
317
+
1. In the theme's `styleOverrides`, the `ownerState` is passed to the function that returns the style:
318
+
319
+
```ts
320
+
const theme =createTheme({
321
+
components: {
322
+
MuiDateCalendar: {
323
+
styleOverrides: {
324
+
root: ({ ownerState }) => ({
325
+
/** Style based on the ownerState */
326
+
}),
327
+
},
328
+
},
329
+
},
330
+
});
331
+
```
332
+
333
+
2. In the `slotProps`, the `ownerState` is passed to the function that returns the custom props:
334
+
335
+
```tsx
336
+
<DatePicker
337
+
slotProps={{
338
+
actionBar: (ownerState) => ({
339
+
/** Props based on the ownerState */
340
+
}),
341
+
}}
342
+
/>
343
+
```
344
+
345
+
Before version `v8.x`, the `ownerState` contained every prop of the component, plus some additional internal states if needed.
346
+
This presented a few problems:
347
+
348
+
- It was hard to know which ancestor defines the `ownerState` and therefore which props it contains (is the `actionBar` slot handled by `DatePicker`, by `DesktopDatePicker` or by `PickerLayout`?).
349
+
350
+
- Many properties of the `ownerState` were not intended for public use, which complicated the evolution of the codebase. All the props received by an internal component became part of the public API, and consequently, any changes to them would have resulted in a breaking change.
351
+
352
+
- Some properties that would have been useful for customizing a component were not present if the component was not using them by default. For example, if the built-in styles for the `actionBar` didn't need to know if the picker is disabled, then the `ownerState` of the `actionBar` didn't contain this information.
353
+
354
+
- The naming of the props made it difficult to understand which element they applied to. If the `ownerState` of the `monthButton` slot contained `disabled`, it was hard to establish whether the disabled state applied to the `monthButton` or the Picker itself.
355
+
356
+
To solve these issues, the `ownerState` has been reworked.
357
+
Every component's `ownerState` contains a shared set of properties describing the state of the picker it is in (`isPickerValueEmpty`, `isPickerOpen`, `isPickerDisabled`, `isPickerReadOnly`, `pickerVariant` and `pickerOrientation`).
358
+
Some component's `ownerState` contain additional properties describing their own state (`isMonthDisabled` for the month button, `toolbarOrientation` for the toolbar, `isDaySelected` for the day button, etc.).
359
+
360
+
:::success
361
+
Most of the properties needed to properly customize your component should be present in the `ownerState`.
362
+
If you need some property that is currently not included, please [open an issue](https://github.com/mui/mui-x/issues/new/choose) in the MUI X repository.
363
+
:::
364
+
312
365
### ⏩ Field editing on mobile Pickers
313
366
314
367
The field is now editable if rendered inside a mobile Picker.
@@ -379,8 +432,8 @@ This change causes a few breaking changes:
379
432
```diff
380
433
const theme = createTheme({
381
434
components: {
382
-
- PickersMonth: {
383
-
+ MonthCalendar: {
435
+
- MuiPickersMonth: {
436
+
+ MuiMonthCalendar: {
384
437
styleOverrides: {
385
438
- monthButton: {
386
439
+ button: {
@@ -420,8 +473,8 @@ This change causes a few breaking changes:
420
473
```diff
421
474
const theme = createTheme({
422
475
components: {
423
-
- PickersYear: {
424
-
+ YearCalendar: {
476
+
- MuiPickersYear: {
477
+
+ MuiYearCalendar: {
425
478
styleOverrides: {
426
479
- yearButton: {
427
480
+ button: {
@@ -824,10 +877,10 @@ If the updated values do not fit your use case, you can [override them](/x/react
824
877
825
878
// This contains a small behavior change.
826
879
// If the picker is not controlled and has a default value,
827
-
// opening it and calling `acceptValueChanges` without any change will call `onAccept`
880
+
// opening it and calling `acceptValueChanges` without any change calls `onAccept`
828
881
// with the default value.
829
-
// Whereas before, opening it and calling `onDimiss` without any change would
830
-
// not have called `onAccept`.
882
+
// Whereas before, opening it and calling `onDimiss` without any change
0 commit comments