Skip to content

Add missing class names from sidebar panels #12082

Closed

Description

@elliotcondon

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
screen shot 2018-11-20 at 10 20 35 am

Additional context

  • WordPress version 4.9.8
  • Gutenberg plugin version 4.4.0

Activity

  1. added
    [Type] Enhancement
    [Feature] Extensibility
    [Status] Duplicate
    on Nov 20, 2018
  2. designsimply commented on Nov 20, 2018

    @designsimply
    Member

    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.

  3. elliotcondon commented on Nov 20, 2018

    @elliotcondon
    Author

    @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:

    1. How can we hide a panel (display:none;) using JS/CSS?
    2. How can we style a field (wrapping element with label / select) with CSS?
  4. chrisvanpatten commented on Nov 20, 2018

    @chrisvanpatten
    Contributor

    @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.

  5. chrisvanpatten commented on Nov 20, 2018

    @chrisvanpatten
    Contributor

    @elliotcondon Further reading: #11802

  6. elliotcondon commented on Nov 20, 2018

    @elliotcondon
    Author

    @chrisvanpatten would love to see some code examples please 🙏.

  7. chrisvanpatten commented on Nov 20, 2018

    @chrisvanpatten
    Contributor

    @elliotcondon Our notifications must have crossed paths but check #11802 :)

  8. elliotcondon commented on Nov 20, 2018

    @elliotcondon
    Author

    @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.

  9. elliotcondon commented on Nov 20, 2018

    @elliotcondon
    Author

    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.
    screen shot 2018-11-20 at 3 31 48 pm

    This topic is to ask for consistency across all sidebar panels as this would allow all developers to style components in a similar way.

  10. chrisvanpatten commented on Nov 20, 2018

    @chrisvanpatten
    Contributor

    @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.

  11. elliotcondon commented on Nov 20, 2018

    @elliotcondon
    Author

    @chrisvanpatten It is very clear that you want to discourage people from styling Gutenberg’s built in components. Thanks for your time.

  12. chrisvanpatten commented on Nov 20, 2018

    @chrisvanpatten
    Contributor

    @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!

  13. 21 remaining items

  14. elliotcondon commented on Nov 22, 2018

    @elliotcondon
    Author

    So.... Q2. How can we style a field (wrapping element with label / select) with CSS?

  15. jasonbahl commented on Nov 22, 2018

    @jasonbahl

    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.

  16. alijaffar commented on Nov 23, 2018

    @alijaffar

    +1 on unique classes or IDs.

  17. zrubinrattet commented on Nov 24, 2018

    @zrubinrattet

    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%.

  18. tomjn commented on Nov 24, 2018

    @tomjn
    Contributor
  19. jasonbahl commented on Nov 24, 2018

    @jasonbahl

    has nobody opened a pull request yet?

    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)

  20. chrisvanpatten commented on Nov 25, 2018

    @chrisvanpatten
    Contributor

    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.

  21. tomjn commented on Nov 25, 2018

    @tomjn
    Contributor

    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.

  22. realworldev commented on Nov 26, 2018

    @realworldev

    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:

    1. show headline "Steps 1-5" in workflow steps
    2. mark different steps with different colors
    3. allow adding new categories, but only top level
    4. show short instructions at each workflow step
    5. long top level category names might need more than one line, provide better readability in list
    6. category box should be higher (400px max.) so more of the 250+ categories are visible

    Solution for Classic Editor:

    #categorydiv::before {
    	content: "Step 1/5";
    	display: block;
    	font-size: 24px;
    	color: green;
    	margin: .5em;
    }
    #categorydiv {
    	border: 2px solid green;
    }
    #categorydiv #newcategory_parent {
    	display: none;
    }
    #categorydiv #category-tabs::before {
    	content: "Select a maximum of 3 categories here, select 'Slider' for integration in startpage slider.";
    	display: block;
    	margin-bottom: 1em;
    }
    #categorydiv ul.categorychecklist > li {
    	line-height: 16px;
    	margin-bottom: 4px;
    }
    #categorydiv .categorydiv div.tabs-panel {
    	max-height: 400px;
    }
    

    Note: "+ Add New Category" has been clicked in both screenshots:

    categorydiv

    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.

  23. rilwis commented on Dec 5, 2018

    @rilwis
    Contributor

    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.

  24. tomjn commented on Dec 5, 2018

    @tomjn
    Contributor
  25. elliotcondon commented on Dec 5, 2018

    @elliotcondon
    Author

    Hi @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.

  26. tomjn commented on Dec 5, 2018

    @tomjn
    Contributor
  27. rilwis commented on Dec 5, 2018

    @rilwis
    Contributor

    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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Needs Technical Feedback[Feature] Extensibility[Type] Help Request

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions