gutenberg icon indicating copy to clipboard operation
gutenberg copied to clipboard

Improve theme.json support for Navigation block

Open scruffian opened this issue 4 years ago • 18 comments

What problem does this address?

There are many settings available to the navigation block which cannot be customized in theme.json. It is beneficial to themes to be able to style blocks via theme.json rather than in block settings, as it means themes can share patterns and simply modify the navigation via theme.json, rather than each theme needing to create its own header to adjust the navigation.

What is your proposed solution?

It is already possible to set colors and typography for the navigation block in theme.json, but the following properties would also be helpful:

This is list is a good starting point but we should anticipate other properties also being needed.

cc @getdave @draganescu

scruffian avatar Feb 24 '22 13:02 scruffian

Excellent list, thank you! I would also add: overlay menu padding that potentially inherits from a smarter global padding (#35607), but is still individually configurable.

One consideration to keep in mind for the overlay menu properties is in case it becomes possible to edit the contents separately for total customization.

jasmussen avatar Feb 25 '22 07:02 jasmussen

Worthing adding to https://github.com/WordPress/gutenberg/issues/38275 ?

getdave avatar Feb 28 '22 11:02 getdave

Worthing adding to https://github.com/WordPress/gutenberg/issues/38275 ?

Yes please!

scruffian avatar Feb 28 '22 14:02 scruffian

May I add here that currently the theme.json block settings for colors on the nav block are unresponsive. I would be nice if this works too!

{
    "settings": {
        "blocks": {
            "core/navigation": {
                "color": {
                    "text": false,
                    "background": false
                }
            }
        }
    }
}

Humanify-nl avatar Mar 10 '22 13:03 Humanify-nl

What would you expect false to do in this context?

scruffian avatar Mar 10 '22 13:03 scruffian

What would you expect false to do in this context?

To disable the color controls for the user in the block editor for this specific block.

Specifically, for theme authors who do not want to give color controls to users (clients) on the menu blocks.

It was my assumption that this table theme.json v2 - living reference will be applicable for all blocks (eventually).

image

Humanify-nl avatar Mar 10 '22 13:03 Humanify-nl

It was my assumption that this table theme.json v2 - living reference will be applicable for all blocks (eventually).

I believe this is a correct assumption :)

scruffian avatar Mar 10 '22 13:03 scruffian

We also should have a way to target the typography inside the overlay: https://github.com/WordPress/gutenberg/issues/39352

I am starting to wonder if the overlay should be a separate block...

scruffian avatar Mar 10 '22 14:03 scruffian

I had some issues with the .has-background class that were coupled with the color styling of submenu background. It is a tad weird and confusing. Would give another possible argument for splitting these two (submenu and menu overlay)

Since I've been working this week on testing the menu block in my own starter theme, I've come upon some other 'theme.json for navigation' related here: #39263 , maybe relevant to your list.

Humanify-nl avatar Mar 10 '22 14:03 Humanify-nl

I am starting to wonder if the overlay should be a separate block...

Would that enable or simplify this?

jasmussen avatar Mar 11 '22 09:03 jasmussen

I am starting to wonder if the overlay should be a separate block...

It should. I've been thinking about it as well.

getdave avatar Mar 15 '22 15:03 getdave

It looks like the Nav block already has Gap support.

Screen Shot 2022-05-16 at 17 07 40

getdave avatar May 16 '22 16:05 getdave

It looks like the https://github.com/WordPress/gutenberg/pull/37543

The block does have support for blockGap, but it doesn't work in theme.json, see https://github.com/WordPress/gutenberg/issues/39789

scruffian avatar May 25 '22 12:05 scruffian

Was about to write an issue for the states when I saw this one! Would be great to have hover, active and visited states on these as they're links. Should be copy/paste-able from the link block. :)

ghost avatar Jan 21 '23 21:01 ghost

Related https://github.com/WordPress/gutenberg/issues/44712

getdave avatar Mar 17 '23 09:03 getdave

We also can not do this to style navigation, this is much needed

"styles": {
        "blocks": {
            "core/navigation": {
                "elements": {
                    "link": {
                        "color": {
                            "text": "red"
                        },
                        ":hover": {
                            "color": {
                                "text": "blue"
                            }
                        }
                    }
                }
            }
        }
}

aslamdoctor avatar Jul 20 '23 13:07 aslamdoctor

We also can not do this to style navigation, this is much needed

"styles": {
        "blocks": {
            "core/navigation": {
                "elements": {
                    "link": {
                        "color": {
                            "text": "red"
                        },
                        ":hover": {
                            "color": {
                                "text": "blue"
                            }
                        }
                    }
                }
            }
        }
}

I found this isn't due to lack of support, but instead a bug where there is a "color: inherit" class that takes precedence... it's in a bug ticket somewhere here. In the meantime you can make it work by using !important:

"styles": {
		"blocks": {
			"core/navigation": {
				"elements": {
					"link": {
						":hover": {
							"color": {
								"text": "#8B6212 !important"
							}
						}
					}
				}
			}
		}
	}```

caseymilne avatar Oct 06 '23 22:10 caseymilne

Thanks everyone for this list. Most of it has landed: block gap in theme.json, interactive state styling (#76491), hiding extra items (#27131), and a fully customizable overlay via the navigation-overlay template part. Submenu colours are tracked in #44712. Closing this tracker.

youknowriad avatar Oct 09 '26 10:10 youknowriad