-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
[fields] Allow to override the separator between the start and the end date in all range fields #12174
[fields] Allow to override the separator between the start and the end date in all range fields #12174
Changes from all commits
ef5143d
97b8829
fa6ffdc
02f4030
a2ac7ab
15362c5
28b961f
e21466e
f29d30e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
<DateRangePicker slotProps={{ fieldSeparator: { children: 'to' } }} /> | ||
<DateRangePicker slotProps={{ fieldSeparator: { variant: 'body2' } }} /> | ||
<DateRangePicker slotProps={{ fieldSeparator: { sx: { opacity: 0.5 } } }} /> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import * as React from 'react'; | ||
import { DemoContainer } from '@mui/x-date-pickers/internals/demo'; | ||
import { AdapterDayjs } from '@mui/x-date-pickers/AdapterDayjs'; | ||
import { LocalizationProvider } from '@mui/x-date-pickers/LocalizationProvider'; | ||
import { DateRangePicker } from '@mui/x-date-pickers-pro/DateRangePicker'; | ||
import { SingleInputDateRangeField } from '@mui/x-date-pickers-pro/SingleInputDateRangeField'; | ||
|
||
export default function RangeFieldDateSeparator() { | ||
return ( | ||
<LocalizationProvider dateAdapter={AdapterDayjs}> | ||
<DemoContainer components={['DateRangePicker', 'DateRangePicker']}> | ||
<DateRangePicker slotProps={{ field: { dateSeparator: 'to' } }} /> | ||
<DateRangePicker | ||
slotProps={{ field: { dateSeparator: 'to' } }} | ||
slots={{ field: SingleInputDateRangeField }} | ||
/> | ||
</DemoContainer> | ||
</LocalizationProvider> | ||
); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import * as React from 'react'; | ||
import { DemoContainer } from '@mui/x-date-pickers/internals/demo'; | ||
import { AdapterDayjs } from '@mui/x-date-pickers/AdapterDayjs'; | ||
import { LocalizationProvider } from '@mui/x-date-pickers/LocalizationProvider'; | ||
import { DateRangePicker } from '@mui/x-date-pickers-pro/DateRangePicker'; | ||
import { SingleInputDateRangeField } from '@mui/x-date-pickers-pro/SingleInputDateRangeField'; | ||
|
||
export default function RangeFieldDateSeparator() { | ||
return ( | ||
<LocalizationProvider dateAdapter={AdapterDayjs}> | ||
<DemoContainer components={['DateRangePicker', 'DateRangePicker']}> | ||
<DateRangePicker slotProps={{ field: { dateSeparator: 'to' } }} /> | ||
<DateRangePicker | ||
slotProps={{ field: { dateSeparator: 'to' } }} | ||
slots={{ field: SingleInputDateRangeField }} | ||
/> | ||
</DemoContainer> | ||
</LocalizationProvider> | ||
); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<DateRangePicker slotProps={{ field: { dateSeparator: 'to' } }} /> | ||
<DateRangePicker | ||
slotProps={{ field: { dateSeparator: 'to' } }} | ||
slots={{ field: SingleInputDateRangeField }} | ||
/> |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,7 @@ import PropTypes from 'prop-types'; | |
import clsx from 'clsx'; | ||
import Stack, { StackProps } from '@mui/material/Stack'; | ||
import MuiTextField from '@mui/material/TextField'; | ||
import Typography, { TypographyProps } from '@mui/material/Typography'; | ||
import Typography from '@mui/material/Typography'; | ||
import { styled, useThemeProps } from '@mui/material/styles'; | ||
import { useSlotProps } from '@mui/base/utils'; | ||
import { | ||
|
@@ -54,14 +54,11 @@ const MultiInputDateRangeFieldRoot = styled( | |
}, | ||
)({}); | ||
|
||
const MultiInputDateRangeFieldSeparator = styled( | ||
(props: TypographyProps) => <Typography {...props}>{props.children ?? ' – '}</Typography>, | ||
{ | ||
name: 'MuiMultiInputDateRangeField', | ||
slot: 'Separator', | ||
overridesResolver: (props, styles) => styles.separator, | ||
}, | ||
)({ | ||
const MultiInputDateRangeFieldSeparator = styled(Typography, { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. One less component in the tree 👌 |
||
name: 'MuiMultiInputDateRangeField', | ||
slot: 'Separator', | ||
overridesResolver: (props, styles) => styles.separator, | ||
})({ | ||
lineHeight: '1.4375em', // 23px | ||
}); | ||
|
||
|
@@ -156,6 +153,9 @@ const MultiInputDateRangeField = React.forwardRef(function MultiInputDateRangeFi | |
const separatorProps = useSlotProps({ | ||
elementType: Separator, | ||
externalSlotProps: slotProps?.separator, | ||
additionalProps: { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I also applied the new prop to the multi input range fields because IMHO it makes the DX more consistent (even though people could use |
||
children: ` ${internalProps.dateSeparator ?? '–'} `, | ||
}, | ||
ownerState, | ||
className: classes.separator, | ||
}); | ||
|
@@ -199,6 +199,11 @@ MultiInputDateRangeField.propTypes = { | |
classes: PropTypes.object, | ||
className: PropTypes.string, | ||
component: PropTypes.elementType, | ||
/** | ||
* String displayed between the start and the end dates. | ||
* @default "–" | ||
*/ | ||
dateSeparator: PropTypes.string, | ||
/** | ||
* The default value. Use when the component is not controlled. | ||
*/ | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I moved this one below the introduction of the single input range fields since it uses them