@@ -171,118 +171,7 @@ The picker components no longer have a keyboard view to render the input inside
171
171
172
172
- If you want to keep the old keyboard view, you can pass a custom ` Layout ` component slot to re-introduce the keyboard view.
173
173
174
- ``` tsx
175
- import * as React from ' react' ;
176
- import { Dayjs } from ' dayjs' ;
177
- import Box from ' @mui/material/Box' ;
178
- import Stack from ' @mui/material/Stack' ;
179
- import IconButton from ' @mui/material/IconButton' ;
180
- import ModeEditIcon from ' @mui/icons-material/ModeEdit' ;
181
- import CalendarMonthIcon from ' @mui/icons-material/CalendarMonth' ;
182
- import { LocalizationProvider } from ' @mui/x-date-pickers/LocalizationProvider' ;
183
- import { AdapterDayjs } from ' @mui/x-date-pickers/AdapterDayjs' ;
184
- import { DateView } from ' @mui/x-date-pickers/models' ;
185
- import {
186
- pickersLayoutClasses ,
187
- PickersLayoutContentWrapper ,
188
- PickersLayoutRoot ,
189
- PickersLayoutProps ,
190
- usePickerLayout ,
191
- } from ' @mui/x-date-pickers/PickersLayout' ;
192
- import { MobileDatePicker } from ' @mui/x-date-pickers/MobileDatePicker' ;
193
- import { DateField } from ' @mui/x-date-pickers/DateField' ;
194
- import {
195
- DatePickerToolbar ,
196
- DatePickerToolbarProps ,
197
- } from ' @mui/x-date-pickers/DatePicker' ;
198
-
199
- function LayoutWithKeyboardView(props : PickersLayoutProps <Dayjs | null , DateView >) {
200
- const { value, onChange } = props ;
201
- const [showKeyboardView, setShowKeyboardView] = React .useState (false );
202
-
203
- const { toolbar, tabs, content, actionBar } = usePickerLayout ({
204
- ... props ,
205
- slotProps: {
206
- ... props .slotProps ,
207
- toolbar: {
208
- ... props .slotProps ?.toolbar ,
209
- // @ts-ignore
210
- showKeyboardViewSwitch: props .wrapperVariant === ' mobile' ,
211
- showKeyboardView ,
212
- setShowKeyboardView ,
213
- },
214
- },
215
- });
216
-
217
- return (
218
- <PickersLayoutRoot ownerState = { props } >
219
- { toolbar }
220
- { actionBar }
221
- <PickersLayoutContentWrapper className = { pickersLayoutClasses .contentWrapper } >
222
- { tabs }
223
- { showKeyboardView ? (
224
- <Box sx = { { mx: 3 , my: 2 , width: 272 }} >
225
- <DateField value = { value } onChange = { onChange } sx = { { width: ' 100%' }} />
226
- </Box >
227
- ) : (
228
- content
229
- )}
230
- </PickersLayoutContentWrapper >
231
- </PickersLayoutRoot >
232
- );
233
- }
234
-
235
- function ToolbarWithKeyboardViewSwitch(
236
- props : DatePickerToolbarProps & {
237
- showKeyboardViewSwitch? : boolean ;
238
- showKeyboardView? : boolean ;
239
- setShowKeyboardView? : React .Dispatch <React .SetStateAction <boolean >>;
240
- },
241
- ) {
242
- const { showKeyboardViewSwitch, showKeyboardView, setShowKeyboardView, ... other } =
243
- props ;
244
-
245
- if (showKeyboardViewSwitch ) {
246
- return (
247
- <Stack
248
- spacing = { 2 }
249
- direction = { other .isLandscape ? ' column' : ' row' }
250
- alignItems = " center"
251
- sx = {
252
- other .isLandscape
253
- ? {
254
- gridColumn: 1 ,
255
- gridRow: ' 1 / 3' ,
256
- }
257
- : { gridColumn: ' 1 / 4' , gridRow: 1 , mr: 1 }
258
- }
259
- >
260
- <DatePickerToolbar { ... other } sx = { { flex: ' 1 1 100%' }} />
261
- <IconButton
262
- color = " inherit"
263
- onClick = { () => setShowKeyboardView !((prev ) => ! prev )}
264
- >
265
- { showKeyboardView ? <CalendarMonthIcon /> : <ModeEditIcon />}
266
- </IconButton >
267
- </Stack >
268
- );
269
- }
270
-
271
- return <DatePickerToolbar { ... other } />;
272
- }
273
- export default function MobileKeyboardView() {
274
- return (
275
- <LocalizationProvider dateAdapter = { AdapterDayjs } >
276
- <MobileDatePicker
277
- slots = { {
278
- layout: LayoutWithKeyboardView ,
279
- toolbar: ToolbarWithKeyboardViewSwitch ,
280
- }}
281
- />
282
- </LocalizationProvider >
283
- );
284
- }
285
- ```
174
+ {{"demo": "MobileKeyboardView.js", "hideToolbar": true, "bg": true}}
286
175
287
176
::: info
288
177
At some point, the mobile pickers should have a prop allowing to have an editable field without opening the modal.
0 commit comments