Skip to content

Best practices to handle :hover styles of children elements #2386

Answered by gamegee
gamegee asked this question in Q&A
Discussion options

You must be logged in to vote

I found a way to do this using _groupHover:

export type ButtonProps = BoxProps & {
  label: string
  iconName: string
  type: 'primary' | 'secondary'
}

export const Button: FC<ButtonProps> = ({ label, iconName, type }) => {
  const color = 'primary' ? 'blue' : 'gray'

  return (
    <PseudoBox
      role="group"
    >
      <Icon name={iconName} color={color} _groupHover={{color: 'red' }} />
      <Text color={color} _groupHover={{color: 'yellow' }}>{label}</Text>
    </PseudoBox>
  )
}

Replies: 4 comments 3 replies

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
3 replies
@ahmadrio
Comment options

@BrunoQuaresma
Comment options

@ehynds
Comment options

Answer selected by with-heart
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
6 participants