There is a input with type number where the user can write a number. If the number is greater than 4 it will change the color of the input border to red.
I want to show the tooltip in the same situation, not on hover. Is it a way to do that?
<div className="tooltip">
<input
className="partial-quantity-input"
type="number"
min="0"
max="4"
value={quantity}
onChange={changeValue}
/>
<span className="tooltiptext">Exceeds original ordered quantity.</span>
</div>
css:
.partial-quantity-input {
background: rgb(255, 255, 255);
border-radius: 0px;
border: 1px solid rgb(255, 255, 255);
height: 40px;
width: 40px;
outline: none;
&:focus {
border: 1px solid rgb(201, 200, 200);
}
}
input::-webkit-outer-spin-button,
input::-webkit-inner-spin-button {
-webkit-appearance: none;
margin: 0;
}
input[type='number'] {
-moz-appearance: textfield;
}
input:invalid {
outline: none;
border: 1px solid red;
}
.tooltip {
position: relative;
display: inline-block;
}
.tooltip .tooltiptext {
visibility: hidden;
bottom: 100%;
left: 50%;
margin-left: -60px;
width: 120px;
color: rgb(0, 0, 0);
text-align: center;
padding: 5px 0;
background: rgb(255, 255, 255);
border-radius: 3px;
border: 1px solid rgb(220, 220, 220);
height: 38px;
width: 252px;
/* Position the tooltip */
position: absolute;
z-index: 1;
}
.tooltip:hover .tooltiptext {
visibility: visible;
}
as it is in the code, it shows the tooltip on hover (.tooltip:hover).
I tried .tooltip:invalid or .tooltip(input:invalid) but did not work.
Any ideas?