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

[Autocomplete] start adornment position issue with filled variant autocompletes #22544

Open
ImanMahmoudinasab opened this issue Sep 9, 2020 · 3 comments · May be fixed by #22609
Open

[Autocomplete] start adornment position issue with filled variant autocompletes #22544

ImanMahmoudinasab opened this issue Sep 9, 2020 · 3 comments · May be fixed by #22609

Comments

@ImanMahmoudinasab
Copy link
Contributor

@ImanMahmoudinasab ImanMahmoudinasab commented Sep 9, 2020

  • The issue is present in the latest release.
  • I have searched the issues of this repository and believe that this is not a duplicate.

Current Behavior 😯

start adornment's position is not correct when autocomplete has a filled variant. it has an extra margin on top:
image

image

image

Expected Behavior 🤔

image

Steps to Reproduce 🕹

Demo: codesandbox

Your Environment 🌎

Tech Version
Material-UI v4.11.0
MUI lab 4.0.0
React 16.13.1
Browser chrome
@mnajdova
Copy link
Member

@mnajdova mnajdova commented Sep 11, 2020

Thanks for the repro @ImanMahmoudinasab

Seems like the margin is coming from the InputAdornment styles:

  /* Styles applied to the root element if `variant="filled"`. */
  filled: {
    '&$positionStart:not($hiddenLabel)': {
      marginTop: 16,
    },
  },

so we need to basically remove the margin. I would propose the following change:

diff --git a/packages/material-ui-lab/src/Autocomplete/Autocomplete.js b/packages/material-ui-lab/src/Autocomplete/Autocomplete.js
index 88e164428..77c4d7c34 100644
--- a/packages/material-ui-lab/src/Autocomplete/Autocomplete.js
+++ b/packages/material-ui-lab/src/Autocomplete/Autocomplete.js
@@ -122,6 +122,9 @@ export const styles = (theme) => ({
         padding: '4.5px 4px',
       },
     },
+    '& [class*="MuiInputAdornment-filled"][class*="MuiInputAdornment-positionStart"]:not([class*="MuiInputAdornment-hiddenLabel"])': {
+      marginTop: 0,
+    },
   },
   /* Styles applied to the input element. */
   input: {

This is the end result:

image

What do you think about this? Would you like to work on a PR for this? :)

@oliviertassinari
Copy link
Member

@oliviertassinari oliviertassinari commented Sep 11, 2020

@mnajdova +1

The structural difference is that the OutlinedInput has the <input /> takes the whole height, while with the Autocomplete, it behaves likes a multiline OutlinedInput, the <input /> only takes the minimum amount of height it needs to function correctly.

We have the same issue with:

<TextField
  InputProps={{
    startAdornment: <InputAdornment position="start">Which?</InputAdornment>
  }}
  multiline
  label="Combo box"
  variant="filled"
/>

Capture d’écran 2020-09-11 à 13 30 50

https://codesandbox.io/s/material-demo-forked-1bdng?file=/demo.js

This has the same root cause than what we have with #21409 (Autocomplete) and #22241 (multiline TextField).

@oliviertassinari
Copy link
Member

@oliviertassinari oliviertassinari commented Sep 11, 2020

Maybe in the future, we should look into how we can unify the CSS for multiline and Autocomplete use cases.

@elishakutnick elishakutnick linked a pull request that will close this issue Sep 15, 2020
1 of 1 task complete
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

3 participants
You can’t perform that action at this time.