Skip to content

Allow custom header links to include dropdowns #1016

@choldgraf

Description

@choldgraf

Context

Currently, our "custom header links" functionality lets people provide name / url pairs that generate extra links in our navigation bar in the header:

https://pydata-sphinx-theme.readthedocs.io/en/stable/user_guide/header-links.html#navigation-bar-external-links

A common pattern is for sites to have dropdowns of links in order to save some space. Our theme already does this partially with the "automatically wrap links over number N in a dropdown menu", but it would be useful if people could define their own dropdown menus as well.

Proposal

Extend the functionality of the "external links" configuration to allow for another field called items. If that field is present, then we assume the value of items is another list of name / url dictionaries (similar to the way we configure external links right now). The whole thing becomes a dropdown menu item with the nested links underneath it.

For example the following would define one external link and one dropdown menu with two external links:

html_theme_options = {
  "external_links": [
      {"name": "link-one-name", "url": "https://<link-one>"},
      {"name": "dropdown-name", "items": [
		    {"name": "nested-name-one", "url": "<url-one>"},
		    {"name": "nested-name-two", "url": "<url-two>"},
		],
	  }
  ]
}

We'd need to do a check to make sure that both url and items were not given in the same entry. Alternatively we could specify a kind key as well, that could be either link or dropdown, and then we could validate the proper options that way.

References

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions