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

Fix <AutocompleteInput> should keep working when passing custom InputProps #9559

Merged
merged 3 commits into from
Jan 5, 2024
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -1592,9 +1592,11 @@ describe('<AutocompleteInput />', () => {
describe('InputProps', () => {
it('should pass InputProps to the input', async () => {
render(<WithInputProps />);
await screen.findByRole('textbox');
const input = await screen.findByRole('textbox');
screen.getByTestId('AttributionIcon');
screen.getByTestId('ExpandCircleDownIcon');
fireEvent.click(input);
screen.getByText('Victor Hugo');
});
});
});
17 changes: 15 additions & 2 deletions packages/ra-ui-materialui/src/input/AutocompleteInput.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1221,12 +1221,25 @@ export const WithInputProps = () => {
TextFieldProps={{
InputProps: {
startAdornment: (
<InputAdornment position="end">
<InputAdornment
position="start"
sx={{
position: 'relative',
top: '-8px',
}}
>
<AttributionIcon />
</InputAdornment>
),
endAdornment: (
<InputAdornment position="end">
<InputAdornment
position="end"
sx={{
position: 'relative',
top: '-8px',
left: '50px',
}}
>
<ExpandCircleDownIcon />
</InputAdornment>
),
Expand Down
79 changes: 44 additions & 35 deletions packages/ra-ui-materialui/src/input/AutocompleteInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -560,42 +560,51 @@ If you provided a React element for the optionText prop, you must also provide t
id={id}
isOptionEqualToValue={isOptionEqualToValue}
filterSelectedOptions
renderInput={params => (
<TextField
name={field.name}
label={
<FieldTitle
label={label}
source={source}
resource={resourceProp}
isRequired={isRequired}
/>
}
error={
!!fetchError ||
((isTouched || isSubmitted) && invalid)
}
helperText={
renderHelperText ? (
<InputHelperText
touched={
isTouched || isSubmitted || fetchError
}
error={
error?.message || fetchError?.message
}
helperText={helperText}
renderInput={params => {
const mergedTextFieldProps = {
...params.InputProps,
...TextFieldProps?.InputProps,
};
return (
<TextField
name={field.name}
label={
<FieldTitle
label={label}
source={source}
resource={resourceProp}
isRequired={isRequired}
/>
) : null
}
margin={margin}
variant={variant}
className={AutocompleteInputClasses.textField}
{...params}
{...TextFieldProps}
size={size}
/>
)}
}
error={
!!fetchError ||
((isTouched || isSubmitted) && invalid)
}
helperText={
renderHelperText ? (
<InputHelperText
touched={
isTouched ||
isSubmitted ||
fetchError
}
error={
error?.message ||
fetchError?.message
}
helperText={helperText}
/>
) : null
}
margin={margin}
variant={variant}
className={AutocompleteInputClasses.textField}
{...params}
InputProps={mergedTextFieldProps}
size={size}
/>
);
}}
multiple={multiple}
renderTags={(value, getTagProps) =>
value.map((option, index) => (
Expand Down
Loading