react-native-paper icon indicating copy to clipboard operation
react-native-paper copied to clipboard

No way to change underline focused color on TextInput without affecting other colors

Open lamecksilva opened this issue 8 years ago • 38 comments

I tried to change the cursor color in the textinput but it appears to underline, how to disable the underline? or leave it transparent?

lamecksilva avatar Dec 01 '18 23:12 lamecksilva

Can you give some more info on what you did?

satya164 avatar Dec 02 '18 17:12 satya164

I want remove this underline color from text input, but the prop "underlineColor" is not working

screenshot_2018-12-02_14-34-54

lamecksilva avatar Dec 02 '18 17:12 lamecksilva

underlineColor prop is for text input when it is inactive.

raajnadar avatar Dec 11 '18 13:12 raajnadar

Right now the underline when focused uses this logic:

https://github.com/callstack/react-native-paper/blob/master/src/components/TextInput.js#L547-L549

The problem is that you cannot change only that color without affecting the whole TextInput. Moreover, we need more docs on all this, see #775.

ferrannp avatar Jan 28 '19 12:01 ferrannp

still no solution for this?? I would like my textInput to have a customized underline color when focused, cannot change the purple, is there a way to change globally the color used by this plugin??

tinni95 avatar Oct 14 '19 23:10 tinni95

Any update on this issue?

poptocrack avatar Oct 28 '19 16:10 poptocrack

How to remove the underline without affect text colors?

douglasjunior avatar Nov 09 '19 14:11 douglasjunior

If you don't want a material design themed input, use the input from React Native and apply the styling you want https://facebook.github.io/react-native/docs/textinput

satya164 avatar Nov 09 '19 15:11 satya164

I just don't want to have the "underline", but the animated label and everything else I'd like to have.

Unfortunately not every design follows 100% of Material Design. (I have never worked on a project that follow 100% of the recommendations)

To whom it may concern, to "hide" the underline I followed this workaround.

const styles = StyleSheet.create({
    inputContainer: {
        borderRadius: 4,
        height: 55,
        overflow: 'hidden',
    },
    input: {
        borderRadius: 0,
        borderTopLeftRadius: 0,
        borderTopRightRadius: 0,
        height: 57,
        overflow: 'hidden',
        backgroundColor: '#fff',
    },
};
...
<View style={styles.inputContainer}>
       <TextInput
            mode="flat"
            label="Username"
            style={styles.input}
        />
</View>

Note that Input is 2 pixels bigger than View.

mrocto

douglasjunior avatar Nov 09 '19 17:11 douglasjunior

You can use theme={{ colors: { primary: color, } }}

react-native-copy-right avatar Nov 23 '19 08:11 react-native-copy-right

I just don't want to have the "underline", but the animated label and everything else I'd like to have.

Unfortunately not every design follows 100% of Material Design. (I have never worked on a project that follow 100% of the recommendations)

To whom it may concern, to "hide" the underline I followed this workaround.

const styles = StyleSheet.create({
    inputContainer: {
        borderRadius: 4,
        height: 55,
        overflow: 'hidden',
    },
    input: {
        borderRadius: 0,
        borderTopLeftRadius: 0,
        borderTopRightRadius: 0,
        height: 57,
        overflow: 'hidden',
        backgroundColor: '#fff',
    },
};
...
<View style={styles.inputContainer}>
       <TextInput
            mode="flat"
            label="Username"
            style={styles.input}
        />
</View>

Note that Input is 2 pixels bigger than View.

mrocto

I know its not answer, but it solves

ehtishamali042 avatar Nov 23 '19 19:11 ehtishamali042

To change the Underline and Label color when focused, you need to pass the props theme, like this:

        <TextInput
            label='Password'
            underlineColor='#fff'
            theme={{colors: {text: 'green', primary: 'yellow'}}}
          />
  • Text is to change the values that you put in the input
  • Primary is to change the underline and the label color

notmarinho avatar Jan 09 '20 12:01 notmarinho

any update?

ilhamsa1 avatar Feb 04 '20 15:02 ilhamsa1

The problem

To change the Underline and Label color when focused, you need to pass the props theme, like this:

        <TextInput
            label='Password'
            underlineColor='#fff'
            theme={{colors: {text: 'green', primary: 'yellow'}}}
          />
  • Text is to change the values that you put in the input
  • Primary is to change the underline and the label color

the problem is when I want to have two different colors for the label and the underline when focused, which apparently is not possible 👎

tinni95 avatar Feb 11 '20 18:02 tinni95

My workaround has been the following :

<TextInput label='Email' value={email} placeholder={"email"} onChangeText={text => setEmail(text)} style={{ backgroundColor: "white" }} selectionColor={Colors.primary} underlineColor={"white"} /> <View style={{ marginTop: -2,borderTopColor: "white", borderTopWidth: 10 }} />

I basically added a view after the textinput with the desired borderTopColor to cover the undesired one from the textinput

tinni95 avatar Feb 11 '20 19:02 tinni95

Following EhtishamAli786's advice (i.e. setting overflow: 'hidden'), but instead setting bottom margin of TextInput to -2 also works to hide the underline when in focus

jkjellan avatar Feb 24 '20 02:02 jkjellan

+1 also looking for a way to solve this issue.

Evilbits avatar Feb 25 '20 07:02 Evilbits

I think changing only the underline color breaks the material's guidelines. But, here is a possible solution.

belgamo avatar Apr 08 '20 12:04 belgamo

I think changing only the underline color breaks the material's guidelines. But, here is a possible solution.

I never worked on a project that follows 100% of material design guildelines. There will always be something that needs to be customized.

The question is: In React Native we do not have the option to override a CSS class as we do on the web, so it is important that libraries offer a certain level of customization.

A simple property that allows customization of the style is enough.

douglasjunior avatar Apr 08 '20 13:04 douglasjunior

In addition to @douglasjunior solution, I have added a negative marginBottom value -3 to the text input and that's works perfectly!

zeabdelkhalek avatar Apr 30 '20 06:04 zeabdelkhalek