-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
Standardized way to modify interactive states (:hover, :focus .etc) for blocks #38277
Comments
This comment was marked as outdated.
This comment was marked as outdated.
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? |
Related: #27075 |
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. |
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: @jasmussen are there any designers working (or planning to work) on this that you know of? |
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 #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). |
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. |
I responded partially in Slack then forgot to copy it here. Here's an expansion:
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 |
This comment was marked as outdated.
This comment was marked as outdated.
I want to emphasis this as it's important. @paaljoachim Thank you for the exploration! |
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
I've been following the work on bringing states to the Style Book from afar and I think it's a great solution for blocks like buttons that need consistency across the site. How do you think it could expand to other blocks? For instance, the Query Loop block has an empty state currently displayed in the canvas below the block's default content. The QL block can be inserted on any page and template and its contents are often specific to the context, so I'm not sure it belongs with the Style Book. Do you think it should be editable similarly to buttons and links or does it deserve a different UI treatment? |
Yes!!! This is important to bring into the hands of designers/theme builders and the Style book would be the perfect place for it. I love it. |
There seems here to be overlap with the need for block states like subscription blocks that may need to show free vs. paid content, or even cart blocks that can be empty or full. The closest we have to that at the moment, is the Custom HTML block which allows a preview, which is admittedly not the best interaction. Style book may indeed be a place for it, but it may also be useful to be able to see in the canvas. Is there an in-between? Here's the Figma, by the way, in case you'd like to tinker! Great feedback, all! |
Maybe we could also tackle this problem (in stylebook) in a more flexible open way. The BlockBook tool @youknowriad built a few years ago had the concept of "Stories". Kind of like Storybook also works: https://youknowriad.github.io/blockbook/block/core---cover/stories Core could register stories for all the states we want to showcase. Whether they are pseudo states or actually different states a block can be in like the query example by @jarekmorawski above |
Nice, yes. Does that need to be accounted for in this mockup, or could we start with Button and Navigation Item blocks and then subsequently follow up? |
That's fine by me if we agree the other use cases should be covered by a different UI. I'm not convinced the Style Book is a good place to interact with contextual block states. The toolbar (or something in the Inspector) could be a good start, but it does raise questions: should it integrate with Style Book somehow? For instance, if Style Book becomes the primary interface for editing button states and we build a different UI for managing block states, should the Button block use it when I add to a post or page? |
I appreciate the Style Book approach which might work well for Theme authors or very experienced users (caveats to this below). However, I don't think it will work for less experienced folks who just want to change visual states on a specific Navigation block. For example, how often do you want to set a standardised For this reason I still believe that ultimately we will need an "inline" means of toggling between states in the block inspector. |
Valid feedback and point, yet I feel exactly opposite to what you describe:
I would set the standized hover/active/current styles for all my navigation blocks, of which I'm most likely to have only one or two, on the theme design itself. I'd do that once, and then never revisit it in a local context. That isn't do dismiss the need for inline controls, which is why it's good that the Style Book approach wouldn't preclude this. But through having a smaller UI footprint, hopefully it would get these tools into theme author hands sooner than the local approach. What do you think? |
@getdave what I meant was using the concept of stories to be able to define what "variation" / "states" get exposed in the style book interface. Not that they would / should be used to edit the states :) |
I appreciate the valid push back here 👍
You are probably right that some (not sure if it's most though...) Themes only have a single "Primary Navigation". What you envisage is suitable for this scenario. However, many Themes have multiple Navigations. This includes the default TT4 Theme which has:
Now imagine the header template part area uses a different color to the footer template part. If I use Style Book to set the states for all my Navigations then it won't work. This is why I'm glad we aren't precluding the requirement for inline controls. This Style Book approach might work as a stop gap, but I can't see it working for anything other than the most basic of Themes. |
It sounds like the discussion is about adding an easier approach to styling navigation through a Global area and then later on adding it also locally so one can adjust it for any Nav directly overriding the Global approach. |
I understand that creating a UI for managing states is a challenge, and that Joens suggestion certainly has some benefits. As a theme author I doubt I would ever find these controls at all if they were tucked away in the style book though. I already struggle sometimes to find a certain control I know exist somewhere. The other day I wanted to try this image lightbox thing and had to resort to googling. Realised that I had to go to global styles to find it. To limit certain controls to the style book would mean that there now are three places where controls for one single block may reside: the ordinary block controls, global styles and global styles with style book activated. |
It seems that most of the discussion here is moving towards two solutions:
While I understand the challenge that 2 brings I would reinforce the importance of working with it. The navigation example that @getdave gave has had some arguments but for me there are even more situations... take the Button block: Your theme developer might have planned it to be red or even have some nice variation that is green. But as a daily user you hit that situation where you really want it to be blue. If we don't offer some UI to do it, the user will never be able to create a coherent button that is blue by default but darker (or lighter) blue when hovered. I know one might argue that user should stick to the theme options and that should be a theme-designer choice... but if so we shouldn't even offer a background color change option at first, right? Similar arguments can be made with the solid vs. outlined states... in the end I believe offering a UI for this is hugely important for Gutenberg to work well, even for classic themes. Once in a while I have to install a plugin just for a simple link or button because the lack of state control would bring me accessibility issues. |
Classic theme support is a good argument for starting with the style book approach, since the style book is likely somewhat easy to make available to classic themes. |
Is it? Wait I didn't knew that it actually makes me really excited for that possibility 🤯 |
Surfacing the Style Book to classic themes is a way to let you style every block your site can use, without necessarily having any block templates. So it's an idea that seems interesting. |
This probably shouldn't be difficult. See this comment. In that comment, an experiment is trying to expose the Style Book and the global styles to the classic theme, but it should also be able to expose just the Style Book. |
Global styles would need something visual, so you can preview the styles you are applying. I'd definitely surface the style book along with global styles, in classic themes. Exposing the template editor would be less useful if block templates are not leveraged. |
Connecting some dots to #66376 which would make it substantially simpler to find these exploded state views. |
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: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:
Here are mockups that extrapolate on Saxon's work to test it for both a Button state, and a navigation "current menu item" state:
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:
Update
We've iterated on this in #1786 and #41976.
A video overview is available.
After #41976, the next steps are:
:hover
onlink
elements within **blocks** in Global Styles UI (currently only top level is supported).:hover
interactivity control to global styles UI #41976 (comment).:focus
and:active
states in the Global Styles UI forlink
.:hover
interactivity control to global styles UI #41976 (comment))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.
The text was updated successfully, but these errors were encountered: