gutenberg icon indicating copy to clipboard operation
gutenberg copied to clipboard

Standardized way to modify interactive states (:hover, :focus .etc) for blocks

Open getdave opened this issue 4 years ago • 93 comments

What problem does this address?

Currently it's not possible to modify the visual styles when the block items are in a given state (hover, focus, etc).

States (#57719) was designed as a solution that could work for this use case, including the hidden complexity that isn't immediately obvious. Consider a navigation menu, you'd want to be able to change colors of menu items in their neutral, hover, focused states. But most likely, you'd also want to be able to change their border, background, perhaps font-weight or text-decoration in those states.

Secondly there is the need to combine properties into new states. Consider the same navigation menu, menu items can have current states. E.g. when you navigate to /about, the "About" menu item should be highlighted as the current menu item. This state cannot inherit the hover and focus states from default menu items, you might have a blue hover color which wouldn't work if you added a black background:

State matrix

In other words, the state proposal suggests that "Hover" is one property that can make a state. "Current" and "Hover" properties together, make a new state.

The state design can solve both those complexities:

  • By having the selector relate to the block itself, it provides access to the whole inspector and all tools within, to customize a state.
  • By allowing you to combine properties to create a new state, the use case of allowing design of the hover state for the current menu item is handled.

Here are mockups that extrapolate on Saxon's work to test it for both a Button state, and a navigation "current menu item" state:

Button, i4 Nav item, i4

This could work as a starting point, and as the states concept gains features, it can be expanded upon.

Figma.

Issue updated May 7th.

Past version of this issue

Examples include:

  • hovered
  • focused
  • active

Update

We've iterated on this in #1786 and #41976.

A video overview is available.

After #41976, the next steps are:

  • [x] Fix https://github.com/WordPress/gutenberg/issues/42055
  • [ ] support :hover on link elements within **blocks** in Global Styles UI (currently only top level is supported).
  • [ ] implement the "disclosure" pattern from @javierarce's designs from https://github.com/WordPress/gutenberg/pull/41976#issuecomment-1170067066.
  • [ ] add support for :focus and :active states in the Global Styles UI for link.
  • [ ] Add color swatches for the first two "states" in the Global Styles element overview item (see https://github.com/WordPress/gutenberg/pull/41976#issuecomment-1170078408)
  • [ ] Enable setting Navigation block link color from global styles. Requires https://github.com/WordPress/gutenberg/pull/42092 to be resolved as Global Styles checks supports to decide whether to enable the panel.

What is your proposed solution?

Provide design tools that allow setting visual presentation for those states.

Likely these will be implemented as an editor-wide feature rather than something that's specific to the Nav block.

I will defer to @jasmussen and @javierarce for their thoughts on how this might happen.

Also pinging @jorgefilipecosta who may have some insight onto whether Global Styles intends to handle this in future.

getdave avatar Jan 27 '22 11:01 getdave

Also cc'ing @annezazu who suggested this idea.

getdave avatar Jan 27 '22 11:01 getdave

Definitely a good challenge. I wonder if we shouldn't zoom out from the navigation block, and look at this issue in more generic terms across all buttons and links. That would put the effort in global styles and design tools territory. One of the interesting challenges to tackle there, is building some confidence on exactly how we should support pseudo states. Do we need them all, or could we start with just hover/focus?

jasmussen avatar Jan 28 '22 08:01 jasmussen

Related: https://github.com/WordPress/gutenberg/issues/27075

MaggieCabrera avatar Jan 31 '22 09:01 MaggieCabrera

I think controlling these states from global styles makes sense and I agree with what @jasmussen said. But we need to be very careful how this is going to happen. It does not make sense to control states for a paragraph but maybe for the button block, it does? How do we specify which blocks this makes sense? I guess a block.json support? I guess for the link element it also makes sense so for some elements we are going to have states. We would need to have a design exploration on how we can expose this UI in an easy-to-use way covering both states for blocks and for elements like but not taking much space so the global styles UI is still clean.

jorgefilipecosta avatar Feb 01 '22 22:02 jorgefilipecosta

Thanks @jorgefilipecosta. I agree it needs to be carefully thought through. Block supports sounds like a good way to indicate whether a given block is suitable for interactive state design tools.

I wonder whether UX wise this could behave in a similar way to the how Devtools handles these states: Screen Shot 2022-02-02 at 09 12 21

@jasmussen are there any designers working (or planning to work) on this that you know of?

getdave avatar Feb 02 '22 09:02 getdave

block supports sounds like a good way to indicate whether a given block is suitable for interactive state design tools.

Just adding a +1 that this would be both a very cool feature, and it will also need to be thought through carefully, both in the UI design, and how we wish to store the styling state. Over in #38167 there is a project underway (the style engine) to explore how we might improve our saving/rendering of block styles (this come out of the discussion in https://github.com/WordPress/gutenberg/discussions/37495). There's an initial PR for how the style engine might work in #37978.

Aside from the UI, how might hover, focus, active states be represented in the style object, both at the block level and in global styles? Do we need the style object to support nested values, scoped by a list of states, or something like that? How do we ensure we reduce duplication of data so we're not storing too many sets of the same values across multiple states (e.g. if we want the hover, focus, and active states to all be the same colours).

If it's first explored as an individual block support, it'd be good to also get an idea of how it could be centralised in the style engine (and / or made easy to change after the fact).

andrewserong avatar Feb 03 '22 00:02 andrewserong

I think it makes sense to add this control to the theme.json before we build a UI for it. That gives us a chance to focus on the data structure and functionality and get that right without needing to think about the UI.

scruffian avatar Feb 03 '22 17:02 scruffian

are there any designers working (or planning to work) on this that you know of?

I responded partially in Slack then forgot to copy it here. Here's an expansion:

  • It’s always easier to start with less, and expand when the need arises. There are a ton of pseudo selectors, and not all will be useful. Some can possibly be combined, such as hover and active into one.
  • It needs some good design explorations that consider these states in a global styles context, so the interface can be the same for both buttons and navigation items, for example.
  • Consider that each state isn’t just a single property change. A focus state is usually underlined, but it could also be a border with a radius, bold text, or a combination.

It's likely necessary to start with a combination of visuals and pseudo code to figure out a structure that works, and is able to grow if we find the need for a bespoke :active state after all.

jasmussen avatar Feb 04 '22 08:02 jasmussen

The following a "rough" sketch made with Affinity Photo associated with the Button block settings and one for Global Styles. Meant to inspire. Example using Default, Hover and Visited states. Inspired by the Colors panel and the toggle between Solid and Gradient colors.

Buttons block

Buttons-block-Default-Hover-Visited-link-states

Global Styles

Global-Styles-Link-States

I removed the Links which is currently in the Elements section.

paaljoachim avatar Feb 04 '22 14:02 paaljoachim

  • Consider that each state isn’t just a single property change. A focus state is usually underlined, but it could also be a border with a radius, bold text, or a combination.

I want to emphasis this as it's important.


@paaljoachim Thank you for the exploration!

getdave avatar Feb 04 '22 15:02 getdave

Since this ticket is about the pseudo states which we need for menu items, buttons, and links, should we rename this ticket to reflect that? It can still be labelled for Navigation and be on that tracking issue, but it seems important to not design a nav-block only UI for this.

jasmussen avatar Mar 07 '22 07:03 jasmussen

Since this ticket is about the pseudo states which we need for menu items, buttons, and links, should we rename this ticket to reflect that? It can still be labelled for Navigation and be on that tracking issue, but it seems important to not design a nav-block only UI for this.

@jasmussen I think that's why we have https://github.com/WordPress/gutenberg/issues/27075. This Issue [i.e. 38277] specifically tracks this for the Nav block.

getdave avatar Mar 07 '22 10:03 getdave

Ah, gotcha. Just wanted to make sure that it's built in a reusable standardized way!

jasmussen avatar Mar 07 '22 11:03 jasmussen

I've updated the description with a note that we should implement as an editor wide feature and not specific to the Nav block.

getdave avatar Mar 07 '22 11:03 getdave

I think it's better to add the option for the hover state effect to the inspector controls. As it will allow users to make it more personalized.

HILAYTRIVEDI avatar Mar 24 '22 05:03 HILAYTRIVEDI

After some thinking, the approach that @paaljoachim proposed makes a lot of sense to me. I'd like to suggest some tweaks to that idea though:

Instead of using segment controls, I think we should go for a different interface. We use segments (or dropdowns, another possibility I explored), to set values… a tabbed list, on the other hand, immediately implies that the elements below belong to the highlighted tab.

I also think we shouldn't show that interface by default, but allow users to enable it through the ellipsis menu:

image

Another reason to avoid using segment controls is that they will limit the number of states we can show (due to internationalization). On the other hand, a tabbed list could be easily modified to indicate that it contains extra states (for example, using small chevrons).

image

Global Styles

One difficulty when it comes to stylizing links and blocks inside the Global Style interface is that Global Styles split the management of colors and typography into two different places.

In the typography section, we could have a new module under the basic settings to customize specific properties.

Limiting the number of properties users can customize will help keep uniformity and good design practices throughout the design (although it'll reduce the expressiveness of the websites users can create).

image

Alternatively, we could show those settings in this way instead:

image

And there are several possibilities to give color styles to links and other blocks, but the one that I think is more simple is to implement the tabbed list after the user select “Links” from the list of elements.

image

That said, in my opinion, using popovers to change colors would be the ideal solution because it would remove the need to navigate through several stacks.

Here's the Figma file where I explored these ideas. Props to @jasmussen to help me with some good feedback.

javierarce avatar May 16 '22 14:05 javierarce

@getdave great, thanks!

javierarce avatar May 16 '22 15:05 javierarce

It was discussed in Core Editor chat here.

getdave avatar May 18 '22 14:05 getdave

One thing that I think we should be cautious of with the "Show states" toggle is, that it adds a lot of additional clicks to your workflow if you want to modify the hover state of multiple blocks. Instead of a local component state, I would recommend that this toggle is a more persistent setting that a user may be able to activate.

I'm not sure what the mechanism should be but just calling this out as a concern :)

Besides that, I think these are great designs for this interaction and I am excited about this being worked on 🚀

Thanks to everyone involved!

fabiankaegy avatar May 18 '22 14:05 fabiankaegy