1

I have an input with the disabled boolean propagated from the props. I've found that with that disabled variable being set, even when it's true I cannot type into the input. I can, however, type into the input if I hold the mouse down on it and keep it down as I type.

This happens when I render the component as both controlled and uncontrolled.

The only way to fix it is to either removing disabled or setting disabled={false} -- but I need it to be variabled.

This is my input:

  class DashboardWidgetTitle extends React.Component {

    constructor(props) {
      super(props);
      this.state = {};
      this.state.title = props.widget.getTitle();
    }

    render () {
      return <input className="title"
                    value={this.state.title}
                    disabled={!this.props.isEditMode}
                    onChange={this._onInputChange.bind(this)}/>
    }

    _onInputChange(e) {
      logit("input change");
      this.setState({title: e.target.value});
    }

  }

Thanks!

EDIT: Extra info --

  • This is used in a widget within an implementation of ReactGridLayout.
  • The component is rendered by a widget that is rendered by the implementation of react grid layout, the "dashboard". That Dashboard has isEditMode as a state that's changed externally via a toggle in Angular (we use React within Angular).
  • If I switch tabs and come back, the focus remains. Otherwise whenever I type a letter, the input becomes unfocused.
  • The input isn't disabled when it shouldn't be, it just has focusing issues -- however removing the disabled attribute or setting it as a static variable, the issue doesn't remain.
  • When I switch the disabled toggle to be isEditMode rather than !isEditMode, everything works. It seems to be there's an onclick on the draggable/resizable portion of the ReactGridLayout that's causing some issues.
7
  • can you show the code where you render DashboardWidgetTitle Commented Nov 14, 2017 at 20:46
  • Yeah, it's fairly simple: <DashboardWidgetTitle widget={this.props.widget} isEditMode={this.props.isEditMode}/> the isEditMode is set 2 levels up as a state object. It isn't being changed. Commented Nov 14, 2017 at 20:49
  • It just looks like your isEditMode is not being passed down correctly. I would log it's value on render. My guess is that it's undefined (not passed) and !undefined is true. Commented Nov 14, 2017 at 21:00
  • Is this what you want: jsfiddle.net/69z2wepo/91532 Commented Nov 14, 2017 at 21:03
  • yeah that was my first thought too. The input doesn't have the disabled attribute at all when it shouldn't. The input does allow focus, in this case, just not a change. The weirdest part is I can get it to work if I type as I hold down the mouse on the input. I'm Commented Nov 14, 2017 at 21:03

1 Answer 1

1

My issue was described right here: https://github.com/STRML/react-grid-layout/issues/615

My own fault of poor research.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.