简体   繁体   English

如何在 TextInput 组件中更改边框颜色“onChangeText”

[英]How to change the border colour 'onChangeText' in TextInput Component

So, I was trying to make this nice little TextInput Component where the border colour changes as soon as I start typing and if I clear the text border colour returns to default.所以,我试图制作这个漂亮的小 TextInput 组件,当我开始输入时边框颜色会发生变化,如果我清除文本边框颜色会返回默认值。

Here is the Component TextInput .这是组件TextInput When you write in the textbox, border colour of the textbox will be changed and after clearing text it sets default.当您在文本框中写入时,文本框的边框颜色将被更改,并且在清除文本后设置为默认值。 Please write a small css class.myInput which I wrote in TextInput.css请写一个小的css class.myInput我在TextInput.ZC7A62 8CBA22E28EB17B5F5C6AE2A266AZ

import React, {useEffect, useState} from 'react'
import './TextInput.css'

function TextInput(props) {
    const [style, setStyle] = useState({});

    function textChange(e) {
        if(e.target.value === '')
            setStyle({border: '1px solid gray'});
        else
            setStyle({border: '1px solid red'});
    }
    return (
        <div>
            <input className="myInput" style={style} onChange={textChange} type="text"/>
        </div>
    );
}

export default TextInput;

Here is the css class:这是 css class:

.myInput {    
   outline-width: 0; 
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 React Native TextInput具有默认值当状态更改(onchangetext)时,如何更新/传递DefualtValue作为文本条目 - React Native TextInput have a Default Value How can we update/pass DefualtValue as a Text entry when state change (onchangetext) 如何制作回调函数来填充 textinput onChangeText 的值道具 - How to make a call back function to populate value prop of textinput onChangeText 如何更改 FlatList 中 TextInput 组件的道具? - How to change props of TextInput component in a FlatList? 如何更改 ReactSelect 组件的颜色? - How to change the colour of ReactSelect component? AutoFocus next TextInput onChangeText 崩溃 - AutoFocus next TextInput onChangeText Crash 如何在 onChangeText 回调中立即更改文本? - How to change text immediately in onChangeText Callback? 我们如何在响应本机中从onChangeText的标头的TextInput过滤数据? - How can we fliter data from header's TextInput on onChangeText in react native? 如何更改grommet v2 FormField的活动边框颜色? - How to change active border colour of grommet v2 FormField? 更新onChangeText函数中数组哈希的TextInput值 - Update TextInput value of hash of array in onChangeText function 对于 redux,TextInput 中的 onChangeText 无法正常工作,无法输入 - onChangeText in TextInput is not working as desired with redux, unable to type
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM