Color alteration of button triggered upon modal closure

I'm currently developing a website and have implemented a modal that appears as follows:

import React,{useState} from "react";
import './AddItem.css';
import { Form, Button,Modal } from "react-bootstrap";

function AddItem({open, setOpen})
{
  const [show, setShow] = useState(false);
  const handleClose = () => setShow(false);
  const handleShow = () => setShow(true);
    return(
      <>
      <Button className="add" onClick={handleShow}>
           ADD
      </Button>

      <Modal show={show} onHide={handleClose}>
        <Modal.Header closeButton>
          <Modal.Title>Modal heading</Modal.Title>
        </Modal.Header>
        <Modal.Body>
          <Form>
            <Form.Group className="mb-3" controlId="exampleForm.ControlInput1">
              <Form.Label>Email address</Form.Label>
              <Form.Control
                type="email"
                placeholder="<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="721c131f1732170a13d1d21d">[email protected]</a>"
                autoFocus
              />
            </Form.Group>
            <Form.Group
              className="mb-3"
              controlId="exampleForm.ControlTextarea1"
            >
              <Form.Label>Example textarea</Form.Label>
              <Form.Control as="textarea" rows={3} />
            </Form.Group>
          </Form>
        </Modal.Body>
        <Modal.Footer>
          <Button variant="secondary" onClick={handleClose}>
            Close
          </Button>
          <Button variant="primary" onClick={handleClose}>
            Save Changes
          </Button>
        </Modal.Footer>
      </Modal>
    </>
  );
}

export default AddItem;

https://i.sstatic.net/BbPUh.png

After clicking on "Save Changes" or closing the modal in any way, the add button in the image (which was clicked to open the modal) changes to an undesired color-

https://i.sstatic.net/qtcZt.png

The color returns to normal only when I click elsewhere on the screen.

How can I prevent this from happening? Here's my Additem.css file:

.add{
    position: absolute;
    top: 21.35%;
    left: 61%;
    height: 6%;
    width: 10%;
    color: white;
    background-color: #283d4a;
    border-left: 1.5px solid #15aef1;
    border-right: 1.5px solid #15aef1;
    border-top: 2.7px solid #15aef1;
    border-bottom: 2.7px solid #15aef1;
    border-top-left-radius: 5px !important;
    border-bottom-left-radius: 5px !important;
  }
  .add:hover{
    background-color:#15aef1 ;
  }

Answer №1

The issue with the color lies in the Bootstrap button, as it has a tendency to revert back to a default color. By using a standard button like:

#React Button

<button className="add" onClick={handleShow}>
           ADD
</button>

instead of

#Bootstrap button

<Button className="add" onClick={handleShow}>
           ADD
</Button>

this problem can be effectively resolved.

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

Setting Up Background Colors in Angular 4

I'm attempting to create a background color that fills the entire page. I've set it in the body tag, but when I add background-color: blue, it doesn't cover the whole background as intended. Instead, it only fills the background of the eleme ...

Tips for effectively applying an image as a border

Just starting out with HTML and CSS here, and I'm trying to figure out how to use an image as a border for a div element. Can someone help point out my mistake? div { width: 240px; height: 510px; background-color: lightblue; border-image ...

A step-by-step guide to creating an interactive Rubik's Cube using THREE JS and loading custom images onto each individual

I am facing a challenge with developing a 5x5 Rubik's Cube. The cube has six faces, which means I need to display 25 images on each small box of each face, totaling 150 images for the entire 5x5 cube. Although the Rubik's Cube itself is displayed ...

Offspring component fails to reverse the skew as intended

Is it possible to skew a navigation bar without affecting the text inside it? I tried skewing the main div of the navigation bar and using a negative skew value on the text, but it didn't work as expected. How can I achieve this effect successfully? ...

Is there a way to enlarge the icon when I hover over the text using framer motion combined with material ui?

Whenever I try to hover over the text, it only scales the icon. It doesn't seem to work when I attempt to hover over it. <ListItem sx={{ fontSize: '14px' }}> <motion.div style={{ display: 'flex', alignItems: 'cent ...

Get the child element from a list within an element using XPath on Sales Navigator

I am attempting to extract the names and positions of random individuals from Sales Navigator. Each person is displayed as a card containing all their information. Despite obtaining a list of these cards, I am struggling to retrieve the Name and Title for ...

Poor mapping on Google Maps API

I've been trying to embed a Google Maps on my website, but for some reason, it keeps stretching and showing grey sections with rounded borders. Here's the code I'm using: <div class="p-5 col-6 d-flex flex-column justify-content-between"& ...

Incorporate a glyphicon into a webpage design that wasn't originally built with bootstrap while maintaining the original layout

Looking to jazz up my vintage website with some cool glyphicons on a specific page. Don't want to mess up the entire look of my site by installing bootstrap. Is there a way to add just the "glyphicons functionality" without changing everything else? ...

What are the Functions of Ctrl-K on Stack Overflow?

I'm intrigued by how to incorporate the Ctrl+K (code sample) feature for code. For example: public static void main(String args[]){ System.out.println.out("welcome"); } Is there a way to nicely format this? Do we need any specific package to ...

accept string arguments using jQuery

When passing two parameters to a function in jQuery and PHP, I encounter an issue. One parameter is a number (referred to as $row ["inv_id"]) and the other is a string ($status = "Close"). $ inv_actions= <a onClick="invoiceStatusChange('.$row["inv ...

Arrange children of varying heights in a line

Wondering if it's feasible to design a flexbox layout with wrapping children while aligning them to the top? .container { display: flex; flex-wrap: wrap; justify-content: space-between; } .container .element { flex: 0 0 auto; } This piece o ...

Incorporate a caret into an element using CSS styling

issue I encountered an issue where <textarea> and Javascript had some quirks when trying to transfer the value into a <pre> tag. My aim was to implement a blinking caret in the <pre> as if I were pressing F7. The reason behind not using ...

How can I implement zoom functionality using a button click in React Leaflet version 4.2.0?

**Is it possible to add a button next to the map in React-Leaflet that allows me to change the zoom level of the map with a click? For example, imagine I have a map displaying a country at zoom level 7. Above the map, there are buttons for different citie ...

The administrator user assigns a user value in the authentication context, but that value remains hidden from the component where it was originally set

The authentication feature: import React, { useState } from 'react'; let selectedUserByAdmin = ''; const AuthContext = React.createContext({ setSelectedUserByAdmin: () => {}, selectedUserByAdmin, }); export const AuthContextPro ...

What could be causing React to reject my handleChange function?

I'm currently attempting a basic form task to familiarize myself with React Forms, but I'm struggling to grasp the syntax. When I use the code below, everything functions smoothly: import React, { useState } from "react"; function Inp ...

Having trouble with react-bootstrap Navbar not displaying correctly in React JS?

I am currently working with ReactJS and Bootstrap 4. I am using the react-bootstrap module to render the Navbar, but I am encountering issues with the rendering. I suspect that there may be a conflict between Bootstrap 4 syntax and another Bootstrap 3 synt ...

Ways to retrieve information when text is modified and a dropdown is selected within an input field

I have an input field with a text box and a dropdown. My goal is to trigger data based on text changes in one method, while using another method for the dropdown. Check out the code below. const allList = [ { id: "1", value: "Fruits" ...

Converting non www to www in React.js

I want to redirect users from http://example.com to http://www.example.com. If I'm using nginx + php, I can achieve this with the following configuration: server { listen 80; server_name example.com; return 301 http://www.example.com$req ...

Tips for achieving a material ui standard look for Texfiled without using outlines

Is it possible to change the styling of react-select from outline to standard when using the material-ui TextField Select The current style of react-select: https://i.sstatic.net/H9KWH.png The desired style: https://i.sstatic.net/Yeelp.png Any sugges ...

checkbox inspired by the design of the iPhone

I'm looking to create a custom checkbox! <label id="sliderLabel"> <input type="checkbox" /> <span id="slider"> <span id="sliderOn">SELECTED</span> <span id="sliderOff">SELECT</span> ...