Skip to content

[0.5] Generate focus variants last and group-hover variants first #417

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 12, 2018

Conversation

adamwathan
Copy link
Member

@adamwathan adamwathan commented Mar 12, 2018

Resolves #392.

This PR changes the order in which state variants are generated to be more intuitive.

Prior to this PR, variants were generated in this order:

  1. Focus
  2. Hover
  3. Group Hover

That means if an element had both hover and focus styles applied to the same property, the hover styles would win if the element was hovered and focused simultaneously:

<!-- This button will be green if hovered and focused -->
<button class="bg-blue focus:bg-red hover:bg-green">Click</button>

While this feels right for buttons, it feels wrong for inputs, where a focus style feels like it should take precedence over a hover style:

weird-input-hover

Choosing either option here has trade-offs, but I'm convinced that having focus styles trump hover styles is a better trade-off for two reasons:

  1. Even though for non-input elements it feels more correct for hover to trump focus, it is very uncommon for focus and hover to both target the same property on those elements, so in practice it doesn't actually matter. I've never given a button a default background color, a focus background color, and a hover background color. Any focus styles I apply to buttons are usually changing the outline color or border.

  2. The only elements where it is reasonably common to target the same property on both hover and focus are input elements, so since that situation actually happens, it makes sense to optimize for it.

This PR also moves group-hover to the beginning, giving it the lowest precedence whereas previously it had the highest precedence. That means that now, if a button is inside a div and has a group hover background color and a regular hover background color, hovering the button will apply the hover background instead of the group hover background.

@adamwathan adamwathan changed the base branch from master to 0.5 March 12, 2018 19:34
@adamwathan adamwathan merged commit fa0e06c into 0.5 Mar 12, 2018
@adamwathan adamwathan deleted the change-variant-order branch May 30, 2018 15:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant