Subdomain nav bar

Use the subdomain nav bar component for top level navigation for subdomain sites.

import {SubdomainNavBar} from '@primer/react-brand'

Examples

SubdomainNavBar is designed to fix to the top of the viewport.

Please refer to our Storybook examples to see the component in a full-screen browser as originally intended.

Basic

Loading

Leading and trailing content

The leadingComponent and trailingComponent props are supported composition slots for custom React elements. Use leadingComponent for content between the title and navigation links, and trailingComponent for content after search and actions. On narrow viewports, both slots move into the menu while preserving that order.

Loading

SubdomainNavBar offers an optional search form control that supports both onSubmit and onChange; use onChange to display inline results. The placeholder labels the input in the opened dialog and defaults to Search {title}, or Search when no navigation title is available.

Users can press / to open the search dialog, or use keyboardShortcut to remap or disable the shortcut. For programmatic control with openSearch() and closeSearch(), see the Imperative Search API Storybook example.

Loading

Search results can be a flat list or grouped by title. Do not mix both formats in the same array.

Use the labels prop to localize search text. Any labels you omit fall back to English.

Loading

Localized narrow menu

Use menuLabels to localize the narrow menu control. The label changes when the menu opens, and any omitted value falls back to English.

Loading

Accessibility

  • Provide a concise, meaningful title. It labels the navigation and communicates the subdomain to assistive technologies.
  • When the menu opens on narrow viewports, hide the rest of the document from screen readers with inert or aria-hidden="true". Use onNarrowMenuToggle to track the menu state.
  • Ensure interactive content supplied through leadingComponent or trailingComponent has an accessible name and remains keyboard operable.
  • Localize the narrow menu’s visible and accessible labels with menuLabels.
  • Choose a keyboardShortcut that does not conflict with browser, operating system, or application shortcuts. Always provide another visible way to open search.
  • For search, localize its visible text, accessible labels, result headings, and live-region announcements. Supplying only some labels values produces a mix of localized text and English defaults.

Component props

SubdomainNavBar Required

NameTypeDefaultDescription
children'SubdomainNavBar.Link'
'SubdomainNavBar.Search'
'SubdomainNavBar.PrimaryAction'
'SubdomainNavBar.SecondaryAction'
'React.ReactElement'
Valid child nodes
classNamestringSets a custom class on the root element
idstringSets a custom ID on the root element
styleReact.CSSPropertiesForwards custom inline styles to the root element
fixedbooleantrueFixes the navigation bar to the top of the viewport
fullWidthbooleanfalseAllows the inner content to fill the available width
logoHrefstringhttps://github.comChanges the URL of the GitHub logo
titlestringRequired subdomain name used visibly and by assistive technologies
titleHrefstring/Links the title to the subdomain root
leadingComponentReact.ReactElementCustom element rendered after the title and before navigation links
trailingComponentReact.ReactElementCustom element rendered after search and actions
menuLabelsPartial<SubdomainNavBarMenuLabels>English labelsOverrides the narrow menu’s visible and accessible labels
refReact.Ref<SubdomainNavBarHandle>Ref to the root element with openSearch() and closeSearch() methods
onNarrowMenuToggle(isOpen: boolean) => voidCalled with the new state when the narrow menu opens or closes

SubdomainNavBarProps, SubdomainNavBarHandle, and SubdomainNavBarMenuLabels are exported from @primer/react-brand.

Narrow menu labels

FieldTypeEnglish defaultPurpose
menuLabelstringMenuVisible and accessible label while the menu is closed
closeLabelstringCloseVisible and accessible label while the menu is open

SubdomainNavBar.Search

NameTypeDefaultDescription
onSubmit(event: FormEvent<HTMLFormElement>) => voidRequired search form submit handler
onChange(event: ChangeEvent<HTMLInputElement>) => voidRequired search input change handler
placeholderstringSearch {title}Text shown in the input trigger and opened search input
shortcutLabelstringShortcut valueVisible input-trigger hint; pass an empty string to hide it
keyboardShortcutstring | false/Global key or modifier combination that opens search; false disables it
labelsPartial<SubdomainNavBarSearchLabels>English labelsOverrides visible and accessible search text and formatting functions
searchResultsSubdomainNavBarSearchResultsFlat or explicitly grouped results
searchTermstringCurrent query used in result headings and accessible labels
classNamestringSets a custom class on the search trigger container
refReact.Ref<HTMLInputElement>Ref to the input inside the opened search dialog

SubdomainNavBarSearchProps and SubdomainNavBarSearchLabels are exported from @primer/react-brand.

Search labels

FieldTypeEnglish defaultPurpose
searchLabelstringSearchAccessible label for the search input
closeLabelstringCloseVisible and accessible close action
resultsLabelstringResultsAccessible label for an untitled result group
searchResultsLabelstringSearch resultsAccessible label for grouped results without a query
formatSearchWithTitle(title: string) => stringSearch ${title}Formats the default placeholder and dialog label
formatSearchTrigger(placeholder: string) => string${placeholder} searchFormats the responsive search trigger’s accessible label
formatResultsHeading(searchTerm: string) => stringResults for “${searchTerm}”Formats the visible heading for ungrouped results
formatResultsLabel(searchTerm: string) => stringResults for ${searchTerm}Formats the accessible label for grouped results
formatSuggestions(count: number) => string${count} suggestions.Formats the polite live-region result-count announcement

Search result types

SubdomainNavBarSearchResultProps, SubdomainNavBarSearchResultGroupProps, and SubdomainNavBarSearchResults are exported from @primer/react-brand.

SubdomainNavBarSearchResultProps

FieldTypeRequiredDescription
titlestringYesLinked result title
descriptionstringYesResult summary
urlstringYesLink destination
datestringYesDisplayed date string; format it for the user’s locale before passing it
categorystringOptional metadata displayed after the date
groupstringGroups flat results under a shared heading
isExternalbooleanShows an external-link indicator for grouped results

SubdomainNavBarSearchResultGroupProps

FieldTypeRequiredDescription
titlestringYesVisible and accessible group name
resultsSubdomainNavBarSearchResultProps[]YesResults in the group

SubdomainNavBar.Link renders an anchor link.

NameTypeDefaultDescription
childrenReact.ReactNodeLink content
classNamestringApplies a custom class
hrefstringDestination path for the anchor element
isExternalbooleanfalseRenders an external-link icon after the link when true

Additional props are passed to the wrapping <li> element. See MDN for accepted list item attributes.