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.

`OutlinedInput` displays notch when it shouldn't

See original GitHub issue

Kind of a very specific bug and also hard to phrase it properly. But in short, OutlinedInput will have a “notch” even when it was disabled via a theme if TextInput has a prop InputLabelProps={{ shrink: true }}.

  • 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 😯

OutlinedInput will display a border notch If all the following are true

  • The theme has props.MuiOutlinedInput.notched set to false
  • OutlinedInput is rendered by using TextField with prop variant="outlined"
  • TextField also has a prop InputLabelProps={{ shrink: true }}

Expected Behavior 🤔

OutlinedInput should have no border notch, regardless of other, unrelated props.

Steps to Reproduce 🕹

  1. Run the following code:
const NotchIssue = () => {
  const theme = createMuiTheme({
    props: { MuiOutlinedInput: { notched: false } }
  });

  return (
    <ThemeProvider theme={theme}>
      <TextField
        InputLabelProps={{ shrink: true }}
        label="Outlined"
        variant="outlined"
      />
    </ThemeProvider>
  );
};

  1. The above example will output this: Screenshot 2020-03-05 at 11 47 15

Here is a live example in CodeSandbox https://codesandbox.io/s/material-demo-uoxz3

Context 🔦

In my current project, we’re using TextField with variant set to outlined by default, via a theme. The theme also sets notched to false, since we styled the InputLabel to fit inside the field borders.

It doesn’t really block us, since we can hide the <legend /> that causes the notch via CSS. But it did catch my attention while working with it.

Your Environment 🌎

In the demo I shared, all packages are set to latest.

Tech Version
Material-UI latest
React latest
Browser Chrome 80
TypeScript latest

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
eps1loncommented, Mar 5, 2020

So here’s why this happens: Usually you want to display the notch when the label is shrunk, right? I hope we can agree that this would be the desired outcome for most use cases.

To guarantee this TextField sets notched to the same value as InputLabelProps.shrink. The props from the theme act as default values. Since notched is set by the TextField the default value from the theme is ignored.

Basically you’re mixing props from context (theme) with props from author and this creates undesired behavior for you.

The fix for this specific issue would be to put shrink in the theme as well

const theme = createMuiTheme({
  props: {
    MuiOutlinedInput: {
      notched: false
    },
    MuiInputLabel: {
      shrink: true
    }
  }
});
<TextField label="Outlined" variant="outlined" />;
```jsx
or both in props:
<TextField
  InputProps={{ notched: false }}
  InputLabelProps={{ shrink: true }}
  label="Outlined"
  variant="outlined"
/>

I don’t think adding documentation for this would’ve helped.

Why is it important that you set on prop by themed default values and the other one by props from author?

1reaction
eps1loncommented, Mar 5, 2020

Great issue! Not sure why it happens but at least I have a test for it.

Read more comments on GitHub >

github_iconTop Results From Across the Web

OutlinedInput displays notch when it shouldn't #20000 - GitHub
The theme has props.MuiOutlinedInput.notched set to false · OutlinedInput is rendered by using TextField with prop variant="outlined" · TextField ...
Read more >
What the notched property is supposed to do in Material-UI
The notched property only has a visible effect in combination with the labelWidth property. When notched is true, it leaves a gap in...
Read more >
inputlabelprops= shrink true | The AI Search Engine You Control
mui/material-ui`OutlinedInput` displays notch when it shouldn't#20000 ... OutlinedInput will display a border notch If all the following are true.
Read more >
@material/notched-outline | Yarn - Package Manager
Fast, reliable, and secure dependency management.
Read more >
OutlinedInput API - Material UI - MUI
API reference docs for the React OutlinedInput component. ... If true , the outline is notched to accommodate the label. onChange, func.
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