Skip to content
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

[pickers] Move the opening logic to the range fields #16175

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions docs/data/date-pickers/calendar-systems/AdapterHijri.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ const cacheRtl = createCache({

function ButtonDateTimeField(props) {
const { internalProps, forwardedProps } = useSplitFieldProps(props, 'date');
const { focused, ...other } = forwardedProps;

const pickerContext = usePickerContext();
const parsedFormat = useParsedFormat();
Expand All @@ -42,7 +41,7 @@ function ButtonDateTimeField(props) {

return (
<Button
{...other}
{...forwardedProps}
variant="outlined"
color={hasValidationError ? 'error' : 'primary'}
className={pickerContext.rootClassName}
Expand Down
3 changes: 1 addition & 2 deletions docs/data/date-pickers/calendar-systems/AdapterHijri.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ const cacheRtl = createCache({

function ButtonDateTimeField(props: DateTimePickerFieldProps) {
const { internalProps, forwardedProps } = useSplitFieldProps(props, 'date');
const { focused, ...other } = forwardedProps;

const pickerContext = usePickerContext();
const parsedFormat = useParsedFormat();
Expand All @@ -46,7 +45,7 @@ function ButtonDateTimeField(props: DateTimePickerFieldProps) {

return (
<Button
{...other}
{...forwardedProps}
variant="outlined"
color={hasValidationError ? 'error' : 'primary'}
className={pickerContext.rootClassName}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { styled } from '@mui/material/styles';
import Stack from '@mui/material/Stack';
import { LocalizationProvider } from '@mui/x-date-pickers/LocalizationProvider';
import { AdapterDayjs } from '@mui/x-date-pickers/AdapterDayjs';
import { usePickerContext, useSplitFieldProps } from '@mui/x-date-pickers/hooks';
import { useSplitFieldProps } from '@mui/x-date-pickers/hooks';
import { DateRangePicker } from '@mui/x-date-pickers-pro/DateRangePicker';
import { useDateRangeManager } from '@mui/x-date-pickers-pro/managers';
import { unstable_useMultiInputRangeField as useMultiInputRangeField } from '@mui/x-date-pickers-pro/hooks';
Expand Down Expand Up @@ -75,7 +75,6 @@ function BrowserTextField(props) {
}

function BrowserMultiInputDateRangeField(props) {
const pickerContext = usePickerContext();
const manager = useDateRangeManager();
const { internalProps, forwardedProps } = useSplitFieldProps(props, 'date');
const { slotProps, ...otherForwardedProps } = forwardedProps;
Expand All @@ -95,21 +94,21 @@ function BrowserMultiInputDateRangeField(props) {
const fieldResponse = useMultiInputRangeField({
manager,
internalProps,
startForwardedProps: startTextFieldProps,
endForwardedProps: endTextFieldProps,
startTextFieldProps,
endTextFieldProps,
rootProps: {
spacing: 2,
direction: 'row',
overflow: 'auto',
...otherForwardedProps,
},
});

return (
<Stack
ref={pickerContext.rootRef}
spacing={2}
direction="row"
overflow="auto"
{...otherForwardedProps}
>
<BrowserTextField {...fieldResponse.startDate} />
<Stack {...fieldResponse.root}>
<BrowserTextField {...fieldResponse.startTextField} />
<span>–</span>
<BrowserTextField {...fieldResponse.endDate} />
<BrowserTextField {...fieldResponse.endTextField} />
</Stack>
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { styled } from '@mui/material/styles';
import Stack from '@mui/material/Stack';
import { LocalizationProvider } from '@mui/x-date-pickers/LocalizationProvider';
import { AdapterDayjs } from '@mui/x-date-pickers/AdapterDayjs';
import { usePickerContext, useSplitFieldProps } from '@mui/x-date-pickers/hooks';
import { useSplitFieldProps } from '@mui/x-date-pickers/hooks';
import {
DateRangePicker,
DateRangePickerFieldProps,
Expand Down Expand Up @@ -109,7 +109,6 @@ interface BrowserMultiInputDateRangeFieldProps
function BrowserMultiInputDateRangeField(
props: BrowserMultiInputDateRangeFieldProps,
) {
const pickerContext = usePickerContext();
const manager = useDateRangeManager();
const { internalProps, forwardedProps } = useSplitFieldProps(props, 'date');
const { slotProps, ...otherForwardedProps } = forwardedProps;
Expand All @@ -129,21 +128,23 @@ function BrowserMultiInputDateRangeField(
const fieldResponse = useMultiInputRangeField({
manager,
internalProps,
startForwardedProps: startTextFieldProps,
endForwardedProps: endTextFieldProps,
startTextFieldProps,
endTextFieldProps,
rootProps: {
spacing: 2,
direction: 'row' as const,
overflow: 'auto',
...otherForwardedProps,
},
});

return (
<Stack
ref={pickerContext.rootRef}
spacing={2}
direction="row"
overflow="auto"
{...otherForwardedProps}
>
<BrowserTextField {...(fieldResponse.startDate as BrowserTextFieldProps)} />
<Stack {...fieldResponse.root}>
<BrowserTextField
{...(fieldResponse.startTextField as BrowserTextFieldProps)}
/>
<span></span>
<BrowserTextField {...(fieldResponse.endDate as BrowserTextFieldProps)} />
<BrowserTextField {...(fieldResponse.endTextField as BrowserTextFieldProps)} />
</Stack>
);
}
Expand Down
1 change: 0 additions & 1 deletion docs/data/date-pickers/custom-field/JoyV6Field.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ function JoyDateField(props) {
// Can be used to style the component
disabled,
readOnly,
focused,
error,
inputRef,
// The rest can be passed to the root element
Expand Down
1 change: 0 additions & 1 deletion docs/data/date-pickers/custom-field/JoyV6Field.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ function JoyDateField(props: DatePickerFieldProps) {
// Can be used to style the component
disabled,
readOnly,
focused,
error,
inputRef,

Expand Down
27 changes: 15 additions & 12 deletions docs/data/date-pickers/custom-field/JoyV6MultiInputRangeField.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,36 +79,39 @@ function JoyMultiInputDateRangeField(props) {
const startTextFieldProps = useSlotProps({
elementType: 'input',
externalSlotProps: slotProps?.textField,
additionalProps: { label: 'Start' },
ownerState: { position: 'start' },
});

const endTextFieldProps = useSlotProps({
elementType: 'input',
externalSlotProps: slotProps?.textField,
additionalProps: { label: 'End' },
ownerState: { position: 'end' },
});

const fieldResponse = useMultiInputRangeField({
manager,
internalProps: { ...internalProps, enableAccessibleFieldDOMStructure: false },
startForwardedProps: startTextFieldProps,
endForwardedProps: endTextFieldProps,
rootProps: {
ref: pickerContext.rootRef,
spacing: 2,
overflow: 'auto',
direction: 'row',
alignItems: 'center',
...otherForwardedProps,
},
startTextFieldProps,
endTextFieldProps,
});

return (
<Stack
spacing={2}
overflow="auto"
direction="row"
alignItems="center"
{...otherForwardedProps}
ref={pickerContext.rootRef}
>
<JoyField {...fieldResponse.startDate} />
<Stack {...fieldResponse.root}>
<JoyField {...fieldResponse.startTextField} />
<FormControl>
<Typography sx={{ marginTop: '25px' }}>{' – '}</Typography>
</FormControl>
<JoyField {...fieldResponse.endDate} />
<JoyField {...fieldResponse.endTextField} />
</Stack>
);
}
Expand Down
27 changes: 15 additions & 12 deletions docs/data/date-pickers/custom-field/JoyV6MultiInputRangeField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -110,36 +110,39 @@ function JoyMultiInputDateRangeField(props: JoyMultiInputDateRangeFieldProps) {
const startTextFieldProps = useSlotProps({
elementType: 'input',
externalSlotProps: slotProps?.textField,
additionalProps: { label: 'Start' },
ownerState: { position: 'start' } as any,
}) as MultiInputFieldSlotTextFieldProps;

const endTextFieldProps = useSlotProps({
elementType: 'input',
externalSlotProps: slotProps?.textField,
additionalProps: { label: 'End' },
ownerState: { position: 'end' } as any,
}) as MultiInputFieldSlotTextFieldProps;

const fieldResponse = useMultiInputRangeField({
manager,
internalProps: { ...internalProps, enableAccessibleFieldDOMStructure: false },
startForwardedProps: startTextFieldProps,
endForwardedProps: endTextFieldProps,
rootProps: {
ref: pickerContext.rootRef,
spacing: 2,
overflow: 'auto',
direction: 'row' as const,
alignItems: 'center',
...otherForwardedProps,
},
startTextFieldProps,
endTextFieldProps,
});

return (
<Stack
spacing={2}
overflow="auto"
direction="row"
alignItems="center"
{...otherForwardedProps}
ref={pickerContext.rootRef}
>
<JoyField {...fieldResponse.startDate} />
<Stack {...fieldResponse.root}>
<JoyField {...fieldResponse.startTextField} />
<FormControl>
<Typography sx={{ marginTop: '25px' }}>{' – '}</Typography>
</FormControl>
<JoyField {...fieldResponse.endDate} />
<JoyField {...fieldResponse.endTextField} />
</Stack>
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { useValidation, validateDate } from '@mui/x-date-pickers/validation';
function AutocompleteField(props) {
const { forwardedProps, internalProps } = useSplitFieldProps(props, 'date');
const { timezone, value, setValue } = usePickerContext();
const { focused, options = [], ...other } = forwardedProps;
const { options = [], ...other } = forwardedProps;
const pickerContext = usePickerContext();

const { hasValidationError, getValidationErrorForNewValue } = useValidation({
Expand Down Expand Up @@ -43,6 +43,7 @@ function AutocompleteField(props) {
<TextField
{...params}
error={hasValidationError}
focused={pickerContext.open}
label={pickerContext.label}
name={pickerContext.name}
InputProps={{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ interface AutocompleteFieldProps extends DatePickerFieldProps {
function AutocompleteField(props: AutocompleteFieldProps) {
const { forwardedProps, internalProps } = useSplitFieldProps(props, 'date');
const { timezone, value, setValue } = usePickerContext();
const { focused, options = [], ...other } = forwardedProps;
const { options = [], ...other } = forwardedProps;
const pickerContext = usePickerContext();

const { hasValidationError, getValidationErrorForNewValue } = useValidation({
Expand Down Expand Up @@ -55,6 +55,7 @@ function AutocompleteField(props: AutocompleteFieldProps) {
<TextField
{...params}
error={hasValidationError}
focused={pickerContext.open}
label={pickerContext.label}
name={pickerContext.name}
InputProps={{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import {

function ButtonDateField(props) {
const { internalProps, forwardedProps } = useSplitFieldProps(props, 'date');
const { focused, ...other } = forwardedProps;

const pickerContext = usePickerContext();
const handleRef = useForkRef(pickerContext.triggerRef, pickerContext.rootRef);
Expand All @@ -32,7 +31,7 @@ function ButtonDateField(props) {

return (
<Button
{...other}
{...forwardedProps}
variant="outlined"
color={hasValidationError ? 'error' : 'primary'}
ref={handleRef}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import {

function ButtonDateField(props: DatePickerFieldProps) {
const { internalProps, forwardedProps } = useSplitFieldProps(props, 'date');
const { focused, ...other } = forwardedProps;

const pickerContext = usePickerContext();
const handleRef = useForkRef(pickerContext.triggerRef, pickerContext.rootRef);
Expand All @@ -36,7 +35,7 @@ function ButtonDateField(props: DatePickerFieldProps) {

return (
<Button
{...other}
{...forwardedProps}
variant="outlined"
color={hasValidationError ? 'error' : 'primary'}
ref={handleRef}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import {

function ButtonDateRangeField(props) {
const { internalProps, forwardedProps } = useSplitFieldProps(props, 'date');
const { focused, ...other } = forwardedProps;

const pickerContext = usePickerContext();
const handleRef = useForkRef(pickerContext.triggerRef, pickerContext.rootRef);
Expand All @@ -35,7 +34,7 @@ function ButtonDateRangeField(props) {

return (
<Button
{...other}
{...forwardedProps}
variant="outlined"
color={hasValidationError ? 'error' : 'primary'}
ref={handleRef}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import {

function ButtonDateRangeField(props: DateRangePickerFieldProps) {
const { internalProps, forwardedProps } = useSplitFieldProps(props, 'date');
const { focused, ...other } = forwardedProps;

const pickerContext = usePickerContext();
const handleRef = useForkRef(pickerContext.triggerRef, pickerContext.rootRef);
Expand All @@ -39,7 +38,7 @@ function ButtonDateRangeField(props: DateRangePickerFieldProps) {

return (
<Button
{...other}
{...forwardedProps}
variant="outlined"
color={hasValidationError ? 'error' : 'primary'}
ref={handleRef}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ function MaskedDateField(props) {
<TextField
placeholder={parsedFormat}
error={hasValidationError}
focused={pickerContext.open}
name={pickerContext.name}
label={pickerContext.label}
className={pickerContext.rootClassName}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ function MaskedDateField(props: DatePickerFieldProps) {
<TextField
placeholder={parsedFormat}
error={hasValidationError}
focused={pickerContext.open}
name={pickerContext.name}
label={pickerContext.label}
className={pickerContext.rootClassName}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ function ReadOnlyDateField(props) {
sx: { cursor: 'pointer', '& *': { cursor: 'inherit' } },
}}
error={hasValidationError}
focused={pickerContext.open}
onClick={() => pickerContext.setOpen((prev) => !prev)}
name={pickerContext.name}
label={pickerContext.label}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ function ReadOnlyDateField(props: DatePickerFieldProps) {
sx: { cursor: 'pointer', '& *': { cursor: 'inherit' } },
}}
error={hasValidationError}
focused={pickerContext.open}
onClick={() => pickerContext.setOpen((prev) => !prev)}
name={pickerContext.name}
label={pickerContext.label}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ function ReadOnlyDateField(props) {
sx: { cursor: 'pointer', '& *': { cursor: 'inherit' } },
}}
error={hasValidationError}
focused={pickerContext.open}
onClick={() => pickerContext.setOpen((prev) => !prev)}
className={pickerContext.rootClassName}
sx={pickerContext.rootSx}
Expand Down
Loading