I’m building an interactive component and have defined 4 variants: default, hovered, pressed, and selected. However, I’m unable to properly switch between them to create a truly interactive component.
Example:
I hover on default and it changes to hovered.
I press on hovered and it changes to pressed However when I release pressed I’m not sure how to change to selected. Tried having onClick from hovered to no avail, there’s no onRelease state.
Additionally noticing this is a problem when a component with a default and selected state share a hover state - how does the system know which is on or off to switch to when hovered?
PS Not sure if the mouse leave events are actually necessary, Figma may remove the mouse down if you move outside the component anyway. Again haven’t built this yet
Have a look here, secondary button (a bit messy but should still make sense): Figma
My diagram, but with a few learnings:
mouse up from pressed needs to go to selected+hover rather than selected, otherwise you get a little flash of selected and then the the hover kicks in (same thing applies from selected+pressed to default, should instead go to hover)
if you hold down the mouse button and then move off the component, it stays stuck in the pressed state, with or without the mouse leave also present. Minor “bug”? I’m not sure. Resets as soon as you hover again anyway.