Skip to content

Allow overriding renderInput in AutocompleteInput - #11385

Open
bipul724 wants to merge 2 commits into
marmelab:nextfrom
bipul724:fix/10430-autocomplete-render-input
Open

bipul724 wants to merge 2 commits into
marmelab:nextfrom
bipul724:fix/10430-autocomplete-render-input

Conversation

@bipul724

Copy link
Copy Markdown
Contributor

Problem

Closes #10430. <AutocompleteInput> already forwards renderInput to MUI's Autocomplete at runtime, but AutocompleteInputProps omits it, so TypeScript users can't override the input rendering (e.g. to show a custom component for the selected option when grouping). Also, because the custom renderInput bypassed react-admin's default rendering, the form field ref was never attached, so react-hook-form couldn't focus the input (e.g. on validation errors).

Solution

Expose renderInput as an optional prop. Regarding the feedback on #11132: simply removing renderInput from the Omit list would make it a required prop, since it's required in MUI's AutocompleteProps, breaking every existing usage. So it's re-declared as optional, reusing MUI's type.

The custom renderInput is now called explicitly, with the form field ref merged into params.inputProps.ref, so focus management keeps working.

How To Test

  • Storybook: ra-ui-materialui/input/AutocompleteInput → Render Input
  • yarn test-unit packages/ra-ui-materialui/src/input/AutocompleteInput.spec.tsx

Additional Checks

  • The PR targets next for a feature
  • The PR includes unit tests
  • The PR includes one or several stories
  • The documentation is up to date

Copilot AI lite review requested due to automatic review settings September 26, 2026 22:08

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot review overview

🟢 Approval recommended

The implementation is backward-compatible, documented, and adequately tested.

Review effort: Balanced
Findings: None

);
};
render(
<AdminContext dataProvider={testDataProvider()}>

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

plezase reuse stories instead of writing the system under test here

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done. The test now renders a new RenderInputFieldRef story.

/>
</Wrapper>
);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

since the original issue was about showing option groups, I think we should demonstrate this is possible with another story

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Added a RenderInputWithGroups story: grouped options with the selected option shown as a custom component (the use case from #10430), plus a test for it.

TextField,
type TextFieldProps,
major as muiMajor,
setRef,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I can't find any documentation on the MUI website about this function. Is it public API?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

it's exported from @mui/material but not documented. I replaced it with a small local assignRef helper.

@bipul724
bipul724 requested review from fzaninotto and a balanced review from Copilot September 29, 2026 13:15

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants