You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Add missing class names from sidebar panels #12082
Describe the bug
Sidebar panels (Categories, Featured Image, etc) are missing unique class names.
It would be very helpful to developers if all sidebar panels contained a unique class name (or id) for CSS/JS targeting.
It looks like some of the panels (post status, revision) offer this already and it would be great to have consistency throughout the markup.
Screenshots
Additional context
WordPress version 4.9.8
Gutenberg plugin version 4.4.0
Reacted by Chris Jones, Alvaro Gois dos Santos, Aurélien Denis, sododesign, Ian Spencer, Mauricio Gelves, Frank Bültge, realworldev, bupotalovo, Anh Tran and 3 more
This was asked in the past and the answer provided was that developers should not rely on CSS selectors to customize panels and that filters and slots should be used instead ( #6057 (comment) ). May I please ask that you try the solution noted there and if you have a very specific use case similar to the comments on that issue, note them here and we discuss the best route forward.
@designsimply I'm not seeing any "solution" on that comment. Could you please provide some examples of how we can customize these sidebar panels using JS? For example:
How can we hide a panel (display:none;) using JS/CSS?
How can we style a field (wrapping element with label / select) with CSS?
@elliotcondon Have you looked at using wp.data to dispatch actions that would hide panels? You can look at the code that powers the "options" modal to see how that works.
Thanks for the link. I've had a look and can see there are a few functions available including removeEditorPanel(). This function looks to completely remove the panel, including all the controls within it, which will return different results than simply hiding it via CSS.
My goal here is not to get bogged down in specific use cases. Instead, I am asking WordPress to retain the same thinking that went into the previous generation admin. The current "classic editor" is amazing to work with (as a web developer) because it follows simple and intuitive naming conventions / HTML markup.
I don't believe we should ask web developers to refine their HTML/CSS/JS skills for front-end, but then tell them they are "doing it wrong" in the back-end. Web developers are a creative bunch. And even after 8 years working on ACF, I am still amazed at the customizations I see in the admin area/editor.
I hope we can add in these classNames, it really will help a lot of people.
Reacted by Jason Bahl, Alvaro Gois dos Santos, Aurélien Denis, Mattias Tengblad, Erik and Jen Baumann
Here is a screenshot of the Gutenberg editor showing that WP core use class names on some sidebar panels for CSS styling. Note the .edit-post-last-revision__panel class.
This topic is to ask for consistency across all sidebar panels as this would allow all developers to style components in a similar way.
@elliotcondon what would be the technical case for hiding a panel via CSS where the JS option wouldn’t be sufficient?
I also think generally we want to discourage people from styling Gutenberg’s built in components, and certainly the editor panels, from a plugin or other integration. Generally the recommendation has been to filter any panels you want to style and provide your own markup/bindings to the API/styles — aka replacing the panels Gutenberg provides rather than modifying them.
@elliotcondon just to be clear I’m only a third party volunteer and my word should not be taken as gospel. I’m a part of the team but don’t represent the opinions of the release leads. My comments are just based on having followed/contributed to Gutenberg for some time and having seen similar questions and topics come up in past issues.
I know it is a bit frustrating because the Gutenberg mentality is often different from previous norms — it is a big mental shift — but seriously if I can help, or help build a good technical case for a change, I am totally happy to do it. I am here to problem solve!
Wait, so this is staying closed? I’m still confused why there can’t be consistent output of styles without the need for filters. Why are the panels treated inconsistently? Still seems like an oversight, not something to offload to site owners/plugin devs.
Adding unique classes/IDs seems like a relatively simple/small thing to do that could have a big impact for some projects. If WP is supposed to be this totally free and open platform why ever have a philosophy to restrict users in any cases? I get the material design thing but you can at least override some of that stuff if you're implementing it usually. We're all consenting adults here. I'm with @elliotcondon on this one 100%.
Has nobody opened a pull request yet? It's all fun piling in in agreement
but condemnation and outrage are neither persuasive nor does it write code.
A pull request that actually implements this is the next step for those who
want it, until then it's purely academic so let's see some constructive
research into how it might be done? Or code!
On Sat, 24 Nov 2018 at 02:18, zrubinrattet ***@***.***> wrote:
Adding unique classes/IDs seems like a relatively simple/small thing to do
that could have a big impact for some projects. If WP is supposed to be
this totally free and open platform why ever have a philosophy to restrict
users in any cases? I get the material design thing but you can at least
override some of that stuff if you're implementing it usually. We're all
consenting adults here. I'm with @elliotcondon
<https://github.com/elliotcondon> on this one 100%.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#12082 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AADl59QRglGxbh4kLqa0CA3RMxvLqu-qks5uyKxsgaJpZM4YqFc4>
.
With all due respect, we’re trying to first have the issue not be closed. If the gatekeepers won’t even acknowledge it is in fact an issue, why waste time on a PR? If we can agree that what @elliotcondon was asking originally, that panels should have consistent classes output I think there’s a chance one of us would be able to work on a PR. But if we’re shut down just by presenting the issue, why would we feel encouraged to open a PR?
I’ll give it a shot if it’s an open issue (probably not super soon though because I’ve got family in town)
Reacted by Spencer Finnell, Ralf Koller, realworldev, Alvaro Gois dos Santos, Anh Tran, Will Skora, Erik, Phil Johnston and Ian Markind
My own personal take is that there are a lot of people in here asking for classes, but I don’t think we’ve seen a single concrete explanation of what the classes would actually be used for, other than “we might need them in the future.”
I think what would help reopen the ticket are some concrete ideas of how the classes would be used, and why the current methods of customisation aren’t sufficient to accomplish those needs. The talk has admittedly gotten a little philosophical, and steering it back to real technical use-cases would be valuable.
The only example I can think of at the moment is adding company branding to a panels header, which sounds like marketing UI clutter. Everything else can be done by either wrapping the panel contents in a div with a class, or adding per item level classes to the panels contents, which would be more optimal from a CSS standpoint.
As for reopening it, simply stating some variation of "I disagree" is ineffectual, and polarizes things, so you are probably doing more harm for your cause than good. Examples, use cases, and code on the other hand work, e.g. implementing it and showing an example use case. As of yet, nobody has actually made an effective case for this outside of hooking in with JS, which has been shown that it won't work.
Shouldn't be too difficult to think of various usecases if you have ever seen realworld WordPress used as CMS with sometimes highly customized backend to guide users with absolutely no technical background to publish posts - some would call this 'democratize publishing'.
General usecase: Plugins which customize admin/edit area like Adminimize with 200.000+ active installs.
Note: "+ Add New Category" has been clicked in both screenshots:
Similar solution for custom taxonomies boxes, #submitdiv ... imagine that yourself.
Overall development time for above requirements: 15 mins.
Used toolchain: Browser inspector, text editor, add_action('admin_head', ..), FTP client.
Solution for Gutenberg?
Maybe somebody can post a simple solution for category box in Gutenberg for above mentioned client requirements, would like to study and learn, thank you.
Besides that:
+1 on unique classes or IDs.
Reacted by Elliot Condon, Ralf Koller, Alvaro Gois dos Santos, carfis, zrubinrattet, folpy, qwerty, bupotalovo, Anh Tran, Frank Neumann-Staude and 4 more
One reason is for consistency as @elliotcondon said. I noticed other issues as well:
Take the Page Attributes meta box as an example. The CSS is following BEM style, but we can't find the class for the block, but inside elements. In details, we have only .editor-page-attributes__template, not .editor-page-attributes. So it's kind of the missing a parent class.
Another reason is it's nearly impossible to target a meta box. For example, there's no difference between taxonomies meta boxes. We can't differentiate built-in Category meta box vs. custom taxonomy meta box.
The reason we need to target a meta box is: in our situation, we want to perform an action (to show/hide a custom field) when users select a category or a post format or a page template. Without ability to target to the category meta box, we can't do that.
Tran, as I described above that won't work, you can't target React elements
and attach event listeners like that.
As soon as someone selects a term or unselected a term, or even expands and
contracts the panel, your event listeners would need recreating. If the
panel is closed there wouldn't even be DOM nodes to match against. Simply
changing the block you're in would change the sidebar undoing what your
code that targets the Html class did
Instead, you'd need to use the JS APIs available and do it the proper data
driven way, either via the data store or the JS WP Hook system that tries
to recreate actions and filters
On Wed, 5 Dec 2018 at 09:37, Tran Ngoc Tuan Anh ***@***.***> wrote:
I'd love to add unique classes or IDs.
One reason is for *consistency* as @elliotcondon
<https://github.com/elliotcondon> said. I noticed other issues as well:
Take the *Page Attributes* meta box as an example. The CSS is following
BEM style, but we can't find the class for the *block*, but inside
elements. In details, we have only .editor-page-attributes__template, not
.editor-page-attributes. So it's kind of the missing a parent class.
Another reason is it's nearly impossible to *target a meta box*. For
example, there's no difference between taxonomies meta boxes. We can't
differentiate built-in Category meta box vs. custom taxonomy meta box.
The reason we need to target a meta box is: in our situation, we want to
perform an action (to show/hide a custom field) when users select a
category or a post format or a page template. Without ability to target to
the category meta box, we can't do that.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#12082 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AADl53jVNntanrk9h5RB1iiLZBRO_KYyks5u15PagaJpZM4YqFc4>
.
jQuery event listeners can be added to a parent element in a way that allows for changing inner elements like so:
$(document).on('click', '.category-items input', function( e ){
// do something
});
That said, I think we are all happy to use the new JS APIs available. The only problem is that we can't find any resources.
Can you please provide a code example on how we can "listen" for a change of a post attribute. For example, if the user selects "Category 2" (taxonomy term), I would like to run some custom JS. How can we do this?
You wouldn't listen to the UI, you would listen for the change to the
internal data structure.
Also don't forget I'm just another commenter, my daily job is code review.
I don't speak in an official capacity so I don't know the ins and outs of
developer docs though I know some are in progress, I don't know their state
I do know that the JS hooks stuff was on the core make blogs and their APIs
is as close to the PHP equivalent as possible, and that the data store is
on GitHub with a tonne of markdown docs, and referenced in the handbook too.
On Wed, 5 Dec 2018 at 10:08, Elliot Condon ***@***.***> wrote:
Hi @tomjn <https://github.com/tomjn>
jQuery event listeners can be added to a parent element in a way that
allows for changing inner elements like so:
$(document).on('click', '.category-items input', function( e ){
// do something
});
That said, I think we are all happy to use the new JS APIs available. The
only problem is that we can't find any resources.
Can you please provide a code example on how we can "listen" for a change
of a post attribute. For example, if the user selects "Category 2"
(taxonomy term), I would like to run some custom JS. How can we do this?
Thanks in advance.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#12082 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AADl5yzk-V6IIbWUDiOg1diYxSyaigIGks5u15sWgaJpZM4YqFc4>
.
I agreed with @elliotcondon that we can listen to the document and provide extra action when something changed.
That sounds familiar with the hooks in PHP. So, the question is, if we have to do with React, does Gutenberg provides these kinds of hooks so we can listen to?
For example, here is the source code for post_format dropdown. And there's no such hook.
Anyway, listening to change event is one use case. And you can argue from the point of React or how JS works in Gutenberg (although it's not really supported yet). But the main point of this issue is about just CSS classes and it has nothing to do with the event or data source. It's more for styling or customizing the editor screen.
Activity
designsimply commentedon Nov 20, 2018
This was asked in the past and the answer provided was that developers should not rely on CSS selectors to customize panels and that filters and slots should be used instead ( #6057 (comment) ). May I please ask that you try the solution noted there and if you have a very specific use case similar to the comments on that issue, note them here and we discuss the best route forward.
elliotcondon commentedon Nov 20, 2018
@designsimply I'm not seeing any "solution" on that comment. Could you please provide some examples of how we can customize these sidebar panels using JS? For example:
display:none;) using JS/CSS?chrisvanpatten commentedon Nov 20, 2018
@elliotcondon Have you looked at using
wp.datato dispatch actions that would hide panels? You can look at the code that powers the "options" modal to see how that works.chrisvanpatten commentedon Nov 20, 2018
@elliotcondon Further reading: #11802
elliotcondon commentedon Nov 20, 2018
@chrisvanpatten would love to see some code examples please 🙏.
chrisvanpatten commentedon Nov 20, 2018
@elliotcondon Our notifications must have crossed paths but check #11802 :)
elliotcondon commentedon Nov 20, 2018
@chrisvanpatten I commented too fast 🤣.
Thanks for the link. I've had a look and can see there are a few functions available including
removeEditorPanel(). This function looks to completely remove the panel, including all the controls within it, which will return different results than simply hiding it via CSS.My goal here is not to get bogged down in specific use cases. Instead, I am asking WordPress to retain the same thinking that went into the previous generation admin. The current "classic editor" is amazing to work with (as a web developer) because it follows simple and intuitive naming conventions / HTML markup.
I don't believe we should ask web developers to refine their HTML/CSS/JS skills for front-end, but then tell them they are "doing it wrong" in the back-end. Web developers are a creative bunch. And even after 8 years working on ACF, I am still amazed at the customizations I see in the admin area/editor.
I hope we can add in these classNames, it really will help a lot of people.
elliotcondon commentedon Nov 20, 2018
Here is a screenshot of the Gutenberg editor showing that WP core use class names on some sidebar panels for CSS styling. Note the

.edit-post-last-revision__panelclass.This topic is to ask for consistency across all sidebar panels as this would allow all developers to style components in a similar way.
chrisvanpatten commentedon Nov 20, 2018
@elliotcondon what would be the technical case for hiding a panel via CSS where the JS option wouldn’t be sufficient?
I also think generally we want to discourage people from styling Gutenberg’s built in components, and certainly the editor panels, from a plugin or other integration. Generally the recommendation has been to filter any panels you want to style and provide your own markup/bindings to the API/styles — aka replacing the panels Gutenberg provides rather than modifying them.
elliotcondon commentedon Nov 20, 2018
@chrisvanpatten It is very clear that you want to discourage people from styling Gutenberg’s built in components. Thanks for your time.
chrisvanpatten commentedon Nov 20, 2018
@elliotcondon just to be clear I’m only a third party volunteer and my word should not be taken as gospel. I’m a part of the team but don’t represent the opinions of the release leads. My comments are just based on having followed/contributed to Gutenberg for some time and having seen similar questions and topics come up in past issues.
I know it is a bit frustrating because the Gutenberg mentality is often different from previous norms — it is a big mental shift — but seriously if I can help, or help build a good technical case for a change, I am totally happy to do it. I am here to problem solve!
21 remaining items
elliotcondon commentedon Nov 22, 2018
So.... Q2. How can we style a field (wrapping element with label / select) with CSS?
jasonbahl commentedon Nov 22, 2018
Wait, so this is staying closed? I’m still confused why there can’t be consistent output of styles without the need for filters. Why are the panels treated inconsistently? Still seems like an oversight, not something to offload to site owners/plugin devs.
alijaffar commentedon Nov 23, 2018
+1 on unique classes or IDs.
zrubinrattet commentedon Nov 24, 2018
Adding unique classes/IDs seems like a relatively simple/small thing to do that could have a big impact for some projects. If WP is supposed to be this totally free and open platform why ever have a philosophy to restrict users in any cases? I get the material design thing but you can at least override some of that stuff if you're implementing it usually. We're all consenting adults here. I'm with @elliotcondon on this one 100%.
tomjn commentedon Nov 24, 2018
jasonbahl commentedon Nov 24, 2018
With all due respect, we’re trying to first have the issue not be closed. If the gatekeepers won’t even acknowledge it is in fact an issue, why waste time on a PR? If we can agree that what @elliotcondon was asking originally, that panels should have consistent classes output I think there’s a chance one of us would be able to work on a PR. But if we’re shut down just by presenting the issue, why would we feel encouraged to open a PR?
I’ll give it a shot if it’s an open issue (probably not super soon though because I’ve got family in town)
chrisvanpatten commentedon Nov 25, 2018
My own personal take is that there are a lot of people in here asking for classes, but I don’t think we’ve seen a single concrete explanation of what the classes would actually be used for, other than “we might need them in the future.”
I think what would help reopen the ticket are some concrete ideas of how the classes would be used, and why the current methods of customisation aren’t sufficient to accomplish those needs. The talk has admittedly gotten a little philosophical, and steering it back to real technical use-cases would be valuable.
tomjn commentedon Nov 25, 2018
The only example I can think of at the moment is adding company branding to a panels header, which sounds like marketing UI clutter. Everything else can be done by either wrapping the panel contents in a div with a class, or adding per item level classes to the panels contents, which would be more optimal from a CSS standpoint.
As for reopening it, simply stating some variation of "I disagree" is ineffectual, and polarizes things, so you are probably doing more harm for your cause than good. Examples, use cases, and code on the other hand work, e.g. implementing it and showing an example use case. As of yet, nobody has actually made an effective case for this outside of hooking in with JS, which has been shown that it won't work.
realworldev commentedon Nov 26, 2018
Shouldn't be too difficult to think of various usecases if you have ever seen realworld WordPress used as CMS with sometimes highly customized backend to guide users with absolutely no technical background to publish posts - some would call this 'democratize publishing'.
General usecase: Plugins which customize admin/edit area like Adminimize with 200.000+ active installs.
Realworld usecase (simplified), client requirements:
Solution for Classic Editor:
Note: "+ Add New Category" has been clicked in both screenshots:
Similar solution for custom taxonomies boxes, #submitdiv ... imagine that yourself.
Overall development time for above requirements: 15 mins.
Used toolchain: Browser inspector, text editor,
add_action('admin_head', ..), FTP client.Solution for Gutenberg?
Maybe somebody can post a simple solution for category box in Gutenberg for above mentioned client requirements, would like to study and learn, thank you.
Besides that:
+1 on unique classes or IDs.
rilwis commentedon Dec 5, 2018
I'd love to add unique classes or IDs.
One reason is for consistency as @elliotcondon said. I noticed other issues as well:
Take the Page Attributes meta box as an example. The CSS is following BEM style, but we can't find the class for the block, but inside elements. In details, we have only
.editor-page-attributes__template, not.editor-page-attributes. So it's kind of the missing a parent class.Another reason is it's nearly impossible to target a meta box. For example, there's no difference between taxonomies meta boxes. We can't differentiate built-in Category meta box vs. custom taxonomy meta box.
The reason we need to target a meta box is: in our situation, we want to perform an action (to show/hide a custom field) when users select a category or a post format or a page template. Without ability to target to the category meta box, we can't do that.
tomjn commentedon Dec 5, 2018
elliotcondon commentedon Dec 5, 2018
Hi @tomjn
jQuery event listeners can be added to a parent element in a way that allows for changing inner elements like so:
That said, I think we are all happy to use the new JS APIs available. The only problem is that we can't find any resources.
Can you please provide a code example on how we can "listen" for a change of a post attribute. For example, if the user selects "Category 2" (taxonomy term), I would like to run some custom JS. How can we do this?
Thanks in advance.
tomjn commentedon Dec 5, 2018
rilwis commentedon Dec 5, 2018
I agreed with @elliotcondon that we can listen to the
documentand provide extra action when something changed.That sounds familiar with the hooks in PHP. So, the question is, if we have to do with React, does Gutenberg provides these kinds of hooks so we can listen to?
For example, here is the source code for
post_formatdropdown. And there's no such hook.Anyway, listening to
changeevent is one use case. And you can argue from the point of React or how JS works in Gutenberg (although it's not really supported yet). But the main point of this issue is about just CSS classes and it has nothing to do with the event or data source. It's more for styling or customizing the editor screen.