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] Custom end adornment placement differs from TextField #42680

Open
stevepennings opened this issue Jun 18, 2024 · 7 comments
Assignees
Labels
component: autocomplete This is the name of the generic UI component, not the React module! component: text field This is the name of the generic UI component, not the React module! enhancement This is not a bug, nor a new feature package: material-ui Specific to @mui/material

Comments

@stevepennings
Copy link

stevepennings commented Jun 18, 2024

Steps to reproduce

Here's a sandbox of my 'bare-minimum implementation'.

Current behavior

Would it be possible to get the end adornment investigated with the 'standard' and 'filled' variant in mind? The spacing of the InputBase in the TextField is very different when wrapped in the Autocomplete.

If I miss something in my implementation, I'd be very grateful for support.

Expected behavior

The EndAdornment of the TextField having the same vertical placing as the EndAdornment of the Autocomplete.

Context

I've got a custom TextField component extending the TextField component of MUI. I'm trying to make the custom Textfield compatible with the Autocomplete of MUI. The 'filled' and 'standard' are surprisingly not behaving the same as 'outlined'.

Your environment

Search keywords: component:autocomplete

@stevepennings stevepennings added the status: waiting for maintainer These issues haven't been looked at yet by a maintainer label Jun 18, 2024
@zannager zannager added component: text field This is the name of the generic UI component, not the React module! component: autocomplete This is the name of the generic UI component, not the React module! labels Jun 18, 2024
@steve-pennings
Copy link

Additionally I'd like to mention that the end adornment of the AutoComplete creates more padding once a value has been selected. When hovered the clear button shows itself <> hidden with the same padding. Consequently, the end adornment also ends up having odd spacing from the right when it's not hovered. Somehow I can't believe I'm the only one facing this issue, but I truly could not find similar issues. Apologies if there are...

@mnajdova mnajdova assigned danilo-leal and unassigned mj12albert Jun 19, 2024
@mnajdova mnajdova added the design This is about UI or UX design, please involve a designer label Jun 19, 2024
@steve-pennings
Copy link

Just found this issue that may have something to do with this one:
#28465 (comment)

@zannager zannager assigned DiegoAndai and unassigned danilo-leal Aug 2, 2024
@DiegoAndai
Copy link
Member

Hey, @steve-pennings. Thanks for the report, and sorry for the late reply.

As you mentioned, there's a difference between how the end adornment is handled in the TextField when inside Autocomplete. In this case, I recommend replacing the endAdornment completely and not relying on props.InputProps.endAdornment inside renderInput. Here's an example of what I mean that you can use as a workaround: https://codesandbox.io/p/sandbox/mui-autocomplete-textfield-filled-with-endadornment-forked-535q4g?file=%2Fsrc%2FApp.js

I believe there's room for improvement here, so the behavior is more consistent, so I'm adding it to the next major's milestone.

@DiegoAndai DiegoAndai added package: material-ui Specific to @mui/material enhancement This is not a bug, nor a new feature and removed status: waiting for maintainer These issues haven't been looked at yet by a maintainer design This is about UI or UX design, please involve a designer labels Aug 21, 2024
@DiegoAndai DiegoAndai added this to the Material UI: v7 (draft) milestone Aug 21, 2024
@DiegoAndai DiegoAndai changed the title Autocomplete: end adornment placement of TextField [material-ui][Autocomplete] Custom end adornment placement differs from TextField Aug 21, 2024
@steve-pennings
Copy link

Amazing, appreciate your reply and your workaround, thank you! Good luck with the next major milestone.

@TiagoPortfolio
Copy link

This solution still makes the end adornment overlap the clear icon

@DiegoAndai
Copy link
Member

@TiagoPortfolio right, with the workaround, you would have to re-implement the clear icon. This is something to consider for the future proper solution.

@Nefcanto
Copy link

Nefcanto commented Feb 2, 2025

I also encountered this error. This is our Autocomplete look:

Image

We want our Autocomplete to become a browsable field too (to open a full-featured list dialog with all filtering and sorting and searching capabilities to find and select and item).

Ths is our code:

                    renderInput={params => <TextField
                        {...params}
                        label={t(label)}
                        onBlur={() => {
                            if (!isDirty) {
                                setIsDirty(true)
                            }
                        }}
                        InputProps={{
                            ...additionalProps,
                            ...params.InputProps,
                            endAdornment: <>
                                {
                                    progress
                                        ?
                                        <Progress size={20} />
                                        :
                                        <BrowserIcons onCleared={() => {
                                            removeFilter(property)
                                            setSelectedEntity(null)
                                        }} />
                                }
                            </>,
                        }}
                    />
                    }

That workaround is a bad recommendation. Because it uses hardcoded values, we should be able to keep MUI theme values dynamically to be forward-compatible.

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! component: text field This is the name of the generic UI component, not the React module! enhancement This is not a bug, nor a new feature package: material-ui Specific to @mui/material
Projects
None yet
Development

No branches or pull requests

10 participants