input:hover {
/* do something */
}
input:error {
/* do something */
}
That’s CSS, which is what I think you’re copying (on purpose or inadvertently).
I would need to see more of your code, but this isn’t a good API:
<Input type="hover error" />
For several reasons.
Firstly, they aren’t types of input: an input that is hovered is not a kind of input, it’s the same input in a hover state. Same with error. The naming is confusing: these are states, not types.
Edit: just to clarify why it doesn’t make sense. Inputs already have types. Look:
<input type="text" />
<input type="email" />
So you can’t have a type
of error, or hover, it doesn’t make sense
Secondly, how are you handling hover
? If you are handling it in React, that means you need a reference (ref
) to the element so that you can check whether it’s in a hover state. CSS handles this just fine, handling it in JS isn’t ideal. Error states are a little different – there are good reasons for handling that in JS, it gives you a little bit more control, but from a styling perspective, CSS also handles that just fine.
Thirdly, you’re using a single string. So now you need to write logic to convert the state of the input to a set of space-separated strings, then to convert from a set of space-separated strings to the logic. This is less of an issue if you use an array, but it’s still an issue. It’s complicated and error-prone, for no good reason.
So something like
<Input isHovered={true} hasError={false} />
Or
{/* has no error message, don't show as being in error: */}
<Input isHovered={true} error="" />
{/* has error message, show as being in error: */}
<Input isHovered={false} error="I am an error message" />
Would be much saner (again, having to write logic to check whether an element is hovered, particularly one that normally has no hover state, is IMO crackers, but if you feel it’s necessary, go for it).