Skip to content

Consider a standardized way to modify hover/focus/active states for blocks #27075

Closed

Description

@kjellr

Gutenberg should consider adding a way for users (and/or theme developers) to modify hover and active states. This would ideally be available in the UI on a per-block level, and also a part of global styles. This feature would be particularly useful for link styles and also for buttons.

Related to #4543

Activity

  1. added
    [Type] Enhancement
    [Feature] Themes
    Global Styles
    on Nov 18, 2020
  2. karmatosed commented on Nov 27, 2020

    @karmatosed
    Member

    I would love to see more consistency in the way hover/focus/active states behave themselves, which to me leads to a more consistent way for them to be styled. I have been working on an example to refine the gallery block borders (#27312), which overlapped. Even a small change like that was a bit of a tangled thread to follow due to the nature of the block. Which makes me feel this is an opportunity to refine and standardize.

  3. MaggieCabrera commented on Jan 27, 2021

    @MaggieCabrera
    Contributor

    I've been working on Seedlet's button hover states and I feel like the solution that I found shouldn't have to be replicated for every theme that is ever developed. Even if it's never surfaced to the user the ability to change the hover color/background should be handled by the editor to some capacity. In particular when the color is one that is selected by the user and not one provided by the theme.

    For the particular case, I was considering that we could either play with the opacity of the background color (using rgba) or play with the lightness (using hsl). Could this be done directly within the editor? As it stands, a custom colored button doesn't have any hover state.

  4. carolinan commented on Feb 7, 2021

    @carolinan
    Contributor

    Changing the color alone is not enough to indicate that the state of the link (button block) has changed,
    unless the color contrast ratio between the two colors is significant. What the minimum contrast ratio is also depends on factors like the font size. https://developer.wordpress.org/coding-standards/wordpress-coding-standards/accessibility/#color-contrast

    If there is a hover color option exposed to users, it may need to be a selection of suggested accessible colors, based on the current button color(s), and refreshed if the user changes the button color.

  5. Tropicalista commented on Mar 22, 2021

    @Tropicalista

    I added recently an issue: #30068

    I suppose that hover is not integrated yet because there's no way to add pseudo class on inline style. A different approach to add custom hover effect should be proposed.

  6. moved this to Not Started in Design Tools Projecton Nov 2, 2021
  7. getdave commented on Jan 31, 2022

    @getdave
    Contributor

    I'm going to add this for discussion in the Core Editor chat. It's something we are going to need for the Navigation block.

  8. aurooba commented on Feb 2, 2022

    @aurooba
    Member

    So I think one of the considerations is what changes with each state. A state change isn't just a change of color or text-decoration, in CSS speak. It could be multiple things.

    I would suggest that for each state, all currently supported properties remain available, so if the block supports background color, margin, padding, and letter case, then you should be able to control each of those per state. This will likely need some CSS adjustments, but should be pretty achievable with CSS variables.

  9. joyously commented on Feb 2, 2022

    @joyously

    I would suggest that for each state, all currently supported properties remain available, so if the block supports background color, margin, padding, and letter case, then you should be able to control each of those per state.

    I disagree because of what can happen when hover changes the size of an element. It has been seen before in the editor that just hovering creates a scrollbar or other size change, which then moves the element so it's no longer hovered, so it changes size again. This creates a flickering of the element that can cause seizures. Even a little movement is annoying.

    I don't think the editor should support the hover, active, focus, visited except on links. If it's standardized, the correct order is maintained. Be aware that visited can only affect color, though. I'm in favor of leaving it to the theme, not the user.

  10. aurooba commented on Feb 2, 2022

    @aurooba
    Member

    It has been seen before in the editor that just hovering creates a scrollbar or other size change, which then moves the element so it's no longer hovered, so it changes size again. This creates a flickering of the element that can cause seizures. Even a little movement is annoying.

    I think there would be value in considering when states show up. Something I love about Adobe XD for example is that, yes you can set a hover state for an element, but you have to toggle that state on in the interface to see what it will look like, instead of having it appear whenever you physically hover on the element. That's a better experience than what we have now, where if something has a hover state it activates in the editor on hover. Something like this would address the concern you are pointing out @joyously, which is absolutely valid.

    I don't think the editor should support the hover, active, focus, visited except on links.

    I don't think it makes sense to support states on everything. But I do think more than just links should support it. The blocks (off the top of my head) that I would love to see state support for are (aside from just links anywhere): buttons, social links, file, site title, and navigation.

  11. joyously commented on Feb 2, 2022

    @joyously

    That's a better experience than what we have now, where if something has a hover state it activates in the editor on hover. Something like this would address the concern you are pointing out

    That's not really what I meant. I was only referring to the front end result of whatever the user chose to change on hover. Their visitors could be faced with lots of issues that are avoided if controls are not provided to the user. That's why I think themes should handle it instead.

    The blocks (off the top of my head) that I would love to see state support for are (aside from just links anywhere): buttons, social links, file, navigation, site title, and navigation.

    Most of those are links (even navigation mentioned twice).

  12. aurooba commented on Feb 2, 2022

    @aurooba
    Member

    Right, but themes can do all kinds of things on the front-end as well (and I've seen plenty that to), ultimately what kind of styles/changes are made on hover or any other state is up to the people curating the design/look. I don't think that should stop the editor from providing flexible tools.

    And yes, most of the blocks I mentioned are links, but I'd like to see states available in them specifically, and not just link control on a global level. :)

    Edit: the reason I am advocating for this approach is because I believe this stuff should be in theme.json. And, correct me if I'm wrong, but if it's in the editor, then it'll also be in theme.json.

  13. 9 remaining items

  14. aurooba commented on Feb 11, 2022

    @aurooba
    Member

    I don't think the user should be involved, so there should be no UI for it, so the editor should not care what the theme does with those styles.

    I disagree. The option for the user to be involved should be there, with the ability for theme authors to disable user customization of this feature if they wish.

    That is how the Block Editor has operated since being merged into core, and long term, that is the best approach. Provide the most flexibility and add curation/locking/limiting options that theme authors can utilize (I want to emphasize that flexibility without the ability to curate/lock/limit is terrible, and features should be developed in tandem with their ability to be locked down). This is important because a very large part of the WordPress end user community are DIY-ers who often start with a theme and then customize on top of it. I'm not a DIYer, but even if I find this helpful when I'm working on personal projects and need to do modifications quickly.

  15. Luehrsen commented on Feb 11, 2022

    @Luehrsen
    Contributor

    Right, but this should really be handled by Gutenberg rather than every theme having to maintain their own version of this code.

    This implies that Gutenberg could handle every style a designer throws at a frontend developer. Considering Gutenberg competitors with a far superior scope (like Webflow, Squarespace, Wix), this is simply not the case. You will always be locked in by the capabilities of what the editor team deems worthy and would stifle innovation and creativity outside of what the team anticipated.

  16. paaljoachim commented on Feb 15, 2022

    @paaljoachim
    Contributor

    @critterverse Channing shared a link to @javierarce post here which is interesting to share into this issue: http://work.javierarce.com/2021/09/14/interaction-of-color/

  17. getdave commented on Feb 16, 2022

    @getdave
    Contributor

    Thank you for the varied opinions expressed here. It's really great to see this discussion evolving.

    For my part, I'd like to add that I don't see this as a binary choice.

    My opinion is that handling some basic interaction styles (such as color) would be appropriate for the editor to handle. Indeed, many users will likely want to be able to have some control over these most basic of design choices.

    That doesn't mean however, that Themes won't still be able to augment or override those settings via CSS to provide additional creativity. We could even have an option within theme.json to disable the ability to edit these interaction states.

    What we don't want is anyone to be "locked in" or for any creativity to be stifled. I hope what I'm suggesting above addresses at least some of those concerns.

  18. oandregal commented on Apr 22, 2022

    @oandregal
    Member

    Braindumping some thoughts regarding a particular detail we should address is how user choices affect states.

    A theme may want to set the blue color for the rest state and the yellow one for hover. Is the user sets the rest color to a yellowish base, is it still good to have yellow for hover? A related though is that different states may require any CSS property to update, like for example padding or margin, as in this use case. In this sense, states are more like "block style variations" than they are "style properties".

    One of the issues is that the theme lacks information about whether an user has styled anything. Or rather, there's no way for a theme to "maintain the design links" when the user edits something. I've shared a potential direction to explore.

  19. cbirdsong commented on Apr 25, 2022

    @cbirdsong

    A related though is that different states may require any CSS property to update, like for example padding or margin, as in this use case. In this sense, states are more like "block style variations" than they are "style properties".

    Updating properties that affect layout on hover/focus is generally considered a very bad idea. Would we really want to encourage that?

  20. getdave commented on May 26, 2022

    @getdave
    Contributor

    For anyone watching this Issue you might like to keep an eye on #38277 which is where design progress is being made on this problem.

  21. added
    [Status] In Progress
    on Jun 14, 2022
  22. removed
    [Status] In Progress
    on Aug 1, 2022
  23. talldan commented on Aug 1, 2022

    @talldan
    Contributor

    I'm not sure if this is still in progress, but the PR was closed so I've removed the assignment and In Progress label.

    For anyone watching this Issue you might like to keep an eye on #38277 which is where design progress is being made on this problem.

    @getdave From a triage point of view, what do you think about rewording the title and description of #38277? It seems like the conversation is no longer about the nav block, and it has become a duplicate of this issue. Potentially this issue could be closed or become an overview while #38277 becomes the design exploration.

    I also don't think we want separate issues for adding hover states to individual blocks because that would become unmanageable. I just closed #42829, but I think it's confusing for the reporter that I'm pointing them to an issue for the nav block.

  24. getdave commented on Aug 1, 2022

    @getdave
    Contributor

    I agree @talldan. Let's close this one in favour of #38277 which, for whatever reason, has become canonical.

    I'm not sure if this is still in progress, but the PR was closed so I've removed the assignment and In Progress label.

    It's still on my radar but I've switched focus to the Nav block for a while.

  25. Repository owner moved this from ⏱ Not Started to ✅ Done in Design Tools Projecton Aug 1, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Global Styles[Feature] Themes[Type] Enhancement

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions