-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Add button interactive states in the stylebook #67541
base: trunk
Are you sure you want to change the base?
Conversation
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.
To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
Flaky tests detected in 7869490. 🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/12148020769
|
Nice, thanks for working on this. Noting that this PR will substantially benefit from #67546, which makes the sections for each category much clearer, so it might be worth a rebase once it lands. I understand this focuses on the Button first, that's sensible, we can look at states for navigation items and other blocks at a later time. Here's what I see, scrolling down in the Style Book: This PR is closely related to the work that happens in #53431 as well, insofar as the new categories that are being discussed, and even moving the style book into the Site View of the site editor, here: That latter piece is important mainly because those categories will need to be invoked from navigation on the left. To that end, I realized that those categories could maybe need a little more clarification, which I'll share on #53431 in a bit. The relevant part is this one: You'd get to that both in Global Styles > Blocks > Button. It would be something similar for Navigation, sketched here: So what do we need for this PR to land? Not all of that, to be clear, but perhaps:
Additionally, we should find some kinder labels than :active, :hover, etc.
Are :link and :any-link supported at the moment? It's not clear to me whether we should surface those here, honestly. CC: @WordPress/gutenberg-design |
Shared an update here: #53431 (comment), not necessarily needed for this PR to land, but good broader context, hopefully. |
Yep, they are supported. Reference from |
const [ elementsButton ] = useGlobalStyle( 'elements.button' ); | ||
const blocks = BUTTON_STATES.map( ( { key } ) => { | ||
const styles = | ||
( key !== 'default' ? elementsButton[ key ] : elementsButton ) || |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What happens when we have both a "default" and a "state", are we merging the state styles with the "default" styles (I just want to confirm that this is covered because it's not clear by reading this code)
.edit-site-style-book__example-subtitle { | ||
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen-Sans, Ubuntu, Cantarell, "Helvetica Neue", sans-serif; | ||
font-size: 9px; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is very weird that we're rendering the titles and subtitles... within an iframe. Do we have any context on this decision? I think it would have been a lot simpler to avoid an iframe for style book and only use iframes for the examples (maybe even use BlockPreview
rather than BlockList
and Provider
)
For clarity, I'm not asking of any change in this particular PR but I wonder if this was considered and if we didn't, we should probably consider as part of our efforts to improve style book. cc @tellthemachines @ramonjd @aaronrobertshaw
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Speaking of the font size, it's a bit small. The later mockups have two heading sizes: the main category (16px), and the subheading size (13px):
Potentially this can be separate since there's a lot of separate work going on with headings, but there's a spec here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we have any context on this decision? I think it would have been a lot simpler to avoid an iframe for style book and only use iframes for the examples
It's an abstraction of noisysock's original implementation.
🤔 If I recall correctly, at the time it was to simulate an "editor instance" within the editor, but isolated so as to have more control over window resizing, styles and so on. It proved useful for revisions where discrete global styles configs could be loaded into the iframe without affecting the main canvas.
As is with many features, things just grew from there.
I think it would have been a lot simpler to avoid an iframe for style book and only use iframes for the examples (maybe even use BlockPreview rather than BlockList and Provider)
I wonder if this was considered and if we didn't, we should probably consider as part of our efforts to improve style book
I agree the setup is ripe for refactoring.
I tried a few variations while researching for #62216. I think it's worth reigniting, so maybe that issue could be extended/repurposed.
It will be a whole lot simpler if Global styles (including revisions and style book) finds a new home in the left-hand "view" site editor side bar.
There have been noises to that effect, but I doubt it will happen soon.
By "simpler" I mean that the component wouldn't have to live in the editor canvas and do all the iframe/slot faffery.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
By "simpler" I mean that the component wouldn't have to live in the editor canvas and do all the iframe/slot faffery.
I feel like refactoring the stylebook to use multiple small "Block Previews" rather than a huge iFrame for everything is independent from whether it should be using the EditorContentSlotFill
or not.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
From memory the main reason we went with a single iframe for everything was in order to correctly show the theme background, whether it's a plain color or a background image. It's particularly relevant for background images as it means the image won't be split up and contained inside multiple small frames, but will replicate what it looks like on the actual site:
We'd have the same problem with gradient backgrounds too.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah that's a good reason :) I wonder if we can have a background iframe positioned absolutely behind everything. (Anyway, I guess we can probably move this discussion to a separate thread/issue :p )
Re: the subtitles, left a comment here: #67541 (comment) |
I'm really waffling on surfacing "Any link" and "Link" here. For a button, it's not clear these are useful to style: for example if I wrote custom CSS I'd never use them. By surfacing them here, we give them prominence, perhaps suggesting you should be styling them. Would it be possible to hide these to start, and then surface them, perhaps under a "More..." link at a later time, if we get feedback these are needed? CC: @WordPress/gutenberg-design for any additional thoughts. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One thing I'm noticing when testing this on actual themes is that quite a few of them don't provide hover and focus states for buttons 😅
It's common practice to provide hover styles for links, but maybe not so much for buttons. It's also common practice (and considered by some folks best practice for a11y reasons) to rely on browser defaults for focus styles.
Another thing to consider is that themes that do provide focus styles might do so for all focusable elements, or at least provide baseline styles and then customise for individual elements.
TT5 provides base outline styles in its stylesheet, whereas TT4 does it in the custom CSS in theme.json. These are styles that we're not picking up here, and I can't think of a straightforward way of doing so unless we get computed properties for the actual elements in the DOM.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for working on this. I think it's good to display the button states.
It would be nice to see the pseudo states editable in the UI, similar to the link element. Is that part of #38277?
const BUTTON_STATES = [ | ||
{ | ||
key: 'default', | ||
title: __( 'Button' ), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
( key !== 'default' ? elementsButton[ key ] : elementsButton ) || | ||
{}; | ||
return createBlock( 'core/button', { | ||
text: __( 'Call to Action' ), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@@ -239,6 +239,11 @@ export const STYLE_BOOK_IFRAME_STYLES = ` | |||
text-transform: uppercase; | |||
} | |||
|
|||
.edit-site-style-book__example-subtitle { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we make the button text describe its state we wouldn't need this CSS anyway.
That's a very good point! Would the button state previews be more useful if there were controls in global styles to modify these states first?
Ah yes true. I think custom theme.json CSS is rendered inside the style book iframe, but in the case of TT4 there's no It would be nice to be able to "force" the |
and
These are related. One of the best reasons for surfacing these pseudo states is to allow you easy access to add them. It's very much a block developer tool, you use these states when you build the theme. And so showing them unstyled can serve as a reminder: hey, you forgot a focus style. Of course the buttons should be shown in that state. In the case of Twenty Twenty-Five, it actually does provide its own focus style across both links and buttons. But it does so using custom CSS, but mainly because these states were not editable in the editor at the time of shipping the feature. So in a way, the fact that these aren't styled by the theme, is part of the reason we do work. It's impactful, thank you! I still don't think we should show
That's another good point, and an argument to also hide this one, require you to edit theme.json for providing this too. As far as things looking duplicated here, this is intentional. It is to imply: this is the same button, or navigation item, we're just showing differente states of the same item: This can be polished further, to be sure. But I wouldn't let that block this PR. Getting the behavior right and looking like the mockups, should be the first step, and enough to merge. |
Maybe they should be hidden by default, but appear when the style exists in theme.json? If I built a theme that included styles for these states, I think I'd expect them to be included in Style Book. |
The problem with them being default is for later, when we allow editing these things, it gives an indication to the user that he can edit these things separately (maybe even click on them to select the state) |
From my point of view, the Stylebook is a guide to all the site elements that can be styled/customized. Not all sites use all the heading levels, and we still don't hide them in the Stylebook. Listing all the possible interactive states of an element makes it easy to select, preview, and style, which seems to be one of the main goals and utility of the Stylebook.
Yes, this is part of an effort to add the editing UI for the interactive states. I was planning to work on that after we ship this. |
const styles = | ||
( key !== 'default' ? elementsButton[ key ] : elementsButton ) || | ||
{}; | ||
return createBlock( 'core/button', { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Something to keep in mind: the block might be deregistered and could trigger errors.
See:
This makes sense for hover, but with focus many themes rely on browser defaults, which is also a correct thing to do, and in those cases this button will never show the actual focus styles. That's not terrible, but in the cases that themes do style focus they often (again, correctly) do it at a global level which we don't provide tools for and I don't believe we have plans to. We could potentially provide support for styling outline on all interactive elements at a global level, but outline is only one of a few popular ways to style focus. Themes will likely still leverage custom CSS or the theme stylesheet for more custom solutions, in which case the style book also won't show the actual focus styles. Additionally, there's a risk of inadvertently worsening the accessibility experience for folks depending on focus styles if we allow editing those styles only on Buttons, or even if we allow editing them individually per block or element type. Focus styles should be consistent across all interactive elements on a website, which is why often they are styled all together. I don't want to block this PR from landing, but we should be aware that the focus button state will in most cases not do its job of reflecting actual focus styles. We should also be very careful in the follow-ups with how we allow styling focus states in the UI, as there's a real risk of users inadvertently making their websites inaccessible by e.g. removing those styles altogether. |
Then a theme like empty theme would not be able to add hover states, it would still force the theme creator to go into the theme files, which is what we are trying to avoid by providing a UI. Maybe we want to only allow a specific set of states for starters and then open up the discussion to show more, but I don't think we should rely on the theme styling them or not. |
We actually can change the outline, it's just theme.json only for the time being |
Yeah but it's restricted to specific elements. There's no way of setting outline globally for all elements on focus. I reckon that's why both TT4 and TT5 use either custom CSS or the theme stylesheet to set a global style for all focusable elements. They also both use the outline property on the button element to set color and offset on the global outline. |
We may be able to do this in a slightly hacky way 😅 Unfortunately I guess we could trigger the focus state on the button programatically and then use |
That sounds interesting! Sounds like we could. But per the discussion on Mockup: |
Came here through another issue, I was wondering if it would be possible to add |
What?
Add button interactive states in the stylebook
Why?
To showcase the different interactive states of the button in the stylebook.
This is part of the effort around adding a UI to define the styles of those interactive states: #38277
Fixes: #67542
How?
Bu adding one button for each interactive state in the stylebook.
Testing Instructions
theme.json
file. Example:Maybe it's simpler for you to download and try this theme featuring only the button interactive states as in the screenshot:
testing-button-states.zip
Screenshots or screencast