question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[TextField] Long labels break layout

See original GitHub issue

The textfield layout is not responsive when there are long labels.

  • This is a v1.3.1 issue.
  • I have searched the issues of this repository and believe that this is not a duplicate.

Expected Behavior

According to Material Design, long labels should be correctly positioned within the available input space: 2018-07-23 13 49 06

Current Behavior

  • Two or more line labels are overlapping the underline line.

Steps to Reproduce

https://codesandbox.io/s/6xjr79vx3w

import React from 'react';
import TextField from '@material-ui/core/TextField';

class TextFields extends React.Component {
  render() {
    return (
      <form noValidate autoComplete="off">
        <TextField
          id="name"
          label="This is a long label because things"
        />
      </form>
    );
  }
}

export default TextFields;

Context

  • All content is usually content managed, which means that the content editors could enter in label that may break the layout.
  • If the enter in a label that is longer than the available space, example: “Do you have any association with a government entity?”, and the user is loading the page in an iPhone 5, there is no enough space to render the label in only one line.

Your Environment

Tech Version
Material-UI v1.3.1
React v16.4.1
browser Chrome

Issue Analytics

  • State:open
  • Created 5 years ago
  • Reactions:7
  • Comments:40 (22 by maintainers)

github_iconTop GitHub Comments

7reactions
ErikParsocommented, Nov 26, 2019

I found a workaround to trim label with ellipsis

.label {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    right: 22px; //do not overlap icon
    bottom: 0px; //maximize container height so label wont be cut horizontaly
}

.label-shrinked {
    right: unset; //show complete label if shrinked
}

and in my component

...
<InputLabel
    classes={{
        root: styles.label,
        shrink: styles["label-shrinked"]
    }}
    id="label">

    {this.props.text}
</InputLabel>
...

result looks like this:

image

image

7reactions
kybargcommented, Jul 24, 2018

@csantos1113 @oliviertassinari From specs: image Labels should be short in other case use helper text instead

Read more comments on GitHub >

github_iconTop Results From Across the Web

[TextField] Long labels break layout #12255 - mui/material-ui
The textfield layout is not responsive when there are long labels. This is a v1.3.1 issue. I have searched the issues of this...
Read more >
long label of \textfield with a break? - LaTeX Stack Exchange
As you can see the foobar text doesn't align on the left side, but instead goes under the textfield. I tried to use...
Read more >
Input field with label in semantic-ui breaks layout
I played around a bit and found a work-around that uses right (or left) aligned icons instead of labels. Hope this helps.
Read more >
C38: Using CSS width, max-width and flexbox to fit labels and ...
This technique ensures labels and inputs do not break out of their layout area, including in one-column layouts where it would cause horizontal...
Read more >
Long label ends with ellipsis instead of breaking
Expected behavior. Long labels should break to 2 lines instead of ending with an ellipsis as it was recently. Actual behavior. Label text...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found