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

[TextField] endAdornment is over/below a long label #39427

Closed
2 tasks done
SBRKH opened this issue Oct 13, 2023 · 5 comments · Fixed by #39470
Closed
2 tasks done

[TextField] endAdornment is over/below a long label #39427

SBRKH opened this issue Oct 13, 2023 · 5 comments · Fixed by #39470
Assignees
Labels
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

@SBRKH
Copy link

SBRKH commented Oct 13, 2023

Duplicates

  • I have searched the existing issues

Latest version

  • I have tested the latest version

Steps to reproduce 🕹

Link to live example:
https://stackblitz.com/edit/react-uvs3ey?file=Demo.tsx

Steps:

  1. Create an input
  2. Put a long label
  3. Add an endAdornment

Current behavior 😯

The label is over/below the endAdornment when is longer than the input width.

Expected behavior 🤔

The label sould be truncated with "..." in the same way it's doing when label is more long than the input width.

Context 🔦

I need to put an endAdornment for input like password (for our french users the input is "Mot de passe") and we give them an endAdornment to show their password during the register.
The fact that the end of the label is going over the endAdornment (or below) causes discomfort for some of them.

Your environment 🌎

npx @mui/envinfo
    System:
    OS: macOS 14.0
  Binaries:
    Node: 18.17.1 - /usr/local/bin/node
    Yarn: 1.22.19 - /usr/local/bin/yarn
    npm: 9.8.1 - /usr/local/bin/npm
  Browsers:
    Chrome: 117.0.5938.149
    Edge: Not Found
    Safari: 17.0
  npmPackages:
    @emotion/react: ^11.11.0 => 11.11.0 
    @emotion/styled: ^11.11.0 => 11.11.0 
    @mui/icons-material: ^5.11.16 => 5.11.16 
    @mui/material: ^5.13.2 => 5.13.2 
    @mui/x-date-pickers: ^6.10.2 => 6.10.2 
    @types/react: ^18.0.28 => 18.0.28 
    react: ^18.2.0 => 18.2.0 
    react-dom: ^18.2.0 => 18.2.0 
    typescript: ^5.0.2 => 5.0.2 

@SBRKH SBRKH added the status: waiting for maintainer These issues haven't been looked at yet by a maintainer label Oct 13, 2023
@Abdullah7771
Copy link

A little confused in currrent vs expected behaviour and two passsword labels.Can you provide a little more context.Also while toggling visibility for passwords why is mouse cursor shifted towards start of input instead of end?

@jahedullah
Copy link

@SBRKH how to submit the answer?

@SBRKH
Copy link
Author

SBRKH commented Oct 16, 2023

A little confused in currrent vs expected behaviour and two passsword labels.Can you provide a little more context.Also while toggling visibility for passwords why is mouse cursor shifted towards start of input instead of end?

Hello,
Sorry for the delay.

Actually, this is what i got :
Screenshot 2023-10-16 at 10 01 56
As you can see, the label is over the end adornment for the input "Confirmer le mot de passe"
For me the label should be truncate in the same way that when you've a large label and should be "Confirmer le mot de ...", like that the label will not be over the adornment.

@mj12albert mj12albert changed the title endAdornment is over/below a long label [TextField] endAdornment is over/below a long label Oct 16, 2023
@mj12albert mj12albert added package: material-ui Specific to @mui/material component: text field This is the name of the generic UI component, not the React module! and removed status: waiting for maintainer These issues haven't been looked at yet by a maintainer component: input labels Oct 16, 2023
@mj12albert
Copy link
Member

Related to #36550 and #37069

@SBRKH Here's a workaround you could try:

<TextField
  variant="outlined"
  label="A really long and contrived input label"
  InputLabelProps={{
    sx: {
      maxWidth: `calc(100% - ${isFocused ? 0 : 48}px)`,
    },
  }}
  InputProps={{
    endAdornment: (
      <InputAdornment position="end">
        <IconButton
          aria-label="toggle password visibility"
          onClick={handleClick}
          onMouseDown={handleMouseDown}
          edge="end"
        >
          <Visibility />
        </IconButton>
      </InputAdornment>
    ),
  }}
  onFocus={() => setFocused(true)}
  onBlur={() => setFocused(false)}
  sx={{ width: 100 }}
/>

Demo: https://codesandbox.io/s/https-github-com-mui-material-ui-issues-39427-vx2gvd?file=/demo.tsx

I wouldn't change the default styles for this, customizing the maxWidth of the label is something users can do
What we should do though is fix the ownerState style overrides of InputLabel so that this particular customization can be done without having to manually add a focused state:

const theme = createTheme({
  components: {
    MuiInputLabel: {
      styleOverrides: {
        root: ({ ownerState }) => ({
          ...(ownerState.focused && {
            maxWidth: `calc(100% - ${isFocused ? 0 : 48}px)`,
          }),
        }),
      },
    },
  },
});

@mj12albert mj12albert added the enhancement This is not a bug, nor a new feature label Oct 16, 2023
@SBRKH
Copy link
Author

SBRKH commented Oct 16, 2023

Hi @mj12albert,
The workaround work perfectly thank you, my research was bad apparently (i didn't see theses issues).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
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
5 participants