代码之家  ›  专栏  ›  技术社区  ›  victor zadorozhnyy

如何在JSS中指定:focus属性?

  •  0
  • victor zadorozhnyy  · 技术社区  · 6 年前

    我正在使用react native web with expo和react native paper(材质ui)

    我的问题是在已编译的web版本中焦点大纲属性上的textarea,所以我需要去掉这个蓝色边框。通常我会的

    textarea:focus {
        outline:none!important
    }
    

    对于react native,我们不能使用css,只能使用jss,但如何为该属性使用它?

    <TextInput
       label='Email'
       value={this.state.text}
       onChangeText={text => this.setState({ text })}
       style={???} 
    />
    

    working example

    2 回复  |  直到 6 年前
        1
  •  2
  •   Stanley Nguyen    6 年前

    您不能使用React组件的内联样式执行此操作。有两种方法可以实现这一点。

    选项1:将样式放入组件的状态并使用 onFocus 操纵它

    选项2:在JS库中使用CSS,如 https://www.styled-components.com/

        2
  •  2
  •   Nooruddin Lakhani    6 年前

    这可能会有帮助

    state = {
            backgroundColor: 'green'
        }
    
        onFocus() {
            this.setState({
                backgroundColor: 'green'
            })
          }
    
          onBlur() {
            this.setState({
              backgroundColor: '#ededed'
            })
          }
    
        <TextInput 
            onBlur={ () => this.onBlur() }
        onFocus={ () => this.onFocus() }
        style={{ height:60, backgroundColor: this.state.backgroundColor }}  />
    
        3
  •  0
  •   Brian Smith    6 年前

    如果您使用react jss,您可以指定事件样式,如focus和hover,如下所示 &:hover &:focus