Skip to content

Commit

Permalink
Bring back inputRef on accessible DOM structure
Browse files Browse the repository at this point in the history
  • Loading branch information
flaviendelangle committed Nov 14, 2024
1 parent 94e2bef commit 9b5af2f
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ export const useDesktopRangePicker = <
className,
sx,
ref: fieldContainerRef,
...(fieldType === 'single-input' && !enableAccessibleFieldDOMStructure && { inputRef }),
...(fieldType === 'single-input' && !!inputRef && { inputRef }),
...(fieldType === 'single-input' && { name }),
},
ownerState,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ export const useMobileRangePicker = <
// Forwarded props
className,
sx,
...(fieldType === 'single-input' && !enableAccessibleFieldDOMStructure && { inputRef }),
...(fieldType === 'single-input' && !!inputRef && { inputRef }),
...(fieldType === 'single-input' && { name }),
},
ownerState,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ export const useDesktopPicker = <
name,
focused: open ? true : undefined,
...(isToolbarHidden && { id: labelId }),
...(!enableAccessibleFieldDOMStructure && { inputRef }),
...(!!inputRef && { inputRef }),
},
ownerState,
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ export const useMobilePicker = <
onClick: actions.onOpen,
onKeyDown: onSpaceOrEnter(actions.onOpen),
}),
...(!enableAccessibleFieldDOMStructure && { inputRef }),
...(!!inputRef && { inputRef }),
},
ownerState,
});
Expand Down
17 changes: 3 additions & 14 deletions packages/x-date-pickers/src/internals/models/fields.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import type {
import type { FieldSection, PickerOwnerState } from '../../models';
import type { UseFieldInternalProps } from '../hooks/useField';

interface BaseForwardedCommonSingleInputFieldProps extends ExportedUseClearableFieldProps {
interface BaseForwardedSingleInputFieldProps extends ExportedUseClearableFieldProps {
className: string | undefined;
sx: SxProps<any> | undefined;
label: React.ReactNode | undefined;
Expand All @@ -18,6 +18,7 @@ interface BaseForwardedCommonSingleInputFieldProps extends ExportedUseClearableF
onKeyDown?: React.KeyboardEventHandler;
onBlur?: React.FocusEventHandler;
ref?: React.Ref<HTMLDivElement>;
inputRef?: React.Ref<HTMLInputElement>;
InputProps?: {
ref?: React.Ref<any>;
endAdornment?: React.ReactNode;
Expand All @@ -33,18 +34,6 @@ interface BaseForwardedCommonSingleInputFieldProps extends ExportedUseClearableF
ownerState: PickerOwnerState;
}

interface BaseForwardedV6SingleInputFieldProps {
inputRef?: React.Ref<HTMLInputElement>;
}

interface BaseForwardedV7SingleInputFieldProps {}

export type BaseForwardedSingleInputFieldProps<TEnableAccessibleFieldDOMStructure extends boolean> =
BaseForwardedCommonSingleInputFieldProps &
(TEnableAccessibleFieldDOMStructure extends false
? BaseForwardedV6SingleInputFieldProps
: BaseForwardedV7SingleInputFieldProps);

/**
* Props the single input field can receive when used inside a picker.
* Only contains what the MUI components are passing to the field, not what users can pass using the `props.slotProps.field`.
Expand Down Expand Up @@ -72,4 +61,4 @@ export type BaseSingleInputFieldProps<
>,
'format' | 'value' | 'onChange' | 'timezone'
> &
BaseForwardedSingleInputFieldProps<TEnableAccessibleFieldDOMStructure>;
BaseForwardedSingleInputFieldProps;

0 comments on commit 9b5af2f

Please sign in to comment.