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.

[InputBase] - Add Mui-readOnly class

See original GitHub issue
  • I have searched the issues of this repository and believe that this is not a duplicate.

Summary 💡

When readonly attribute is set to true, add a Mui-readOnly (suggested name) class to the input / div associated. This already happens when disabled set to true (.Mui-disabled)

Examples 🌈

      <TextField
        id="filled-basic"
        label="Filled readOnly"
        variant="filled"
        value="text"
        disabled
        InputProps={{
          readOnly: true
        }}
      />

image

Motivation 🔦

I want my readOnly fields to behave in a specific way, in this specific case I want to set pointer-events: none when my fields are readonly.

As MUI wraps the input field with a div, even when my input has pointer-events: none, the div still keeps the default behavior like changing colors on hover, which is undesirable behavior.

There are different solutions for this but AFAIK all of them would need extra logic which I believe it would be avoided by having this class…I could do, for example:

 MuiFilledInput: {
        " & .Mui-readOnly": {
          pointerEvents: "none"
        }
      }

Also, there is already classes like Mui-focused, Mui-error and Mui-disabled, I believe Mui-readOnly would be a nice addition.

Issue Analytics

  • State:open
  • Created 2 years ago
  • Reactions:10
  • Comments:9 (3 by maintainers)

github_iconTop GitHub Comments

7reactions
Samuel-Beslogiccommented, Aug 10, 2021

+1 I’d even ask for readonly to be a prop of InputBase (and by extension, TextField)

1reaction
ZeeshanTambolicommented, Aug 25, 2022

readOnly prop was added for Input in #33654 which was released in @mui/material@5.9.3.

Read more comments on GitHub >

github_iconTop Results From Across the Web

InputBase API - Material UI - MUI
Name Type Default autoComplete string autoFocus bool false classes object
Read more >
Passing class from Material-UI TextField to InputBase
TextField has an InputProps prop to pass values down to the OutlinedInput . But I need to pass a className prop down to...
Read more >
@material-ui/core InputBase JavaScript Examples
This page shows JavaScript code examples of @material-ui/core InputBase.
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