-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[docs] Add example for avoiding picker views layout shift (#9781)
Signed-off-by: noraleonte <[email protected]> Co-authored-by: Olivier Tassinari <[email protected]> Co-authored-by: Lukas <[email protected]>
- Loading branch information
1 parent
8f6730c
commit d1ac291
Showing
3 changed files
with
104 additions
and
0 deletions.
There are no files selected for viewing
46 changes: 46 additions & 0 deletions
46
docs/data/date-pickers/custom-components/PopperComponent.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import * as React from 'react'; | ||
import dayjs from 'dayjs'; | ||
import { LocalizationProvider } from '@mui/x-date-pickers/LocalizationProvider'; | ||
import { AdapterDayjs } from '@mui/x-date-pickers/AdapterDayjs'; | ||
import { DatePicker } from '@mui/x-date-pickers/DatePicker'; | ||
|
||
export default function PopperComponent() { | ||
return ( | ||
<LocalizationProvider dateAdapter={AdapterDayjs}> | ||
<DatePicker | ||
label="Basic date picker" | ||
views={['month', 'year']} | ||
minDate={dayjs(new Date(2022, 0, 1))} | ||
maxDate={dayjs(new Date(2024, 12, 31))} | ||
reduceAnimations | ||
slotProps={{ | ||
popper: { | ||
modifiers: [ | ||
{ | ||
name: 'viewHeightModifier', | ||
enabled: true, | ||
phase: 'beforeWrite', | ||
fn: ({ state }) => { | ||
state.styles.popper.height = '320px'; | ||
if (state.placement.includes('top-start')) { | ||
state.styles.popper = { | ||
...state.styles.popper, | ||
display: 'flex', | ||
alignItems: 'flex-end', | ||
}; | ||
} | ||
if (state.placement.includes('bottom')) { | ||
state.styles.popper = { | ||
...state.styles.popper, | ||
display: 'block', | ||
}; | ||
} | ||
}, | ||
}, | ||
], | ||
}, | ||
}} | ||
/> | ||
</LocalizationProvider> | ||
); | ||
} |
46 changes: 46 additions & 0 deletions
46
docs/data/date-pickers/custom-components/PopperComponent.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import * as React from 'react'; | ||
import dayjs from 'dayjs'; | ||
import { LocalizationProvider } from '@mui/x-date-pickers/LocalizationProvider'; | ||
import { AdapterDayjs } from '@mui/x-date-pickers/AdapterDayjs'; | ||
import { DatePicker } from '@mui/x-date-pickers/DatePicker'; | ||
|
||
export default function PopperComponent() { | ||
return ( | ||
<LocalizationProvider dateAdapter={AdapterDayjs}> | ||
<DatePicker | ||
label="Basic date picker" | ||
views={['month', 'year']} | ||
minDate={dayjs(new Date(2022, 0, 1))} | ||
maxDate={dayjs(new Date(2024, 12, 31))} | ||
reduceAnimations | ||
slotProps={{ | ||
popper: { | ||
modifiers: [ | ||
{ | ||
name: 'viewHeightModifier', | ||
enabled: true, | ||
phase: 'beforeWrite', | ||
fn: ({ state }: { state: Partial<any> }) => { | ||
state.styles.popper.height = '320px'; | ||
if (state.placement.includes('top-start')) { | ||
state.styles.popper = { | ||
...state.styles.popper, | ||
display: 'flex', | ||
alignItems: 'flex-end', | ||
}; | ||
} | ||
if (state.placement.includes('bottom')) { | ||
state.styles.popper = { | ||
...state.styles.popper, | ||
display: 'block', | ||
}; | ||
} | ||
}, | ||
}, | ||
], | ||
}, | ||
}} | ||
/> | ||
</LocalizationProvider> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters