Skip to content

Fix header navigation item allocation on resize#1228

Merged
colinrotherham merged 30 commits into
mainfrom
header-calculation
Apr 16, 2025
Merged

Fix header navigation item allocation on resize#1228
colinrotherham merged 30 commits into
mainfrom
header-calculation

Conversation

@colinrotherham

@colinrotherham colinrotherham commented Apr 11, 2025

Copy link
Copy Markdown
Contributor

Description

This PR fixes #1226 and adds 2x commits from #1058 as follows:

  1. Wrap header navigation items when JavaScript is not enabled
  2. Add space between header navigation items using padding

Most helpful was 2) where CSS gap is removed

Checklist

Comment thread packages/components/header/_header.scss Outdated
Comment thread packages/components/header/header.js
Comment thread packages/components/header/header.js Outdated
@colinrotherham colinrotherham force-pushed the header-calculation branch 3 times, most recently from 27ed7e5 to 6cda5ed Compare April 11, 2025 13:26
@paulrobertlloyd

Copy link
Copy Markdown
Contributor

This all looks good to me, some nice tidy up within the JS for this component too.

Take it this PR also ticks off updating the mocked navigation HTML used in the component test to actually represent the markup now being used as well?

@MatMoore MatMoore left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I skipped over some of the CSS details, but the javascript changes look good to me. Extracting methods for showing/hiding the menu bar is a nice improvement 👍🏻

Have a couple of minor suggestions inline, but the approach seems good.

Comment thread packages/components/header/header.js Outdated
Comment thread packages/components/header/header.js Outdated
Comment thread packages/components/header/header.js Outdated
Comment thread tests/backstop/engine_scripts/playwright/onReadyResize.js Outdated
@colinrotherham

Copy link
Copy Markdown
Contributor Author

Take it this PR also ticks off updating the mocked navigation HTML used in the component test to actually represent the markup now being used as well?

@paulrobertlloyd Yeah it's the same HTML now, did I see that somewhere?

I'd like to import Nunjucks in future and render the actual template so it's always correct 😮

@colinrotherham

Copy link
Copy Markdown
Contributor Author

Thanks @paulrobertlloyd @MatMoore I've pushed up some feedback, ready for review again

MatMoore
MatMoore previously approved these changes Apr 14, 2025

@MatMoore MatMoore left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍🏻

@anandamaryon1

Copy link
Copy Markdown
Contributor

Not sure whether it's really an issue, but in testing this I observe that the number of items shown varies between first load and any subsequent resizing at 768px wide.

For example, if I resize from wider down to 768, I see the More button:
image

But if I refresh / load up on 768 wide, I see all the nav items at once, without the More button:
image

Not really a usability issue but maybe a symptom of some breakpoints not quite aligning?

@colinrotherham

colinrotherham commented Apr 15, 2025

Copy link
Copy Markdown
Contributor Author

Not sure whether it's really an issue, but in testing this I observe that the number of items shown varies between first load and any subsequent resizing at 768px wide.

Hey @anandamaryon1 thanks for spotting another bug 😆

The loop in this.calculateBreakPoints() had these lines:

if (item.element.parentElement === this.mobileMenu) {
  return
}

Which means:

  • On the 1st run, we move overflow items to the mobile menu
  • On the 2nd run, we skip offset calculations for overflow items

But uniquely at 769px we adjust the spacing, so if we hadn't skipped we'd realise there was enough room

I've pushed up a fix

Other bug fixes and removals

I've also spotted a few other things so pushed:

  • Remove unused orientation change handler
  • Remove unused js-show from README example
  • Remove unused this.mobileMenuCloseButton
  • Remove unnecessary focus on menu close
  • Fix escape key removeEventListener() and others
  • Fix menu button arrow colour on focus

With the tests updated to check the expected item counts at each width

anandamaryon1
anandamaryon1 previously approved these changes Apr 15, 2025
MatMoore
MatMoore previously approved these changes Apr 15, 2025
Comment thread packages/components/header/header.js Outdated
Comment thread packages/components/header/README.md
Comment thread tests/integration/jsdom/header.test.mjs
Comment thread tests/integration/jsdom/header.test.mjs
Comment thread tests/integration/jsdom/header.test.mjs
colinrotherham and others added 7 commits April 15, 2025 16:43
Co-authored-by: Colin Rotherham <work@colinr.com>
This prevents items appearing next to each other in browsers that do not support column-gap on flex containers and removes the need to use gap when calculating breakpoint widths in component JS.

Co-authored-by: Colin Rotherham <work@colinr.com>
@colinrotherham colinrotherham force-pushed the header-calculation branch 2 times, most recently from 304c2a8 to 535c3dd Compare April 15, 2025 17:05
Comment thread packages/components/header/header.js Outdated
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Header navigation items hidden after resize

4 participants