I am working on a site, and i have a modal which basically looks like this:
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="name#example.com"
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;
When i click on save changes, or close the modal in any way, the add button in the picture,(which i clicked to open the modal) turns un undesirable color-
The color only reverts back to normal when i click anywhere else on the screen.
How do i prevent this from occuring? 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 ;
}
The color problem lies with bootstrap button. It has a property of rolling back to a color. Using a regular button like:
#React Button
<button className="add" onClick={handleShow}>
ADD
</button>
instead of
#Bootstrap button
<Button className="add" onClick={handleShow}>
ADD
</Button>
is effective in solving this.
Related
I've 2 controllable text input with validation:
required={true}
minLength={5}
maxLength={10}
Both are share the same state, so their text are always in sync.
value={text}
onChange={(e) => setText(e.target.value)}
The initial value of them are 'ab':
const [text, setText] = useState("ab");
Then I added a css for visualizing the validation state:
input[type="text"]:valid {
background-color: lightgreen !important;
}
input[type="text"]:invalid {
background-color: pink !important;
}
The problem:
At the first load, both color are green.
The value are 'ab' it doesn't satisfy the validation.
Why not colored red?
When i added one character of the first textbox => abc
The color is red, that's to be expected.
But the second one still colored green. That's not expected.
Anyone can fix the problem? I want the text & validation are in sync.
Sandbox: enter link description here
code:
import "./styles.css";
import { useState } from "react";
import "./App.css";
export default function App() {
const [text, setText] = useState("ab");
return (
<div className="App">
<input
type="text"
required={true}
minLength={5}
maxLength={10}
value={text}
onChange={(e) => setText(e.target.value)}
/>
<br />
<input
type="text"
required={true}
minLength={5}
maxLength={10}
value={text}
onChange={(e) => setText(e.target.value)}
/>
</div>
);
}
css:
input[type="text"]:valid {
background-color: lightgreen !important;
}
input[type="text"]:invalid {
background-color: pink !important;
}
To be completely honest, I don't know why React is behaving this way, but an alternative would be to add a 'valid' or 'invalid' class to the input depending on the 'text' value:
<input
className={text.length >= 5 && text.length <= 10 ? 'valid' : 'invalid'}
type="text"
required={true}
value={text}
onChange={(e) => setText(e.target.value)}
/>
.valid {
background-color: lightgreen !important;
}
.invalid {
background-color: pink !important;
}
I am trying to change button 2 to finger pointer after clicking button 1
so i am wondering is there a way to do it if there is please tell me what code do i write
Note:button 1 is already a finger pointer i want button 2 to be a finger pointer after clicking button 1
this is my code:
<input type="button" id="button1" type="submit" style="cursor: pointer; background-color:black;height: 45px; width: 150px; color:red;border-radius:10px;"value="first button" onclick="enableButton2()" />
<input type="button" id="button2" style="background-color:yellow; height: 45px;width: 225px;color:red;border-radius:10px;"value="second button" disabled />
use it :
<script>
function enableButton2(){
var btn2 = document.getElementById('button2');
btn2.setAttribute('disabled', false)
btn2.style.cursor = 'pointer'
}
</script>
<input type="button" id="button1" type="submit" style="cursor: pointer; background-color:black;height: 45px; width: 150px; color:red;border-radius:10px;" value="first button" onclick="enableButton2()" />
<input type="button" id="button2" style="background-color:yellow; height: 45px;width: 225px;color:red;border-radius:10px;" value="second button" disabled="true" />
this way:
the css style you are looking for is cursor : not-allowed;
const bt_1 = document.getElementById('button1')
, bt_2 = document.getElementById('button2')
;
bt_1.onclick = () =>
{
bt_2.disabled = false
}
button {
cursor : pointer;
height : 45px;
border-radius : 10px;
color : red;
}
button[disabled] {
cursor : not-allowed;
pointer-events : none;
color : #c0c0c0;
background-color : #ffffff !important;
}
#button1 {
background-color : black;
width : 150px;
}
#button2 {
background-color : yellow;
width : 225px;
}
<button id="button1" type="submit" > first button </button>
<button id="button2" disabled > second button </button>
I am trying to add checkboxes to a login page using code that I found at react-bootstrap.github.io
The problem I'm having is the checkbox is overlapping the label.
My code (register.js) is below
import React, { useState } from 'react'
import { Link } from 'react-router-dom';
import { request } from './services/Request';
import { Button, FormGroup, FormControl, FormLabel, FormCheck } from 'react-bootstrap';
//import { FormRow } from 'react-bootstrap/Form';
import "./Styles/register.css"
export const Register = () => {
return (
<div style={{display: "flex", justifyContent: "center"}}>
<h1> Register </h1>
<div className="Register">
<form onSubmit={handleSubmit}>
</FormGroup>
<FormGroup controlId="email" bsSize="large">
<FormLabel>Email</FormLabel>
<FormControl
required
autoFocus
type="email"
//value={email}
onChange={ onChangeHandlerFn }
/>
</FormGroup>
<FormGroup controlId="password" bsSize="large">
<FormLabel>Password</FormLabel>
<FormControl
required
autoFocus
type="password"
//value={password}
onChange={ onChangeHandlerFn }
/>
</FormGroup>
<FormGroup controlId="password" bsSize="large">
{['checkbox'].map((type) => (
<div key={`default-${type}`} className="mb-3">
<FormCheck
type={type}
id={`default-${type}`}
label={`I am an individual`}
/>
</div>
))}
<Button variant="primary" type="submit" block>Register</Button>
<span>
Have an account?
Sign in
</span>
<ul>
<li><Link to="/privacy">Privacy & Terms</Link></li>
</ul>
</form>
</div>
</div>
);
};
The problem is the checkboxes are overlapping their labels:
Here is my css:
#media all and (min-width: 480px) {
.Register {
padding: 60px 0;
}
.Register form {
margin: 0 auto;
max-width: 320px;
}
}
ul {
list-style-type: none !important;
margin: 0;
padding: 0;
overflow: hidden;
}
Everything works, for the sake of length, I've done post all of the code.
Any help would be greatly appreciated.
What about adding to the left padding of the label so it clears the checkbox?
label {
padding-left:15px;
}
I would hide a buttons except the last one . But when I put mouse over prevous elements, they get displayed.
Here's my html
<p-growl [(value)]="msgs"></p-growl>
<div class="center" appMcard>
<h2> Select Group (s) name(s) </h2>
<form [formGroup]="GroupRMPM_FG" class="form">
<div formArrayName="GroupId_Name" *ngFor="let control of GroupRMPM_FG.controls.GroupId_Name.controls; let i= index" >
<input type="text" pInputText [formControl]="control.controls.Group_Id_Name"/>
<button pButton type="button" class="delete-btn " *ngIf="GroupRMPM_FG.controls.GroupId_Name.controls.length > 1" (click)="deleteGroup(i)" icon="fa-minus" >
</button>
<button *ngIf="GroupRMPM_FG.controls.GroupId_Name.controls.length == i+1" pButton type="button" (click)="addNewGroup()" icon="fa-plus" class="add-btn formcontainer"></button>
<button *ngIf="GroupRMPM_FG.controls.GroupId_Name.controls.length != i+1" pButton type="button" class="dummyElement" icon="fa-plus" ></button>
<button *ngIf="GroupRMPM_FG.controls.GroupId_Name.controls.length == 1" pButton type="button" class="dummyElement" icon="fa-plus" ></button>
</div>
</form>
<div>
I have created a "dummy element" so that the content is centred in the right way when I get only a "plus" icon .
Here's the CSS:
.dummyElement, .dummyElement:hover{
background-color:transparent;
border-color: transparent;
cursor:none;
color: transparent;
}
Here's what I get
Also the cursor is disappearing when I'm over the button.
In my Browser dev tool show me this :
For information I use primeNg Button.
Please use pointer-events: none; instead of cursor:none as below;
.dummyElement, .dummyElement:hover{
background-color:transparent;
border-color: transparent;
pointer-events: none;
color: transparent !important;
}
It seems like your CSS is overwritten by another CSS rule. Try to add !important to your CSS:
.dummyElement, .dummyElement:hover{
background-color:transparent;
border-color: transparent;
cursor:none;
color: transparent !important;
}
is there any way to Style the Title inside The Tag?
i mean for an example :
<input type= "submit" id="submit" title= "submit your form">
i want to know is it possible to style this title inside the input tag?
No. But you may try some trick with it.
$(document).ready(function(){
var old_title;
$('.title-styled').on('mouseover', function(){
old_title = $(this).attr('title');
$('.title-message').html($(this).attr('title')).css('visibility', 'visible');
$(this).attr('title', '');
});
$('.title-styled').on('mouseleave', function(){
$(this).attr('title', old_title);
$('.title-message').html('').css('visibility', 'hidden');
});
});
.title-message{
visibility: hidden;
padding: 10px;
border: solid 1px #f9f9f9;
box-shadow: 3px 3px 3px #1a1a1a;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input type= "submit" id="submit" class="title-styled" title= "submit your form">
<span class="title-message"></span>
Other option:
If you want to use a jQuery plugins, visit this link.