Change TextInput Style on Focus React Native Paper
Asked Answered
A

5

5

First of all, I've researched through other posts and find many solutions but nothing work in React Native Paper ?

I need change TextInput Style on Focus in React Native Paper

Auriga answered 10/12, 2019 at 6:42 Comment(1)
You can add extra style on hover event to the selected textareaAlleyne
K
6
const { isActive } = this.state;
const customStyle = isActive ? styles.customText : {};


<TextInput
    label='Email'
    value={this.state.text}
    style={customStyle}
    onFocus={() => this.setState({ isActive: true, })}
    onBlur={() => this.setState({ isActive: false, })}
    onChangeText={text => this.setState({ text })}
/>
Kuhn answered 17/12, 2019 at 7:14 Comment(0)
T
2

You can use the onBlur and onFocus that come with TextInput from react-native-paper the methods to change the styling. Example: to be placed in the render method

const { isActive } = this.state;
const customStyle = isActive ? styles.customText : {};

the component as placed in the return function

<TextInput
    label='Email'
    value={this.state.text}
    style={customStyle}
    onFocus={() => this.setState({ isActive: true, })}
    onBlur={() => this.setState({ isActive: false, })}
    onChangeText={text => this.setState({ text })}
/>
Taco answered 10/12, 2019 at 9:49 Comment(0)
A
1

You can add extra style on hover event to the selected textarea and remove that style onBlur, This can be achieved by using state value check as given below

class Myclass extends Component {
constructor(props) {
    super(props);
    this.state = {
      focus : false,
      name  : ''
    }
}

render() {    
    return (

            <TextInput 
                style={[styles.mText,this.state.focus? styles.textFocus : null]}
                placeholder=""
                onChangeText={(value) => this.setState({ name:value })}
                value={this.state.name}
                onFocus={()=>{this.setState({focus:true})}}
                onBlur={()=>{this.setState({focus:false})}}
            />

    );
}

}

Style for textinput is given below

const styles = StyleSheet.create({

  mText:{
    backgroundColor: '#fff',
    padding:5,
    height:40,
    width:300,
    borderColor:"#333",
    borderStyle:"solid",
    borderWidth:1,
  },

  textFocus:{
    backgroundColor: '#eee',
    borderColor:"#5d05d5",
  },

});
Alleyne answered 10/12, 2019 at 10:8 Comment(0)
S
1

just add theme in the TextInput tag

<TextInput theme={{ colors: { primary: "color of your wish" } }} />
Scampi answered 12/12, 2020 at 9:15 Comment(0)
M
0

Bro You can use activeOutlineColor="" it'll change your outline text color as well as your outline(border). If you want to set outline color diffrent than you can use outlineStyle={borderWidth: 1, borderColor: ""} whatever you want.

Misguided answered 11/4, 2023 at 7:11 Comment(1)
As it’s currently written, your answer is unclear. Please edit to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers in the help center.Compression

© 2022 - 2024 — McMap. All rights reserved.