Skip to content

[Autocomplete] Prevent renderValue from being skipped when value is 0 #46145

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

Merged
merged 9 commits into from
May 14, 2025
2 changes: 1 addition & 1 deletion packages/mui-material/src/Autocomplete/Autocomplete.js
Original file line number Diff line number Diff line change
Expand Up @@ -590,7 +590,7 @@ const Autocomplete = React.forwardRef(function Autocomplete(inProps, ref) {

if (renderTags && multiple && value.length > 0) {
startAdornment = renderTags(value, getCustomizedItemProps, ownerState);
} else if (renderValue && value) {
} else if (renderValue && value != null) {
startAdornment = renderValue(value, getCustomizedItemProps, ownerState);
} else if (multiple && value.length > 0) {
startAdornment = value.map((option, index) => {
Expand Down
16 changes: 16 additions & 0 deletions packages/mui-material/src/Autocomplete/Autocomplete.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3597,5 +3597,21 @@ describe('<Autocomplete />', () => {

expect(textbox).toHaveFocus();
});

it('should allow zero number (0) as a value to render', () => {
const { container } = render(
<Autocomplete
defaultValue={0}
options={[0, 1, 2]}
getOptionLabel={(option) => option.toString()}
renderInput={(params) => <TextField {...params} autoFocus />}
renderValue={(value, getItemProps) => {
return <Chip label={value} {...getItemProps()} />;
}}
/>,
);

expect(container.querySelector(`.${chipClasses.root}`)).to.have.text('0');
});
});
});
Loading