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] proposal: read-only prop #9790

Closed
caub opened this issue Jan 8, 2018 · 5 comments
Closed

[TextField] proposal: read-only prop #9790

caub opened this issue Jan 8, 2018 · 5 comments
Labels
component: text field This is the name of the generic UI component, not the React module! support: question Community support but can be turned into an improvement

Comments

@caub
Copy link
Contributor

caub commented Jan 8, 2018

It would interesting to be able to switch easily between a "presentation"/review mode and an editable mode

Like disabled prop, but not with that opacity

Let me make a codesandox demonstrating it

@oliviertassinari
Copy link
Member

oliviertassinari commented Jan 8, 2018

How is it different from using the readOnly attribute of the native input?

@oliviertassinari oliviertassinari added the component: text field This is the name of the generic UI component, not the React module! label Jan 8, 2018
@caub
Copy link
Contributor Author

caub commented Jan 8, 2018

Good point, I didn't know about it, the only annoying part is that the field has still the focusable effect https://codesandbox.io/s/lp7z7zkp1z even in read-only

But that's native https://jsfiddle.net/crl/70jw3nah/ too so I can manage that myself

Thanks, I will close

I'd still want maybe a way to disable the Input's inkbar, when it's readOnly, will see what I can do

@caub caub closed this as completed Jan 8, 2018
@oliviertassinari
Copy link
Member

oliviertassinari commented Jan 9, 2018

@caub Great. Here is the answer in case codesandbox lost this piece of code:

import React from 'react';
import { render } from 'react-dom';
import TextField from './TextField';
import Button from 'material-ui/Button';

class App extends React.Component {
  state = {readOnly: true}

  render() {
    const {readOnly} = this.state;
    return (
      <div>
        <TextField
          inputProps={{
            readOnly: Boolean(readOnly),
            disabled: Boolean(readOnly),
          }}
          required
          fullWidth={true}
          label="Name"
          name="name"
          margin="normal"
          defaultValue={"test"}
        />
        <Button raised
          onClick={e => {this.setState({readOnly: !readOnly})}}>
          {readOnly ? 'edit' : 'review'}
        </Button>
      </div>
    )
  }
}

render(<App />, document.getElementById('root'));

@oliviertassinari oliviertassinari added the support: question Community support but can be turned into an improvement label Jan 9, 2018
@sameer-kumar-jain
Copy link

I am having weird issue with this, if I have an empty readonly TextField and update its value on later state change, I can see overlapping label and value.

@sameer-kumar-jain
Copy link

Sorry false alarm, I missed setting initial state parameter

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! support: question Community support but can be turned into an improvement
Projects
None yet
Development

No branches or pull requests

3 participants