I have a React component that looks like this
export const SearchBar = ({
searchInput,
updateSearchKeyword,
}: SearchBarProps) => {
const dummy = "";
return (
<div className={`${styles.container} `}>
<input
className={`${styles["search-bar"]} `}
type={"text"}
value={dummy}
title="search"
placeholder="Search..."
onChange={(e) => updateSearchKeyword(e.target.value)}
/>
</div>
);
};
Now, I want to apply CSS changes when the input field has text. My CSS code is as follows
.search-bar:valid {
color: red;
}
But the color is always red, meaning the input is always considered 'valid'
I have tried
.search-bar[type="text"]:valid {
color: red;
}
and also added a pattern
in the component, but the issue persists. How can I resolve this?
Note: I am using modules.css
, so the class names may appear unusual, but they are functioning correctly for other properties.