Skip to content

Commit 9428747

Browse files
Add space between header navigation items using padding
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.
1 parent 130909d commit 9428747

File tree

3 files changed

+29
-20
lines changed

3 files changed

+29
-20
lines changed

packages/components/header/_header-white.scss

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@
6767
}
6868
}
6969

70-
.nhsuk-header__navigation-list {
70+
.nhsuk-navigation {
7171
border-top-width: 0;
7272
}
7373
}
@@ -82,7 +82,7 @@
8282
}
8383
}
8484

85-
.nhsuk-header__navigation-list {
85+
.nhsuk-navigation {
8686
border-top-color: $color_nhsuk-grey-5;
8787
border-top-width: 1px;
8888
}

packages/components/header/_header.scss

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -222,26 +222,30 @@
222222
}
223223

224224
.nhsuk-navigation {
225-
display: flex;
225+
@include govuk-width-container;
226226

227227
@include mq($until: tablet) {
228228
position: relative;
229229
z-index: 10;
230230
}
231+
232+
@include mq($from: tablet) {
233+
border-top: 1px solid $color_transparent_nhsuk-white-20;
234+
}
231235
}
232236

233237
// Visible navigation list
234238
.nhsuk-header__navigation-list {
235-
@include govuk-width-container;
236-
column-gap: nhsuk-spacing(4);
237239
display: flex;
238240
flex-wrap: wrap;
239241
list-style: none;
242+
margin: 0 (nhsuk-spacing(2) * -1);
240243
padding: 0;
241-
width: 100%;
244+
width: calc(100% + nhsuk-spacing(2) + nhsuk-spacing(2));
242245

243246
@include mq($from: tablet) {
244-
border-top: 1px solid $color_transparent_nhsuk-white-20;
247+
margin: 0 (nhsuk-spacing(3) * -1);
248+
width: calc(100% + nhsuk-spacing(3) + nhsuk-spacing(3));
245249
}
246250

247251
.js-enabled & {
@@ -257,6 +261,11 @@
257261

258262
.nhsuk-header__navigation-item {
259263
margin-bottom: 0;
264+
padding: 0 nhsuk-spacing(2);
265+
266+
@include mq($from: tablet) {
267+
padding: 0 nhsuk-spacing(3);
268+
}
260269
}
261270

262271
// This is a <strong> element used as a fallback mechanism for visually
@@ -328,10 +337,13 @@
328337
top: 100%;
329338
left: 0;
330339

340+
@include mq($until: tablet) {
341+
margin: 0 (nhsuk-spacing(3) * -1);
342+
}
343+
331344
.nhsuk-header__navigation-link {
332345
@include govuk-width-container;
333346
@include nhsuk-link-style-no-visited-state;
334-
padding: 12px 0;
335347

336348
// When in expanded menu, a current item link should revert to having a
337349
// no box-shadow, with a box-shadow added to containing list item instead.
@@ -349,6 +361,7 @@
349361

350362
.nhsuk-header__navigation-item {
351363
border-top: 1px solid $color_nhsuk-grey-5;
364+
padding: 0;
352365
}
353366

354367
// Current item within expended mobile menu gets blue line on left edge.
@@ -369,6 +382,11 @@
369382
.nhsuk-mobile-menu-container {
370383
align-self: center;
371384
display: none;
385+
padding: 0 nhsuk-spacing(2);
386+
387+
@include mq($from: tablet) {
388+
padding: 0 nhsuk-spacing(3);
389+
}
372390
}
373391

374392
.nhsuk-mobile-menu-container--visible {

packages/components/header/header.js

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -63,19 +63,13 @@ class Header {
6363
/**
6464
* Calculate breakpoints.
6565
*
66-
* Calculate the breakpoints by summing the widths of
67-
* each navigation item.
68-
*
66+
* Calculate breakpoints by summing the width of each navigation item.
6967
*/
7068
calculateBreakpoints() {
71-
// Get the width of the gap between each navigation item
72-
const navigationListStyles = window.getComputedStyle(this.navigationList)
73-
const gapPixels = navigationListStyles.getPropertyValue('column-gap')
74-
const gap = Number(gapPixels.replace('px', ''))
75-
7669
let childrenWidth = 0
7770
for (let i = 0; i < this.navigationList.children.length; i++) {
78-
childrenWidth += this.navigationList.children[i].offsetWidth + gap
71+
childrenWidth += this.navigationList.children[i].offsetWidth
72+
7973
this.breakpoints[i] = childrenWidth
8074
}
8175
}
@@ -188,9 +182,6 @@ class Header {
188182
this.mobileMenuContainer.classList.add(
189183
'nhsuk-mobile-menu-container--visible'
190184
)
191-
if (itemsVisible === 2) {
192-
return
193-
}
194185
while (availableSpace < this.breakpoints[itemsVisible - 1]) {
195186
this.mobileMenu.insertBefore(
196187
this.navigationList.children[itemsVisible - 2],

0 commit comments

Comments
 (0)