Skip to content

[autocomplete] Fix renderInput not passing slotProps#48537

Open
mj12albert wants to merge 2 commits into
mui:v7.xfrom
mj12albert:fix-autocomplete-renderInput-slotProps
Open

[autocomplete] Fix renderInput not passing slotProps#48537
mj12albert wants to merge 2 commits into
mui:v7.xfrom
mj12albert:fix-autocomplete-renderInput-slotProps

Conversation

@mj12albert
Copy link
Copy Markdown
Member

@mj12albert mj12albert commented May 13, 2026

Re: #43869 (comment)

This doesn't work in v7 because params doesn't contain slotProps:

renderInput={(params) => (
  <TextField
    {...params}
    slotProps={{
      ...params.slotProps,
      htmlInput: {
        ...params.slotProps.htmlInput,
        maxLength: 4,
      },
    }}
  />
)}

Worth fixing because slotProps individually work with Autocomplete and TextField, but doesn't work for the most common combination of the two

@mj12albert mj12albert added type: bug It doesn't behave as expected. scope: autocomplete Changes related to the autocomplete. This includes ComboBox. v7.x labels May 13, 2026
@mui-bot
Copy link
Copy Markdown

mui-bot commented May 13, 2026

Netlify deploy preview

https://deploy-preview-48537--material-ui.netlify.app/

Bundle size report

Bundle Parsed size Gzip size
@mui/material 🔺+107B(+0.02%) 🔺+24B(+0.02%)
@mui/lab 0B(0.00%) 0B(0.00%)
@mui/system 0B(0.00%) 0B(0.00%)
@mui/utils 0B(0.00%) 0B(0.00%)

Details of bundle changes

Generated by 🚫 dangerJS against ac976f5

@mj12albert mj12albert changed the title Fix autocomplete renderInput slotProps [autocomplete] Fix renderInput not passing slotProps May 13, 2026
@mj12albert mj12albert marked this pull request as ready for review May 13, 2026 17:08
Copy link
Copy Markdown
Member

@silviuaavram silviuaavram left a comment

Choose a reason for hiding this comment

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

Looks good, but since this already works with v9, shouldn't we let consumers update instead of back-porting fixes?

const textbox = screen.getByRole('combobox');
expect(textbox).to.have.property('maxLength', 4);

fireEvent.mouseDown(textbox);
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.

is this last part needed?

)}
/>,
);
}).not.toErrorDev();
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.

is this error checking necessary?


unmount();

const { container: selectContainer } = render(
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.

maybe add a separate test for this?

@mj12albert
Copy link
Copy Markdown
Member Author

shouldn't we let consumers update instead of back-porting fixes

I think this one is still worth patching since v7 pushes users towards slotProps but it doesn't work for the very common combination of Autocomplete+TextField @silviuaavram

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

Labels

scope: autocomplete Changes related to the autocomplete. This includes ComboBox. type: bug It doesn't behave as expected. v7.x

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants