相关疑难解决方法(0)

通过事件响应改变输入类型

我正在尝试扩展一个 React 输入组件,该组件需要输入密码,并且在其旁边的元素或元素发生特定事件之后 - 它需要切换输入的类型(type =“text/password”)。

React 如何处理这个问题?

我将其作为我的组件的类:

import { React, Component } from 'lib' 

export class PasswordInput extends Component {
constructor(props, context){
    super(props, context)
    const { type, validate, password } = this.props

    if(context.onValidate && password) {
        context.onValidate(password, validate)
    }

    if(context.showHide && password) {
        context.onValidate(password, validate)
    }
}

render() {
    let inputType = 'password'

    return (
        <div className="form">
            <label htmlFor="password">{ this.props.label }</label>
            <input {...this.constructor.filterProps(this.props)} type={ inputType } />
            { this.props.touched && this.props.error && <div className="error">{ this.props.error }</div> }
            <button …
Run Code Online (Sandbox Code Playgroud)

javascript ecmascript-6 reactjs babeljs react-dom

2
推荐指数
1
解决办法
1万
查看次数

标签 统计

babeljs ×1

ecmascript-6 ×1

javascript ×1

react-dom ×1

reactjs ×1