Header component

Hierarchy

  • GOVUKFrontendComponent
    • Header

Constructors

  • Apply a matchMedia for desktop which will trigger a state sync if the browser viewport moves between states.

    Parameters

    • $module: Element

      HTML element to use for header

    Returns Header

Properties

$menu: HTMLElement
$menuButton: Element
$module: Element
menuIsOpen: boolean = false

Save the opened/closed state for the nav in memory so that we can accurately maintain state when the screen is changed from small to big and back to small

mql: MediaQueryList = null

A global const for storing a matchMedia instance which we'll use to detect when a screen size change happens. We rely on it being null if the feature isn't available to initially apply hidden attributes

moduleName: string = 'govuk-header'

Name for the component used when initialising using data-module attributes.

Methods

  • Private

    Sync menu state

    Uses the global variable menuIsOpen to correctly set the accessible and visual states of the menu and the menu button. Additionally will force the menu to be visible and the menu button to be hidden if the matchMedia is triggered to desktop.

    Returns void

  • Private

    Handle menu button click

    When the menu button is clicked, change the visibility of the menu and then sync the accessibility state and menu button state

    Returns void