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

[material-ui][Autocomplete] Shouldn't resize when hovering #42452

Merged

Conversation

ZeeshanTamboli
Copy link
Member

@ZeeshanTamboli ZeeshanTamboli commented May 30, 2024

Fixes #42340

Regression from #41781

In #41781, to prevent the clear icon from overlapping with text in the autocomplete and to add spacing when hovered, min-width: 0 was applied as per this explanation.

When zero minimum width on hover was applied:

Before.fix.issue.42340.mp4

However, this caused an issue (#42340) where hovering over the autocomplete shrinks its width (setting min width to 0) because the minimum width is set to 30px.

Removing the zero minimum width on hover fixes this issue. The original fix (#41781) addressed a specific edge case for small autocompletes (see the width in regression test).

When the zero minimum width is removed on hover, as seen in the following video, the input text and clear icons are close but still acceptable:

After.fix.issue.42340.mp4

IMO, developers should ensure the autocomplete is rendered in a sufficient space where the text and clear icon don't overlap.

The main fix in #41781 was to prevent wrapping of flex items, which is needed only when multiple options are supported in the autocomplete. This retains the fix without needing minimum width on hover.


Before: https://codesandbox.io/p/sandbox/icy-voice-mh8ff2-forked-hxh565?file=%2Fsrc%2FDemo.tsx%3A12%2C28
After: https://codesandbox.io/p/sandbox/icy-voice-mh8ff2-forked-fkrfrt?file=%2Fsrc%2FDemo.tsx


Second commit replaces the deprecated InputProps with slotProps.input.

@ZeeshanTamboli ZeeshanTamboli added package: material-ui Specific to @mui/material component: autocomplete This is the name of the generic UI component, not the React module! regression A bug, but worse needs cherry-pick The PR should be cherry-picked to master after merge labels May 30, 2024
@mui-bot
Copy link

mui-bot commented May 30, 2024

Netlify deploy preview

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

Bundle size report

Details of bundle changes (Toolpad)
Details of bundle changes

Generated by 🚫 dangerJS against ff4eb16

@ZeeshanTamboli ZeeshanTamboli marked this pull request as ready for review May 30, 2024 12:08
@ZeeshanTamboli ZeeshanTamboli requested a review from DiegoAndai May 30, 2024 12:12
Copy link
Member

@DiegoAndai DiegoAndai left a comment

Choose a reason for hiding this comment

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

Thanks for the detailed explanation @ZeeshanTamboli 🚀

@Iron0utlaw
Copy link

Hi @ZeeshanTamboli , can you please provide me an explanation of how to solve this in an existing project?

joserodolfofreitas pushed a commit to joserodolfofreitas/material-ui that referenced this pull request Jul 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component: autocomplete This is the name of the generic UI component, not the React module! needs cherry-pick The PR should be cherry-picked to master after merge package: material-ui Specific to @mui/material regression A bug, but worse
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[material-ui][Autocomplete] Resizing on hover/focus when displayed in a table with table-layout: auto set
4 participants