diff --git a/packages/components/header/_header.scss b/packages/components/header/_header.scss index 4834ae59d..849925d1b 100644 --- a/packages/components/header/_header.scss +++ b/packages/components/header/_header.scss @@ -412,10 +412,6 @@ padding-right: 23px; } - @include mq($from: desktop) { - display: none; - } - .nhsuk-icon__chevron-down { right: -3px; } diff --git a/packages/components/header/header.js b/packages/components/header/header.js index c2b5a9da9..51d226cc9 100644 --- a/packages/components/header/header.js +++ b/packages/components/header/header.js @@ -155,7 +155,7 @@ class Header { */ updateNavigation() { - const availableSpace = this.navigation.offsetWidth + const availableSpace = this.navigationList.offsetWidth let itemsVisible = this.navigationList.children.length if (availableSpace < this.breakpoints[itemsVisible - 1]) { diff --git a/tests/integration/jsdom/header.test.js b/tests/integration/jsdom/header.test.js index 2c9847abb..732fb7ede 100644 --- a/tests/integration/jsdom/header.test.js +++ b/tests/integration/jsdom/header.test.js @@ -3,21 +3,21 @@ import Header from '../../../packages/components/header/header.js' describe('Header class', () => { beforeEach(() => { document.body.innerHTML = ` -
-
-
  • Health A-Z
  • -
  • NHS services
  • -
  • Live Well
  • -
  • Mental health
  • -
  • Care and support
  • -
  • Pregnancy
  • -
  • Home
  • -
  • More
  • -
    -
    -
    -
    - ` +
    +
    +
  • Health A-Z
  • +
  • NHS services
  • +
  • Live Well
  • +
  • Mental health
  • +
  • Care and support
  • +
  • Pregnancy
  • +
  • Home
  • +
  • More
  • +
    +
    +
    +
    + ` }) it('Should create navigation elements in the DOM', async () => { @@ -50,7 +50,7 @@ describe('Header class', () => { }) it('Should close menu when escape key is pressed', async () => { - //define a event for the escape key + // Define a event for the escape key const escapeKeyEvent = new KeyboardEvent('keydown', { key: 'Escape', code: 'Escape', @@ -62,18 +62,18 @@ describe('Header class', () => { await Header() - //Expect the menu to be hidden initially + // Expect the menu to be hidden initially expect( document.querySelector('.nhsuk-header__drop-down').classList.contains('nhsuk-header__drop-down--hidden') ).toBe(true) - //Toogle the menu - open it + // Toggle the menu - open it toggleButton.click() expect( document.querySelector('.nhsuk-header__drop-down').classList.contains('nhsuk-header__drop-down--hidden') ).toBe(false) - //Press the escape key to close it + // Press the escape key to close it document.dispatchEvent(escapeKeyEvent) expect( document.querySelector('.nhsuk-header__drop-down').classList.contains('nhsuk-header__drop-down--hidden') @@ -88,16 +88,16 @@ describe('Header class', () => { }) it('Should setup the Mobile Menu List during initialization', async () => { - //Initially there won't be any ul elements inside the container- it gets added in the setupMobileMenu method + // Initially there won't be any ul elements inside the container- it gets added in the setupMobileMenu method let mobileMenuList = document.querySelector('.nhsuk-mobile-menu-container ul') - //So we expect that to be null until it gets created + // So we expect that to be null until it gets created expect(mobileMenuList).toBe(null) // Call the Header initialization function await Header() - //We update the variable to hold the ul element from the container that has been created + // We update the variable to hold the ul element from the container that has been created mobileMenuList = document.querySelector('.nhsuk-mobile-menu-container ul') expect(mobileMenuList).not.toBeNull() @@ -108,7 +108,6 @@ describe('Header class', () => { it('Should not update navigation when the available space is enough for all elements', async () => { const mobileMenuToggleButton = document.querySelector('.nhsuk-header__menu-toggle') const mobileMenuContainer = document.querySelector('.nhsuk-mobile-menu-container') - const navigationElement = document.querySelector('.nhsuk-navigation') const navigationList = document.querySelector('.nhsuk-header__navigation-list') let mobileMenuList = document.querySelector('.nhsuk-mobile-menu-container ul') @@ -116,7 +115,7 @@ describe('Header class', () => { const navigationOffsetWidthSpy = jest.spyOn(HTMLElement.prototype, 'offsetWidth', 'get') // Mock offsetWidth for navigation element navigationOffsetWidthSpy.mockImplementation(function () { - if (this === navigationElement) { + if (this === navigationList) { return 1000 // Mock navigation element offsetWidth } return 50 // Mock children offsetWidth @@ -140,7 +139,6 @@ describe('Header class', () => { it('Should update navigation when the available space is not enough for all elements', async () => { const mobileMenuToggleButton = document.querySelector('.nhsuk-header__menu-toggle') const mobileMenuContainer = document.querySelector('.nhsuk-mobile-menu-container') - const navigationElement = document.querySelector('.nhsuk-navigation') const navigationList = document.querySelector('.nhsuk-header__navigation-list') let mobileMenuList = document.querySelector('.nhsuk-mobile-menu-container ul') @@ -148,7 +146,7 @@ describe('Header class', () => { const navigationOffsetWidthSpy = jest.spyOn(HTMLElement.prototype, 'offsetWidth', 'get') // Mock offsetWidth for navigation element navigationOffsetWidthSpy.mockImplementation(function () { - if (this === navigationElement) { + if (this === navigationList) { return 700 // Mock navigation element offsetWidth } return 100 // Mock children offsetWidth