React Native focus underline

81 views Asked by At

How can I remove the white bar on focus of my TextInput ? I have tried to removed it with underlineColor but I still see it

<TextInput
  style={[styles.input, styles.textArea]}
  placeholder="Raison de l'absence"
  value={reason}
  onChangeText={setReason}
  underlineColor="transparent"
  underlineColorAndroid="transparent"
  autoFocus={false}
/>;

I am using MD3DarkTheme from react-native-paper

textArea: {
        borderColor: 'transparent',
    },

input: {
        width: '100%',
        height: 40,
        borderWidth: 1,
        borderRadius: 5,
        marginBottom: 15,
        paddingLeft: 10,
        justifyContent: 'center',
        color: PaperDarkTheme.colors.text,
    },

Solution : According to the documentation I had to change activeUnderlineColor

White Bar

2

There are 2 answers

0
Vibhor On

By passing primary color as transparent in the theme prop you can get of underline from TextInput.

import { TextInput } from "react-native-paper";

<TextInput
  style={[styles.input, styles.textArea]}
  placeholder="Raison de l'absence"
  value={reason}
  onChangeText={setReason}
  underlineColor="transparent"
  underlineColorAndroid="transparent"
  outlineColor="transparent"
  autoFocus={false}
  theme={{ colors: { primary: "transparent" } }} // add this
/>;
0
Pratik Prakash Bindage On
import React from 'react';
import { TextInput, DefaultTheme } from 'react-native-paper';

const MyTextInput = ({ value, onChangeText, placeholder }) => {
  const customTextInputTheme = {
    ...DefaultTheme,
    colors: {
      ...DefaultTheme.colors,
      primary: 'transparent',
      underlineColor: 'transparent',
    },
  };

  return (
    <TextInput
      style={{ marginBottom: 15 }}
      theme={customTextInputTheme}
      label={placeholder}
      value={value}
      onChangeText={onChangeText}
    />
  );
};

export default MyTextInput;