Displaying text values with a colored background is a feature of the TextInput component in React Native

Seeking assistance with creating a login screen using React Native, featuring semi-transparent text input. Encountering a peculiar issue where typed text appears highlighted, even though it is not. Please see the screenshot below:

(Unable to upload to imgur, here is the image link: )

Below is my code snippet:

class LoginForm extends Component {

    //#region Constructors   
    constructor(props) {
        // Calling the Component constructor
        super(props);
        // Initializing component properties
        this.state = {
            isLoading: false,
            usernameInput: "",
            passwordInput: "",
            urlInput: "",
            portInput: "443"
        };
    }
    //#endregion

    //#region Component Lifecycle
    componentDidMount() {
        
    }

    render() {

        return (
            <View style={styles.mainContainer} pointerEvents={this.state.isLoading ? 'none' : 'auto'}>
                <TextInput style = {styles.input} 
                            autoCapitalize="none" 
                            onSubmitEditing={() => this.passwordInput.focus()} 
                            autoCorrect={false} 
                            keyboardType='email-address' 
                            returnKeyType="next" 
                            placeholder='*Email*' 
                            placeholderTextColor={COLOR_GREY_300}
                            value={this.state.usernameInput}
                            onChangeText={text => this.setState({usernameInput: text})}/>
                <TextInput style = {styles.input}   
                            returnKeyType="go" 
                            ref={(input)=> this.passwordInput = input} 
                            onSubmitEditing={() => this.urlInput.focus()}
                            placeholder='*Password*' 
                            returnKeyType="next" 
                            placeholderTextColor={COLOR_GREY_300} 
                            secureTextEntry
                            value={this.state.passwordInput}
                            onChangeText={text => this.setState({passwordInput: text})}/>
                <TextInput style = {styles.input} 
                            autoCapitalize="none" 
                            onSubmitEditing={() => this.portInput.focus()} 
                            ref={(input)=> this.urlInput = input} 
                            autoCorrect={false}  
                            returnKeyType="next" 
                            placeholder='*url address*' 
                            placeholderTextColor={COLOR_GREY_300}
                            value={this.state.urlInput}
                            onChangeText={text => this.setState({urlInput: text})}/>
                <TextInput style = {styles.input} 
                            autoCapitalize="none" 
                            onSubmitEditing={this._onSubmitLogin} 
                            ref={(input)=> this.portInput = input} 
                            autoCorrect={false}  
                            keyboardType='number-pad' 
                            returnKeyType="go" 
                            placeholder='*port*' 
                            placeholderTextColor={COLOR_GREY_300}
                            value={this.state.portInput}
                            onChangeText={text => this.setState({portInput: text})} />
                <TouchableOpacity style={styles.buttonContainer} onPress={this._onSubmitLogin}>
                    <Text style={styles.buttonText}>*LOGIN*</Text>
                </TouchableOpacity> 
                <ActivityIndicator size="large" color={COLOR_SECONDARY} animating={this.state.isLoading} style={styles.activityIndicator} />
            </View>
        );
    }
    //#endregion

    //#region Listeners
    _onSubmitLogin = () => {
        // Show loader
        this.setState({
            isLoading: true
        });

        // Retrieve API KEY
        let authController = new OBAuthController();
        authController.callPostCreateApiKey().then((apiKey) => {
            
            console.log("apiKey = " + JSON.stringify(apiKey));
            // Hide loader
            this.setState({
                isLoading: false
            });
        });
    }
    //#endregion
}

export default LoginForm;

//#region StyleSheet Definition   
const styles = StyleSheet.create({
    mainContainer: {
        padding: 50
    },
    input:{
        height: 40,
        backgroundColor: 'rgba(225,225,225,0.3)',
        marginBottom: 16,
        padding: 10,
        color: '#fff'
    },
    buttonContainer:{
        backgroundColor: '#2980b6',
        paddingVertical: 15
    },
    buttonText:{
        color: 'white',
        textAlign: 'center',
        fontWeight: '700'
    },
    activityIndicator: {
        position:'absolute',
        alignSelf:'center'
    }
})
//#endregion

Any suggestions or solutions to this issue? Thank you!

Answer №1

After taking @Hariks suggestion, I decided to enclose each of my TextInput components within a View:

<View style={styles.inputView}>
                    <TextInput style = {styles.input} 
                                autoCapitalize="none" 
                                onSubmitEditing={() => this.passwordInput.focus()} 
                                autoCorrect={false} 
                                keyboardType='email-address' 
                                returnKeyType="next" 
                                placeholder='*Email*' 
                                placeholderTextColor={COLOR_GREY_300}
                                value={this.state.usernameInput}
                                onChangeText={text => this.setState({usernameInput: text})}/>
                </View>
                <View style={styles.inputView}>
                    <TextInput style = {styles.input}   
                                returnKeyType="go" 
                                ref={(input)=> this.passwordInput = input} 
                                onSubmitEditing={() => this.urlInput.focus()}
                                placeholder='*Password*' 
                                returnKeyType="next" 
                                placeholderTextColor={COLOR_GREY_300} 
                                secureTextEntry
                                value={this.state.passwordInput}
                                onChangeText={text => this.setState({passwordInput: text})}/>
                </View>
                <View style={styles.inputView}>
                    <TextInput style = {styles.input} 
                                autoCapitalize="none" 
                                onSubmitEditing={() => this.portInput.focus()} 
                                ref={(input)=> this.urlInput = input} 
                                autoCorrect={false}  
                                returnKeyType="next" 
                                placeholder='*URL address*' 
                                placeholderTextColor={COLOR_GREY_300}
                                value={this.state.urlInput}
                                onChangeText={text => this.setState({urlInput: text})}/>

                </View>
                <View style={styles.inputView}>
                    <TextInput style = {styles.input} 
                                autoCapitalize="none" 
                                onSubmitEditing={this._onSubmitLogin} 
                                ref={(input)=> this.portInput = input} 
                                autoCorrect={false}  
                                keyboardType='number-pad' 
                                returnKeyType="go" 
                                placeholder='*Port*' 
                                placeholderTextColor={COLOR_GREY_300}
                                value={this.state.portInput}
                                onChangeText={text => this.setState({portInput: text})} />
                </View>

And here are the corresponding styles:

inputView: {
        height: 40,
        backgroundColor: 'rgba(225,225,225,0.3)',
        marginBottom: 16,
        padding: 10,
    },
    input:{
        color: '#fff'
    },

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Customize CSS for Vimeo's HTML5 player

Can I customize Vimeo's HTML and CSS attributes? I have a video that autoplays and I don't want the play button. I want to modify this specific class. .a.l .b .as { position: absolute; top: 50%; left: 50%; margin: -2em 0 0 -3.25em; float: none; ...

Radio button - arranging the background image and text in alignment

I'm struggling to align my custom radio buttons alongside text. Here is an example image: https://i.sstatic.net/2g5w8.jpg Despite using CSS for styling, I am unable to properly align the radio buttons. Below is a snippet of my HTML: label.item { ...

Using jQuery to compare input with the current select optgroup choices

I'm struggling with looping through options within a form select. The options are grouped into optgroups, and I believe this is where my issue lies as I can't seem to find the correct syntax. My objective is to compare the value entered using .v ...

Increase the options available in the dropdown menu by adding more selected items, without removing any already selected

I came across this code on the internet http://jsfiddle.net/bvotcode/owhq5jat/ When I select a new item, the old item is replaced by the new item. How can I add more items without replacing them when I click "dropdown list"? Thank you <select id=&qu ...

Is there a glitch in the Bootstrap v4 Navbar?

Encountering an issue with the default navbar example from Bootstrap's official website. The navbar is supposed to be full-sized and collapse when the screen size decreases. However, after implementing the code into my project, it appears as always co ...

The reason the section's height is set to 0 is due to the absolute positioning of the div

Currently, I have a section tag with three divs inside that are positioned absolute (used for the isotope plugin). <section id="section1" class="cd-section"> // pos. static/relative has height 0px <div class="itemIso"> // pos. absolute, he ...

Creating a three-column layout with position fixed in the center

I'm struggling with achieving a maximum width of 400px for the entire set of three columns and centering them. ---------------------------------------------------- | | | |----------------------------- ...

Immediate display of collapsed/toggle menu in a Bootstrap navbar

I have created a bootstrap responsive navigation menu that collapses into a box when the page is resized. It's a standard menu with bootstrap, but I'm facing an issue where the menu automatically appears when the page gets small instead of needin ...

Effective method for loading UIImage

One dilemma I am facing in my app is reusing icons across multiple views, like a favorite icon. I'm considering using a class with class methods to load static images for memory optimization. What do you think? For instance: + (UIImage *)favoriteIc ...

Filtering rows of an HTML table that contain links in the `<href>` column data in real time

When using HTML and JavaScript, I have found a solution that works well for many of the columns I am working with. You can see the details on how to dynamically filter rows of an HTML table using JavaScript here. var filters=['hide_broj_pu',&apo ...

When hovering over an image, CSS text will be displayed

Creating a CSS hover effect where text appears when the user hovers over a small thumbnail and a large image is displayed upon clicking. I have set up a modal for the image, but having difficulty with positioning the text. Currently, the text is located un ...

Is it possible to insert a button into a specific column of an ngx-datatable within an Angular 8 application?

I am having trouble with this particular HTML code. <ngx-datatable-column name="Option" prop="option" [draggable]="false" [resizeable]="false [width]="250"> <span> <button class="optionButton" type="button" data-to ...

Creating a UIView Controller Instance

I am having trouble programmatically instantiating a UIView and UIViewController, as none of my labels or text fields are being displayed. Below is the code for my view controller: import UIKit class AdminNewsController: UIViewController { var adminNew ...

Tips for positioning two fields side by side on a webpage with CSS

I currently have two datepickers aligned vertically and I'm looking to display them in a horizontal layout with some spacing between them. What changes do I need to make in order to present these two calendar pickers side by side on the same row? Cou ...

Generate distribution profile using an iOS .p12 certificate

My Client has provided me with a .p12 certificate, which I have successfully installed on my KeyChain. Now, I need to use this certificate to create a distribution provisioning profile and sign my app IPA with it. Can someone guide me on how to create the ...

Establishing picture displays for specific table sections

Can you help me with a tableview issue in my app? Initially, my tableview has 4 rows with the same images displayed. When I click on the first row, I manually add sub-rows beneath it and reload the tableview. If I click on the first row again, I want to ...

Track and log specific route requests with ExpressJS morgan feature

Hello, I am currently utilizing the NodeJS web framework Expressjs along with a middleware called morgan to log requests to a file. Here is my configuration: // create a write stream (in append mode) var accessLogStream = fs.createWriteStream(__dirname + ...

Labels arranged in a fixed width format

Is there a way to ensure that the labels for the inputs are all the same width, creating a more cohesive table-like layout? Imagine it as two columns: one for the labels and one for the inputs. Here is the code I have so far: th, td, table{border: 2px ...

Simple HTML files on a local server are having trouble loading images and JavaScript, yet the CSS is loading

Having worked in web design for quite some time, I recently began working on a basic Angular app that is meant to be very simple. For this project, I am only using the angular files and a single html file as the foundation. As I started setting up the bas ...

create the text with double bold - adjusted pages

Is there a method to enhance the boldness of the text without adjusting the font size? Currently, the following styling is applied: numbers: { fontSize: 30, color: '#31C283', fontWeight: 'bold', }, Is there a way to m ...