reactjs - 在 Material Design Light 和 React 中动态设置 Textfield 值时标签不 float

标签 reactjs material-design-lite

当我动态设置值(即不通过键入更新 Prop )时,标签不会移开。

我的代码是

  render: function() {
    // Removed some minor logic here that isn't related
    return(
      <div className={classes}>
        <div className={_mdlInputClassNames} ref="inputContainer">
          <input
            ref="input"
            type="text"
            id={this.props.id}
            className="mdl-textfield__input"
            data-upgraded
            name={this.props.name}
            value={this.props.value}
            onKeyDown={this.props.onKeyDown}
            onKeyUp={this.props.onKeyUp}
            onChange={this._onChange}
            onBlur={this.props.onBlur}
            autoComplete="off" />
          <label
            htmlFor={this.props.id}
            className="mdl-textfield__label" >
              {this.props.label}
          </label>
          <div className={msgClasses}>{msg}</div>
        </div>
      </div>
    );
  },


  componentDidUpdate: function() {
    // THIS DOESNT DO ANYTHING
    // var inputContainer = this.refs.inputContainer.getDOMNode();
    // componentHandler.upgradeElement(inputContainer, 'MaterialTextfield');
  },

根据我在网上找到的信息,升级该元素应该可行。但它没有任何作用。

查看 DOM 元素,它上面已经有一个 is-upgraded 类,但没有 is-dirty 类,后者似乎是实际移动的类标签。

任何帮助都会很棒

最佳答案

这对我有用:

$("#inputId").val("thevalue").parent().addClass("is-dirty");

关于reactjs - 在 Material Design Light 和 React 中动态设置 Textfield 值时标签不 float ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33341464/

相关文章:

javascript - 未捕获错误 : Expected onClick listener to be a function, 而得到类型字符串

forms - 如何在 Material Design Lite 中根据表单内容启用/禁用提交按钮?

html - Material Design Lite 响应式 CSS 不适用于移动设备/平板电脑或 Chrome DevTools 模拟器

javascript - 在 Material 设计灯中选择选项卡时调用函数

javascript - keyCode 返回 'undefined' ( react )

javascript - "Error: You may not call store.getState() while the reducer is executing."

javascript - ReactJS 无法映射数组

javascript - 我可以从 reactJS 中的渲染条件函数更改我的 css 样式属性吗?

javascript - 多 Material 设计精简版 snackbar 的时间错误

css - 更改 mdl-layout-header 的高度 mdl-layout-header-row