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 e040f2e
Show file tree
Hide file tree
Showing 7 changed files with 10 additions and 24 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 @@ -404,8 +404,8 @@ const useSingleInputFieldSlotProps = <
const slotProps = {
...fieldProps.slotProps,
textField: pickerSlotProps?.textField,
clearButton: pickerSlots?.clearButton,
clearIcon: pickerSlots?.clearIcon,
clearButton: pickerSlotProps?.clearButton,
clearIcon: pickerSlotProps?.clearIcon,
};

const enrichedFieldProps: ReturnType = {
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 {
export 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;
5 changes: 1 addition & 4 deletions packages/x-date-pickers/src/models/fields.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,10 +142,7 @@ export type PickerFieldSlotProps<
export type BaseSingleInputPickersTextFieldProps<
TEnableAccessibleFieldDOMStructure extends boolean,
> = UseClearableFieldResponse<
UseFieldResponse<
TEnableAccessibleFieldDOMStructure,
BaseForwardedSingleInputFieldProps<TEnableAccessibleFieldDOMStructure>
>
UseFieldResponse<TEnableAccessibleFieldDOMStructure, BaseForwardedSingleInputFieldProps>
>;

/**
Expand Down

0 comments on commit e040f2e

Please sign in to comment.