Unable to input text into text fields or interact with buttons by clicking or hovering in a React form

I am new to React and currently working on a login page that asks for both a username and password. While I haven't implemented much logic yet, I have been exploring online resources to learn more. It appears that I should be able to interact with the text fields by clicking on them or hover over the sign-in button to see some changes.

Currently, I have added CSS for hover effects but I have to manually trigger it using Google DevTools to see any changes. I would greatly appreciate some assistance with this issue. Below is the code snippet:

export default class Login extends React.Component {
    render() {
            return (
                    <form>

                            <SmallHeading name="USERNAME:"/>
                            <input className="inputField" type="text" placeholder="Enter username"/>

                            <div className="space"></div>

                            <SmallHeading name="PASSWORD:"/>
                            <input className="inputField" type="text" placeholder="Enter password"/>

                            <div id="buttonWrapper">
                                    <input type="submit" className="btn buttonFont buttonStyle" id="logInButton" value="LOG IN" />
                            </div>
                    </form>
            );
    }
}

Answer №1

Easy sign-in form

class SignIn extends Component {
  state={
    email:'', password:''
  }
  onChange=e=>{
    let val = e.target.value
    this.setState({[e.target.name]:val})
  }
  handleSubmit=e=>{
    e.preventDefault();
    const {email} = this.state;
    alert(email)
  }
  render() {
    console.log(this.state)
    return (
      <form onSubmit={this.handleSubmit}>
       <label>Email</label>
        <input
          className="username"
          name='email'
          type="text"
          placeholder="Enter email"
          onChange={this.onChange}
        />
        <label>Password</label>
        <input
          className="password"
          name='password'
          type="text"
          placeholder="Enter password"
          onChange={this.onChange}
        />
        <div id="buttonWrapper">
          <input
            type="submit"
            className="btn buttonFont buttonStyle"
            id="logInButton"
            value="LOG IN"
          />
        </div>
      </form>
    );
  }
}

CSS Styles

input[type=text]{ 
        width: 100%; 
        padding: 12px 20px; 
        margin: 8px 0; 
        display: inline-block; 
        border: 1px solid #ccc; 
        box-sizing: border-box; 
    } 
input[type=submit] { 
      background-color: #4CAF50; 
      color: white; 
      padding: 14px 20px; 
      margin: 8px 0; 
      border: none; 
      cursor: pointer; 
      width: 100%; 
  } 

Answer №2

How to Add Hover Effect to a Button

input[type=submit]:hover{
  color: red
}

Alternatively, for the wrapper element:

#buttonWrapper:hover{
  color: red
}

I hope this is helpful!
Check out this sample

Answer №3

It finally clicked for me - I made a silly error on my part. Upon conducting more troubleshooting, I identified that the issue stemmed from the CSS of the container div where the form is placed. I mistakenly assigned a z-index of -1, causing interference.

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

Creating a default option in a Select tag with React when iterating over elements using the map method

After learning that each element in the dropdown must be given by the Option tag when using Select, I created an array of values for the dropdown: a = ['hai','hello','what'] To optimize my code, I wrote it in the following ...

When using NextJS <Link, mobile users may need to tap twice to navigate

Whenever I use the NextJS <Link tag on my mobile device, I notice that I have to double-tap for the link to actually route to the desired page. Take a look at the code snippet below: <Link href="/methodology" passHref={true} ...

"Enhancing Collaboration with NextJs Multi-Zones' Unified Header

Currently, I have two applications named admin-shell and delivery-management, both of which are being managed using Multi Zones in NextJs. These applications share a common header with navigation links, but I am encountering difficulties navigating betwee ...

I need help with customizing the progress bar in HTML and CSS

How can I create a progress bar like the one shown below: https://i.sstatic.net/BFv87.png .detail-load { height: 42px; border: 1px solid #A2B2C5; padding: 1px; border-radius: 10px; } .detail-load > .detail-loading { ...

Setting the useState hook to a User type in React - the ultimate guide!

As someone new to hooks, I'm unsure about what the initial value for useState should be set to. Currently, an empty object is set as the default value for useState with const [user, setUser] = useState({}); This is causing ${crafter.id} to throw an e ...

Continue extending the footer as the screen size decreases

Could anyone offer some assistance? I'm currently working on a project and facing issues with getting the footer to always be pushed down as the screen size decreases. As of now, my content is going under the footer instead. Any help would be greatly ...

Instructions on obtaining a distinct daily array from the weather API array that provides a detailed 5-day weather report every 3 hours

Seeking assistance with my weather app development on React using axios with the openweathermap.org API. Currently stuck on getting data formatted in a specific way from the 5-day forecast it provides, totaling 40 reports over the 5 days. The API response ...

The background-image property fails to display on a table element

I’m having trouble displaying a background image in a table within my Django app. Here’s the code I’m using: <table style="background-image: url('/static/assets/img/myimage.png') ;background-position: 0 100% !important;background-repeat ...

Using the same button to navigate to a different page in react-router-dom and sending data from a form that contains necessary attributes on form.Control

I am currently working on a project using React Bootstrap forms and React Router DOM. I have encountered an issue where the same button is responsible for both redirecting to another page and submitting data. My goal is to have the form check if all requir ...

"Enhance your React application with react-router-dom by including parameters in the index URL while also

Here is the code I am currently using: <Router history={history}> <div> <Route exact path="/:id?" component={Container1} /> <Route path="/component2/ component={Container2} /> </div> </Router> When accessin ...

Issues arise when attempting to use Stylus in conjunction with React

I am currently working on developing a web application that utilizes Stylus and React. I have successfully rewritten all the Stylus language files, but I am encountering an issue where the React components are not being styled as expected. Below is one of ...

Ways to retrieve headers from server-side rendered (SSR) response in Next.js

I am currently developing a web application using getServerSideProps in Next.js. I have successfully set an authorization token in the header within the getServerSideProps function, but now I am facing challenges retrieving this token from the header. Her ...

Difficulty achieving gradient effect with partial background color change in table-cell

In order to achieve a unique look for this particular design, I am seeking ways to alter the red background color of each cell in varying degrees - such as 100% for the first cell, 100% for the second cell, and 50% for the third cell. Update: After experi ...

Find all strings in the array that do not begin with a letter from the alphabet

When a specific button is clicked, I need to filter the example array provided in the snippet below. The expected output should only include elements that do not start with an alphabet. I attempted: const example = ["test", 'xyz', '1 test& ...

Ensure the placeholder remains front and center, growing in size as it moves vertically

.inpsearch{ border:2px solid #bbb; border-radius:14px; height:29px; padding:0 9px; } .inpsearch::-webkit-input-placeholder { color: #ccc; font-family:arial; font-size:20px; } <input type='search' class='inpsea ...

Storing multiple email addresses in an array using an HTML input element

I have a small React Bootstrap form where I am trying to save multiple email addresses entered by the user into an array. However, when I use onChange={()=> setEmails(e.target.value as any} it stores them in string format like this --> [email p ...

Tips for keeping a dynamic height div in place without affecting surrounding elements

HTML: <div id="autocomplete" hidden></div> <input type = "button" id = "search" value = "Search"> The autocomplete div contains dynamically generated input tags created by jQuery. These input tags cause the button to be shifted down the ...

Parent: Using Flexbox vs Child: Choosing between inline-block or inline elements (Advantages of utilizing CSS3 flexbox?)

I've been exploring the capabilities of CSS3's new "display: flex" property and trying to determine its advantages. So far, I haven't discovered any significant benefits beyond creating a virtual horizontal line within each flex box containe ...

Having trouble accessing env variables from React Component in Next.js?

I recently set up a Next.js project and included an .env file to store environment variables used in my server.js file. However, I am facing an issue when trying to access these variables from a component. Can anyone provide guidance on how to resolve this ...

Display of certain special characters such as ">" may be affected when using UTF-8 encoding

Here are the codes I'm working with: ul.pathnav a:before{ content:"\0X3E"; text-decoration:none; } I have been trying to use the hex code \0x3e for ">", but it doesn't seem to be working. However, when I tried usi ...