-
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
Ability to style current menu item #42299
Comments
relative to #40778 |
Whilst I recognise the need for this, I really don't think we should be using the pseudo selector syntax. AFAIK If we want to style current we should consider an alternative syntax. |
Information I found says:
I don't think that the currently selected Navigation element has "timing" in the sense the spec suggests. Have you seen a usage in the wild where |
I don't think its necessary for theme.json syntax to match the CSS spec. theme.json is an abstraction of CSS into a system that Global Styles understands, so it's totally valid for us to implement things in a way that works for block themes, even if it doesn't map perfectly into to the CSS spec. |
I really think that we're going to go down the wrong track here. We have an established expectation that the pseudo selector used in What is being proposed here is that we circumvent this expectation for a single given use case (i.e. just because it's convenient for us to use I appreciate we need to optimise for user experience over developer experience. However, I think in the longer term the proposed approach could open the door to more such confusing edge cases which folks will be required to memorise. Let's take a moment to consider who we are really optimising for here. We have two types of "user":
We can easily shield the "Site Owner" from any decisions we make in Theme JSON because we have the Global Styles UI acting as a layer between the code and the UI that they experience. Therefore the user we are actually optimising for here is the WordPress Developer. IMHO asking developers to memorize random exceptions to what are otherwise clear cut conventions when authoring Theme JSON is poor UX. Also consider that if we proceed with what's being proposed and then further down the line we want to add a My opinion is that we should come up with an alternative syntax to allow us to add these states within Theme JSON without impinging on the established convention and causing confusion. It's just an idea but how about we utilise a
To me this reads as "at the state when the item is the one which is currently active then apply these styles". What do you think? A final note to say that if/when the "current" state is exposed to Site Owners in the Global Styles UI I fully expect it to be listed alongside other "states" such as |
@WordPress/block-themers Do you have any opinions on this proposal? I've outlined the arguments above and we need to come to a decision about whom we're intending to optimise for here. IMHO whatever we do in Theme JSON should be optimised for developers not site owners. Site Owners experience styling via the Global Styles UI and thus we can easily "shield" them from whatever we implement in the raw |
Yes, I follow this logic. I think using I like @getdave proposal for using |
I agree that
Thinking out of the current context, for the blocks such as I mean use the prefix
|
I think we're digressing in mixing the discussions of variants and should focus the usage on state. |
Completely agree with this, and would also like to +1 the |
But what if we stick to |
This is for styling a menu item that already has a CSS class that indicates that it is the current page, correct?
|
My concern with this is that it might create an expectation that I can specify any class name here and expect it to work, which it wouldn't! |
This styling should be for |
Yes that is a valid concern: I don't find it unlikely that more (not all or custom) classes might be supported in the future. |
Then we're back to the original argument. |
I've added this to the Core Editor chat agenda to see if we can get further input on this. |
My current opinion is that, while a great endeavor, we gain little from mapping CSS to I fully agree that using CSS style Again, I do think that having both is ideal but at the same time having one syntax is simply a better experience. |
Ah I see @draganescu. So you're suggesting we use That's an interesting alternative suggestion. |
@ is not without its own meaning: https://www.w3.org/TR/css-syntax-3/#at-rules |
I'm not sure this is a valid concern. The way we have been implementing |
This definitely won't be the last time this issue comes up, and I agree that anything that creates a mismatch between CSS syntax and I'd much prefer @carolinan's suggestion. It maps to the CSS concept of I will also just call out that the item with this styling should have |
Ok so I’m hearing that Whilst I appreciate the logic and find the suggestion highly valuable, I also share @scruffian’s concern that allowing particular CSS classes to be introduced here might set the expectation that any CSS selector can be used. This comes back to my point that we should avoid folks needing to understand too many “rules” about what is/isn’t allowed in certain contexts. In this case the developer needs to know that in specific cases you are allowed to use specific CSS selectors in specific places. I think that’s an undue cognitive overhead. Maybe there’s a way where we can prepend or nest the selector in order to denote that it is a special case? For example:
This clearly differentiates it from pseudo selectors whilst also helping to avoid the impression that it will accept any CSS selector? We also need to consider that we might want to apply pseudo selector styles to the current item. For example, how can I style the current item on I am conscious this is far from perfect and I’m not making any decisions just outlining suggestions for consideration :man-bowing: |
What about following the aria label and using |
It feels like this issue could really use some high-level discussion—I hope there has been some already though I haven't seen it (update July 29, 2022: here's a small discussion from last year)—about the overall planned scope of CSS support in One possible limit that might be useful would be limiting it only to elements and the CSS classes output by core (and possibly also registered block styles?). That would exclude things like parent context (e.g., If using that ideal, the "core/navigation": {
":hover": {
"color": "red"
},
"states": {
"current-menu-item": {
"color": "hotpink"
},
"current-menu-ancestor": {
"fontWeight": "bold"
},
"menu-item-has-children": {
"border": {
"style": "dotted",
"color": "papayawhip",
"width": "0 0 .25rem 0"
}
}
}
} The only downside is that |
@jasmussen What do you think of leveraging the existing block style variation control in Global Styles? They're very close in theory already. We can improve both holistically then, if they're 1:1 — even something simple like right caret would help convey. In future iterations, maybe a popover with the available controls (like duotone), instead of a whole different drawer/panel. Just thinking aloud. 🤔 |
Hey @draganescu 👋 I may be misunderstanding this here so please tell me if this is not the case :) When you say "the block support and global styles UI" I read that as the settings on an individual block and the settings in global styles. However, currently the Does this mean that the states (kind of like the already existing pseudo selectors) are only meant to work in the site editor as global settings? If so I think that will be very limiting to this API because when we look at the navigation block, the most basic site usually has at least two navigations. One in the Header of the site and one in the Footer of the site. They almost never share the same styling for the currently active menu item because the background color they are often differs. Also, the navigation in the header often is considered the primary one and therefore often gets more visually interesting treatment applied. |
Thanks for the questions they're very useful. @mrwweb I think you're spot on with identifying the pseudoclasses and HTML and ARIA attributes that should be used to target what is considered "current" for the user. The API described here is not meant to supplant that. The To answer your points more directly the block author can and should make use of pseudoclasses, HTML and ARIA attributes when outputing the block's HTML not this This is the current thinking at least allowing for maximum flexibility and also trying to keep the granularity in check - e.g. there is no way to make a good UX if we implement one tab per possible state). But if this API has gaps unseen let's work through them. @fabiankaegy good call, I am hoping the selectors API will be used across all the features. The API allows the definition of what the selector is for and then any part of the system, global styles or block supports, should "get" that selector and work with it. Simply put, the goal is not not limit |
Thanks for the response. The point about each block specifying unique selectors is helpful. What I am mostly trying to say is that I think the plan right now for the If there were an additional
My point about the CSS and HTML APIs is that aligning the |
Punting this from the 6.5 board due to lack of activity. |
Thank you for updating here Anne. Some additional context - during this release cycle, contributions were focused primarily on trying to make the Navigation Overlay (mobile view) customisable and also on improving the mobile breakpoint detection. This is why there was a lack of activity here. You can read more in the Tracking Issue updates. |
Noting that there are mockups included in #38277 (comment) that try to address this issue as well. If developers subscribed could review, it would be appreciated! |
I revisited the pseudo states issue again, with a potentially simpler design. That design includes a "current" state for the menu item. Is that a reason to consolidate this issue with the other? If not, then an implementation might at least address both these issues! Please share your thoughts on the other issue 🙏 |
The user/themer should be able to style the current menu styles. It could be done something like this in theme.json:
The text was updated successfully, but these errors were encountered: