Skip to content

Commit 8b72d66

Browse files
flaviendelangleLukasTy
authored andcommitted
[pickers] Remove the form props from the layout and the toolbar slots (mui#15492)
1 parent 86dde6e commit 8b72d66

File tree

24 files changed

+53
-152
lines changed

24 files changed

+53
-152
lines changed

docs/data/migration/migration-pickers-v7/migration-pickers-v7.md

+42
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,48 @@ const theme = createTheme({
254254
});
255255
```
256256

257+
## Slots breaking changes
258+
259+
### Slot: `layout`
260+
261+
- The component passed to the `layout` slot no longer receives a `disabled` prop, instead you can use the `usePickersContext` hook:
262+
263+
```diff
264+
-console.log(props.disabled);
265+
+import { usePickersContext } from '@mui/x-date-pickers/hooks';
266+
+const { disabled } = usePickersContext();
267+
+console.log(disabled);
268+
```
269+
270+
- The component passed to the `layout` slot no longer receives a `readOnly` prop, instead you can use the `usePickersContext` hook:
271+
272+
```diff
273+
-console.log(props.readOnly);
274+
+import { usePickersContext } from '@mui/x-date-pickers/hooks';
275+
+const { readOnly } = usePickersContext();
276+
+console.log(readOnly);
277+
```
278+
279+
### Slot: `toolbar`
280+
281+
- The component passed to the `toolbar` slot no longer receives a `disabled` prop, instead you can use the `usePickersContext` hook:
282+
283+
```diff
284+
-console.log(props.disabled);
285+
+import { usePickersContext } from '@mui/x-date-pickers/hooks';
286+
+const { disabled } = usePickersContext();
287+
+console.log(disabled);
288+
```
289+
290+
- The component passed to the `toolbar` slot no longer receives a `readOnly` prop, instead you can use the `usePickersContext` hook:
291+
292+
```diff
293+
-console.log(props.readOnly);
294+
+import { usePickersContext } from '@mui/x-date-pickers/hooks';
295+
+const { readOnly } = usePickersContext();
296+
+console.log(readOnly);
297+
```
298+
257299
## Renamed variables
258300

259301
The following variables were renamed to have a coherent `Picker` / `Pickers` prefix:

docs/pages/x/api/date-pickers/date-picker-toolbar.json

-2
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,7 @@
2020
"required": true
2121
},
2222
"classes": { "type": { "name": "object" }, "additionalInfo": { "cssApi": true } },
23-
"disabled": { "type": { "name": "bool" }, "default": "false" },
2423
"hidden": { "type": { "name": "bool" }, "default": "`true` for Desktop, `false` for Mobile." },
25-
"readOnly": { "type": { "name": "bool" }, "default": "false" },
2624
"sx": {
2725
"type": {
2826
"name": "union",

docs/pages/x/api/date-pickers/date-range-picker-toolbar.json

-2
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,7 @@
1111
"required": true
1212
},
1313
"classes": { "type": { "name": "object" }, "additionalInfo": { "cssApi": true } },
14-
"disabled": { "type": { "name": "bool" }, "default": "false" },
1514
"hidden": { "type": { "name": "bool" }, "default": "`true` for Desktop, `false` for Mobile." },
16-
"readOnly": { "type": { "name": "bool" }, "default": "false" },
1715
"sx": {
1816
"type": {
1917
"name": "union",

docs/pages/x/api/date-pickers/date-time-picker-toolbar.json

-2
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,7 @@
1313
"required": true
1414
},
1515
"classes": { "type": { "name": "object" }, "additionalInfo": { "cssApi": true } },
16-
"disabled": { "type": { "name": "bool" }, "default": "false" },
1716
"hidden": { "type": { "name": "bool" }, "default": "`true` for Desktop, `false` for Mobile." },
18-
"readOnly": { "type": { "name": "bool" }, "default": "false" },
1917
"sx": {
2018
"type": {
2119
"name": "union",

docs/pages/x/api/date-pickers/date-time-range-picker-toolbar.json

-2
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,7 @@
2020
"required": true
2121
},
2222
"classes": { "type": { "name": "object" }, "additionalInfo": { "cssApi": true } },
23-
"disabled": { "type": { "name": "bool" }, "default": "false" },
2423
"hidden": { "type": { "name": "bool" }, "default": "`true` for Desktop, `false` for Mobile." },
25-
"readOnly": { "type": { "name": "bool" }, "default": "false" },
2624
"sx": {
2725
"type": {
2826
"name": "union",

docs/pages/x/api/date-pickers/pickers-layout.json

-2
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,9 @@
22
"props": {
33
"isRtl": { "type": { "name": "bool" }, "required": true },
44
"classes": { "type": { "name": "object" }, "additionalInfo": { "cssApi": true } },
5-
"disabled": { "type": { "name": "bool" }, "default": "false" },
65
"orientation": {
76
"type": { "name": "enum", "description": "'landscape'<br>&#124;&nbsp;'portrait'" }
87
},
9-
"readOnly": { "type": { "name": "bool" }, "default": "false" },
108
"slotProps": { "type": { "name": "object" }, "default": "{}" },
119
"slots": {
1210
"type": { "name": "object" },

docs/pages/x/api/date-pickers/time-picker-toolbar.json

-2
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,7 @@
2020
"required": true
2121
},
2222
"classes": { "type": { "name": "object" }, "additionalInfo": { "cssApi": true } },
23-
"disabled": { "type": { "name": "bool" }, "default": "false" },
2423
"hidden": { "type": { "name": "bool" }, "default": "`true` for Desktop, `false` for Mobile." },
25-
"readOnly": { "type": { "name": "bool" }, "default": "false" },
2624
"sx": {
2725
"type": {
2826
"name": "union",

docs/translations/api-docs/date-pickers/date-picker-toolbar/date-picker-toolbar.json

-6
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,11 @@
22
"componentDescription": "",
33
"propDescriptions": {
44
"classes": { "description": "Override or extend the styles applied to the component." },
5-
"disabled": {
6-
"description": "If <code>true</code>, the component is disabled. When disabled, the value cannot be changed and no interaction is possible."
7-
},
85
"hidden": { "description": "If <code>true</code>, show the toolbar even in desktop mode." },
96
"onViewChange": {
107
"description": "Callback called when a toolbar is clicked",
118
"typeDescriptions": { "view": "The view to open" }
129
},
13-
"readOnly": {
14-
"description": "If <code>true</code>, the component is read-only. When read-only, the value cannot be changed but the user can interact with the interface."
15-
},
1610
"sx": {
1711
"description": "The system prop that allows defining system overrides as well as additional CSS styles."
1812
},

docs/translations/api-docs/date-pickers/date-range-picker-toolbar/date-range-picker-toolbar.json

-6
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,11 @@
22
"componentDescription": "",
33
"propDescriptions": {
44
"classes": { "description": "Override or extend the styles applied to the component." },
5-
"disabled": {
6-
"description": "If <code>true</code>, the component is disabled. When disabled, the value cannot be changed and no interaction is possible."
7-
},
85
"hidden": { "description": "If <code>true</code>, show the toolbar even in desktop mode." },
96
"onViewChange": {
107
"description": "Callback called when a toolbar is clicked",
118
"typeDescriptions": { "view": "The view to open" }
129
},
13-
"readOnly": {
14-
"description": "If <code>true</code>, the component is read-only. When read-only, the value cannot be changed but the user can interact with the interface."
15-
},
1610
"sx": {
1711
"description": "The system prop that allows defining system overrides as well as additional CSS styles."
1812
},

docs/translations/api-docs/date-pickers/date-time-picker-toolbar/date-time-picker-toolbar.json

-6
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,11 @@
22
"componentDescription": "",
33
"propDescriptions": {
44
"classes": { "description": "Override or extend the styles applied to the component." },
5-
"disabled": {
6-
"description": "If <code>true</code>, the component is disabled. When disabled, the value cannot be changed and no interaction is possible."
7-
},
85
"hidden": { "description": "If <code>true</code>, show the toolbar even in desktop mode." },
96
"onViewChange": {
107
"description": "Callback called when a toolbar is clicked",
118
"typeDescriptions": { "view": "The view to open" }
129
},
13-
"readOnly": {
14-
"description": "If <code>true</code>, the component is read-only. When read-only, the value cannot be changed but the user can interact with the interface."
15-
},
1610
"sx": {
1711
"description": "The system prop that allows defining system overrides as well as additional CSS styles."
1812
},

docs/translations/api-docs/date-pickers/date-time-range-picker-toolbar/date-time-range-picker-toolbar.json

-6
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,11 @@
22
"componentDescription": "",
33
"propDescriptions": {
44
"classes": { "description": "Override or extend the styles applied to the component." },
5-
"disabled": {
6-
"description": "If <code>true</code>, the component is disabled. When disabled, the value cannot be changed and no interaction is possible."
7-
},
85
"hidden": { "description": "If <code>true</code>, show the toolbar even in desktop mode." },
96
"onViewChange": {
107
"description": "Callback called when a toolbar is clicked",
118
"typeDescriptions": { "view": "The view to open" }
129
},
13-
"readOnly": {
14-
"description": "If <code>true</code>, the component is read-only. When read-only, the value cannot be changed but the user can interact with the interface."
15-
},
1610
"sx": {
1711
"description": "The system prop that allows defining system overrides as well as additional CSS styles."
1812
},

docs/translations/api-docs/date-pickers/pickers-layout/pickers-layout.json

-6
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,10 @@
22
"componentDescription": "",
33
"propDescriptions": {
44
"classes": { "description": "Override or extend the styles applied to the component." },
5-
"disabled": {
6-
"description": "If <code>true</code>, the component is disabled. When disabled, the value cannot be changed and no interaction is possible."
7-
},
85
"isRtl": {
96
"description": "<code>true</code> if the application is in right-to-left direction."
107
},
118
"orientation": { "description": "Force rendering in particular orientation." },
12-
"readOnly": {
13-
"description": "If <code>true</code>, the component is read-only. When read-only, the value cannot be changed but the user can interact with the interface."
14-
},
159
"slotProps": { "description": "The props used for each component slot." },
1610
"slots": { "description": "Overridable component slots." },
1711
"sx": {

docs/translations/api-docs/date-pickers/time-picker-toolbar/time-picker-toolbar.json

-6
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,11 @@
22
"componentDescription": "",
33
"propDescriptions": {
44
"classes": { "description": "Override or extend the styles applied to the component." },
5-
"disabled": {
6-
"description": "If <code>true</code>, the component is disabled. When disabled, the value cannot be changed and no interaction is possible."
7-
},
85
"hidden": { "description": "If <code>true</code>, show the toolbar even in desktop mode." },
96
"onViewChange": {
107
"description": "Callback called when a toolbar is clicked",
118
"typeDescriptions": { "view": "The view to open" }
129
},
13-
"readOnly": {
14-
"description": "If <code>true</code>, the component is read-only. When read-only, the value cannot be changed but the user can interact with the interface."
15-
},
1610
"sx": {
1711
"description": "The system prop that allows defining system overrides as well as additional CSS styles."
1812
},

packages/x-date-pickers-pro/src/DateRangePicker/DateRangePickerToolbar.tsx

-12
Original file line numberDiff line numberDiff line change
@@ -142,12 +142,6 @@ DateRangePickerToolbar.propTypes = {
142142
*/
143143
classes: PropTypes.object,
144144
className: PropTypes.string,
145-
/**
146-
* If `true`, the component is disabled.
147-
* When disabled, the value cannot be changed and no interaction is possible.
148-
* @default false
149-
*/
150-
disabled: PropTypes.bool,
151145
/**
152146
* If `true`, show the toolbar even in desktop mode.
153147
* @default `true` for Desktop, `false` for Mobile.
@@ -161,12 +155,6 @@ DateRangePickerToolbar.propTypes = {
161155
*/
162156
onViewChange: PropTypes.func.isRequired,
163157
rangePosition: PropTypes.oneOf(['end', 'start']).isRequired,
164-
/**
165-
* If `true`, the component is read-only.
166-
* When read-only, the value cannot be changed but the user can interact with the interface.
167-
* @default false
168-
*/
169-
readOnly: PropTypes.bool,
170158
/**
171159
* The system prop that allows defining system overrides as well as additional CSS styles.
172160
*/

packages/x-date-pickers-pro/src/DateTimeRangePicker/DateTimeRangePickerToolbar.tsx

+3-15
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import {
1212
PickerVariant,
1313
PickerRangeValue,
1414
} from '@mui/x-date-pickers/internals';
15-
import { usePickerTranslations } from '@mui/x-date-pickers/hooks';
15+
import { usePickerContext, usePickerTranslations } from '@mui/x-date-pickers/hooks';
1616
import { PickerValidDate } from '@mui/x-date-pickers/models';
1717
import {
1818
DateTimePickerToolbarProps,
@@ -135,8 +135,6 @@ const DateTimeRangePickerToolbar = React.forwardRef(function DateTimeRangePicker
135135
isLandscape,
136136
views,
137137
ampm,
138-
disabled,
139-
readOnly,
140138
hidden,
141139
toolbarFormat,
142140
toolbarPlaceholder,
@@ -145,6 +143,8 @@ const DateTimeRangePickerToolbar = React.forwardRef(function DateTimeRangePicker
145143
...other
146144
} = props;
147145

146+
const { disabled, readOnly } = usePickerContext();
147+
148148
const commonToolbarProps = {
149149
isLandscape,
150150
views,
@@ -253,12 +253,6 @@ DateTimeRangePickerToolbar.propTypes = {
253253
*/
254254
classes: PropTypes.object,
255255
className: PropTypes.string,
256-
/**
257-
* If `true`, the component is disabled.
258-
* When disabled, the value cannot be changed and no interaction is possible.
259-
* @default false
260-
*/
261-
disabled: PropTypes.bool,
262256
/**
263257
* If `true`, show the toolbar even in desktop mode.
264258
* @default `true` for Desktop, `false` for Mobile.
@@ -274,12 +268,6 @@ DateTimeRangePickerToolbar.propTypes = {
274268
*/
275269
onViewChange: PropTypes.func.isRequired,
276270
rangePosition: PropTypes.oneOf(['end', 'start']).isRequired,
277-
/**
278-
* If `true`, the component is read-only.
279-
* When read-only, the value cannot be changed but the user can interact with the interface.
280-
* @default false
281-
*/
282-
readOnly: PropTypes.bool,
283271
/**
284272
* The system prop that allows defining system overrides as well as additional CSS styles.
285273
*/

packages/x-date-pickers/src/DatePicker/DatePickerToolbar.tsx

-12
Original file line numberDiff line numberDiff line change
@@ -136,12 +136,6 @@ DatePickerToolbar.propTypes = {
136136
*/
137137
classes: PropTypes.object,
138138
className: PropTypes.string,
139-
/**
140-
* If `true`, the component is disabled.
141-
* When disabled, the value cannot be changed and no interaction is possible.
142-
* @default false
143-
*/
144-
disabled: PropTypes.bool,
145139
/**
146140
* If `true`, show the toolbar even in desktop mode.
147141
* @default `true` for Desktop, `false` for Mobile.
@@ -155,12 +149,6 @@ DatePickerToolbar.propTypes = {
155149
* @param {TView} view The view to open
156150
*/
157151
onViewChange: PropTypes.func.isRequired,
158-
/**
159-
* If `true`, the component is read-only.
160-
* When read-only, the value cannot be changed but the user can interact with the interface.
161-
* @default false
162-
*/
163-
readOnly: PropTypes.bool,
164152
/**
165153
* The system prop that allows defining system overrides as well as additional CSS styles.
166154
*/

packages/x-date-pickers/src/DateTimePicker/DateTimePickerToolbar.tsx

+2-14
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import { formatMeridiem } from '../internals/utils/date-utils';
2424
import { pickersToolbarTextClasses } from '../internals/components/pickersToolbarTextClasses';
2525
import { pickersToolbarClasses } from '../internals/components/pickersToolbarClasses';
2626
import { PickerValidDate } from '../models';
27+
import { usePickerContext } from '../hooks/usePickerContext';
2728

2829
export interface ExportedDateTimePickerToolbarProps extends ExportedBaseToolbarProps {
2930
/**
@@ -243,15 +244,14 @@ function DateTimePickerToolbar(inProps: DateTimePickerToolbarProps) {
243244
toolbarFormat,
244245
toolbarPlaceholder = '––',
245246
views,
246-
disabled,
247-
readOnly,
248247
toolbarVariant = 'mobile',
249248
toolbarTitle: inToolbarTitle,
250249
className,
251250
...other
252251
} = props;
253252

254253
const isRtl = useRtl();
254+
const { disabled, readOnly } = usePickerContext();
255255
const ownerState: DateTimePickerToolbarOwnerState = { ...props, isRtl };
256256
const utils = useUtils();
257257
const { meridiemMode, handleMeridiemChange } = useMeridiemMode(value, ampm, onChange);
@@ -412,12 +412,6 @@ DateTimePickerToolbar.propTypes = {
412412
*/
413413
classes: PropTypes.object,
414414
className: PropTypes.string,
415-
/**
416-
* If `true`, the component is disabled.
417-
* When disabled, the value cannot be changed and no interaction is possible.
418-
* @default false
419-
*/
420-
disabled: PropTypes.bool,
421415
/**
422416
* If `true`, show the toolbar even in desktop mode.
423417
* @default `true` for Desktop, `false` for Mobile.
@@ -431,12 +425,6 @@ DateTimePickerToolbar.propTypes = {
431425
* @param {TView} view The view to open
432426
*/
433427
onViewChange: PropTypes.func.isRequired,
434-
/**
435-
* If `true`, the component is read-only.
436-
* When read-only, the value cannot be changed but the user can interact with the interface.
437-
* @default false
438-
*/
439-
readOnly: PropTypes.bool,
440428
/**
441429
* The system prop that allows defining system overrides as well as additional CSS styles.
442430
*/

packages/x-date-pickers/src/DesktopDateTimePicker/DesktopDateTimePickerLayout.tsx

-12
Original file line numberDiff line numberDiff line change
@@ -68,12 +68,6 @@ DesktopDateTimePickerLayout.propTypes = {
6868
*/
6969
classes: PropTypes.object,
7070
className: PropTypes.string,
71-
/**
72-
* If `true`, the component is disabled.
73-
* When disabled, the value cannot be changed and no interaction is possible.
74-
* @default false
75-
*/
76-
disabled: PropTypes.bool,
7771
isLandscape: PropTypes.bool.isRequired,
7872
/**
7973
* `true` if the application is in right-to-left direction.
@@ -94,12 +88,6 @@ DesktopDateTimePickerLayout.propTypes = {
9488
* Force rendering in particular orientation.
9589
*/
9690
orientation: PropTypes.oneOf(['landscape', 'portrait']),
97-
/**
98-
* If `true`, the component is read-only.
99-
* When read-only, the value cannot be changed but the user can interact with the interface.
100-
* @default false
101-
*/
102-
readOnly: PropTypes.bool,
10391
/**
10492
* The props used for each component slot.
10593
* @default {}

0 commit comments

Comments
 (0)