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 TextFieldProps> are not applied #9527

Merged
merged 2 commits into from
Dec 15, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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 @@ -23,6 +23,7 @@ import {
TranslateChoice,
OnChange,
InsideReferenceInputOnChange,
WithInputProps,
} from './AutocompleteInput.stories';
import { act } from '@testing-library/react-hooks';
import { ReferenceArrayInput } from './ReferenceArrayInput';
Expand Down Expand Up @@ -1587,4 +1588,12 @@ describe('<AutocompleteInput />', () => {
fireEvent.change(input, { target: { value: 'newValue' } });
await waitFor(() => expect(onInputChange).toHaveBeenCalled());
});

describe('InputProps', () => {
it('should pass InputProps to the input', async () => {
render(<WithInputProps />);
screen.getByTestId('AttributionIcon');
screen.getByTestId('ExpandCircleDownIcon');
});
});
});
46 changes: 46 additions & 0 deletions packages/ra-ui-materialui/src/input/AutocompleteInput.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import {
TextField,
Typography,
Box,
InputAdornment,
} from '@mui/material';
import { useFormContext } from 'react-hook-form';
import fakeRestProvider from 'ra-data-fakerest';
Expand All @@ -31,6 +32,8 @@ import { AutocompleteInput, AutocompleteInputProps } from './AutocompleteInput';
import { ReferenceInput } from './ReferenceInput';
import { TextInput } from './TextInput';
import { useCreateSuggestionContext } from './useSupportCreateSuggestion';
import ExpandCircleDownIcon from '@mui/icons-material/ExpandCircleDown';
import AttributionIcon from '@mui/icons-material/Attribution';

export default { title: 'ra-ui-materialui/input/AutocompleteInput' };

Expand Down Expand Up @@ -1194,3 +1197,46 @@ export const TranslateChoice = () => {
</AdminContext>
);
};

export const WithInputProps = () => {
const choices = [
{ id: 1, name: 'Leo Tolstoy' },
{ id: 2, name: 'Victor Hugo' },
{ id: 3, name: 'William Shakespeare' },
{ id: 4, name: 'Charles Baudelaire' },
{ id: 5, name: 'Marcel Proust' },
];

return (
<Admin dataProvider={dataProvider} history={history}>
<Resource
name="books"
edit={() => (
<Edit>
<SimpleForm>
<AutocompleteInput
source="author"
fullWidth
choices={choices}
TextFieldProps={{
InputProps: {
startAdornment: (
<InputAdornment position="end">
<AttributionIcon />
</InputAdornment>
),
endAdornment: (
<InputAdornment position="end">
<ExpandCircleDownIcon />
</InputAdornment>
),
},
}}
/>
</SimpleForm>
</Edit>
)}
/>
</Admin>
);
};
2 changes: 1 addition & 1 deletion packages/ra-ui-materialui/src/input/AutocompleteInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -591,8 +591,8 @@ If you provided a React element for the optionText prop, you must also provide t
margin={margin}
variant={variant}
className={AutocompleteInputClasses.textField}
{...TextFieldProps}
{...params}
{...TextFieldProps}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the fix

size={size}
/>
)}
Expand Down
Loading