Skip to content

Commit

Permalink
[TextField] Fix outlined render gap if label = empty string (#19722)
Browse files Browse the repository at this point in the history
  • Loading branch information
captain-yossarian authored Mar 1, 2020
1 parent a698407 commit e6e329f
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 9 deletions.
17 changes: 8 additions & 9 deletions packages/material-ui/src/TextField/TextField.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,15 +106,14 @@ const TextField = React.forwardRef(function TextField(props, ref) {
if (InputLabelProps && typeof InputLabelProps.shrink !== 'undefined') {
InputMore.notched = InputLabelProps.shrink;
}

InputMore.label = label ? (
<React.Fragment>
{label}
{required && '\u00a0*'}
</React.Fragment>
) : (
label
);
if (label) {
InputMore.label = (
<React.Fragment>
{label}
{required && '\u00a0*'}
</React.Fragment>
);
}
}
if (select) {
// unset defaults from textbox inputs
Expand Down
8 changes: 8 additions & 0 deletions packages/material-ui/src/TextField/TextField.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,14 @@ describe('<TextField />', () => {

expect(container.querySelector('label')).to.have.class('foo');
});

['', undefined].forEach(label => {
it(`should not render empty (${label}) label element`, () => {
const { container } = render(<TextField id="labelled" label={label} />);

expect(container.querySelector('label')).to.be.null;
});
});
});

describe('with a helper text', () => {
Expand Down

0 comments on commit e6e329f

Please sign in to comment.