Skip to content

Commit 0e7286c

Browse files
Merge pull request #1317 from nhsuk/header-search-fixes
Ensure focused search input in header renders consistently across breakpoints
2 parents 5abb89b + 6589c0b commit 0e7286c

File tree

52 files changed

+95
-34
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+95
-34
lines changed

backstop.config.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -594,6 +594,17 @@ module.exports = {
594594
viewports.get('large-desktop')
595595
]
596596
},
597+
{
598+
clickSelector: '.nhsuk-header__search-input',
599+
label: 'Header with search (focused search input)',
600+
url: `${BASE_URL}/components/header/header-search.html`,
601+
viewports: [
602+
viewports.get('mobile'),
603+
viewports.get('tablet'),
604+
viewports.get('desktop'),
605+
viewports.get('large-desktop')
606+
]
607+
},
597608
{
598609
label: 'Header with account (logged in)',
599610
url: `${BASE_URL}/components/header/header-account-logged-in.html`,
@@ -687,6 +698,18 @@ module.exports = {
687698
viewports.get('large-desktop')
688699
]
689700
},
701+
{
702+
clickSelector: '.nhsuk-header__search-input',
703+
label: 'Header organisational with white header (focused search input)',
704+
url: `${BASE_URL}/components/header/header-org-white.html`,
705+
onReadyScript: 'playwright/onReadyResize.js',
706+
viewports: [
707+
viewports.get('mobile'),
708+
viewports.get('tablet'),
709+
viewports.get('desktop'),
710+
viewports.get('large-desktop')
711+
]
712+
},
690713
{
691714
label: 'Header organisational with white header, navigation',
692715
url: `${BASE_URL}/components/header/header-org-white-nav.html`,

packages/components/header/_index.scss

Lines changed: 71 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
@use "../../core/settings" as *;
44
@use "../../core/tools" as *;
55

6+
$_header-item-padding: 12px;
7+
68
////
79
/// Header component
810
///
@@ -85,24 +87,44 @@
8587
/// Account
8688

8789
.nhsuk-header__account {
88-
background: nhsuk-shade($color_nhsuk-blue, 20%);
90+
position: relative;
8991
border-radius: $nhsuk-border-radius;
9092
flex-grow: 1;
91-
outline: 1px solid nhsuk-shade($color_nhsuk-blue, 20%);
9293
margin-bottom: 1px;
9394

94-
@include nhsuk-media-query($from: tablet) {
95-
align-self: start;
96-
}
97-
9895
.nhsuk-icon__user {
9996
height: 24px;
10097
width: 24px;
10198
flex-shrink: 0;
10299
}
100+
101+
&,
102+
&::before {
103+
background-color: nhsuk-shade($color_nhsuk-blue, 20%);
104+
}
105+
106+
// Expand header account by 1px to ensure the search
107+
// input does not appear to be taller when inline
108+
&::before {
109+
content: "";
110+
display: block;
111+
position: absolute;
112+
top: -1px;
113+
right: 0;
114+
bottom: -1px;
115+
left: 0;
116+
border: 1px solid nhsuk-shade($color_nhsuk-blue, 20%);
117+
border-radius: $nhsuk-border-radius + 1px;
118+
}
119+
120+
@include nhsuk-media-query($from: tablet) {
121+
align-self: start;
122+
}
103123
}
104124

105125
.nhsuk-header__account-list {
126+
position: relative;
127+
z-index: 1;
106128
display: flex;
107129
flex-wrap: wrap;
108130
gap: 1px;
@@ -113,14 +135,13 @@
113135
}
114136

115137
.nhsuk-header__account-item {
116-
background-color: nhsuk-shade($color_nhsuk-blue, 20%);
117138
display: flex;
118139
flex-grow: 1;
119140
gap: nhsuk-spacing(2);
120141
margin: 0;
121142
outline: 1px solid $color_nhsuk-blue;
122143
overflow-wrap: anywhere;
123-
padding: nhsuk-spacing(2) 12px;
144+
padding: nhsuk-spacing(2) $_header-item-padding;
124145
@include nhsuk-font(16);
125146

126147
&:nth-last-child(2) {
@@ -159,47 +180,58 @@
159180
flex-grow: 1;
160181
position: relative;
161182
z-index: 13;
183+
162184
@include nhsuk-print-hide;
163185

164186
.nhsuk-icon__search {
165187
height: 28px;
166188
width: 28px;
189+
190+
// Adjust optical alignment due to the handle appearing
191+
// to push the magnifying glass circle to the top left
192+
margin: 0 -2px -2px 0;
167193
}
168194
}
169195

170196
.nhsuk-header__search-form {
171197
display: flex;
172198
height: 100%;
173199
overflow: visible;
174-
175-
@include nhsuk-media-query($until: tablet) {
176-
position: relative;
177-
}
178200
}
179201

180-
.nhsuk-header__search-input {
181-
border: 1px solid $color_nhsuk-white;
202+
// 1. Disable default search input appearance
203+
.nhsuk-header__search-input.nhsuk-input {
204+
border-color: transparent;
182205
border-radius: $nhsuk-border-radius 0 0 $nhsuk-border-radius;
183-
font-size: $nhsuk-base-font-size;
184206
height: 40px;
185-
padding: 0 12px;
207+
margin-right: -$nhsuk-border-width-form-element;
208+
padding-right: $_header-item-padding;
209+
padding-left: $_header-item-padding - $nhsuk-border-width-form-element;
186210
width: 100%;
211+
@include nhsuk-font-size(16);
187212

188213
&:focus {
189-
border: nhsuk-spacing(1) solid $nhsuk-focus-text-color;
190-
box-shadow: 0 0 0 $nhsuk-focus-width $nhsuk-focus-color;
191-
outline: $nhsuk-focus-width solid transparent;
192-
outline-offset: $nhsuk-focus-width;
193-
padding: 0 9px;
214+
z-index: 10;
194215
}
195216

196217
&::placeholder {
197218
color: $color_nhsuk-grey-1;
198219
opacity: 1; // Fixes low contrast of placeholder text in firefox
199220
}
200221

222+
// Hide search input clear button (IE)
223+
&::-ms-clear {
224+
display: none;
225+
}
226+
227+
// Hide search input icon and cancel button (WebKit, Blink)
228+
&::-webkit-search-decoration,
229+
&::-webkit-search-cancel-button {
230+
appearance: none;
231+
}
232+
201233
@include nhsuk-media-query($until: tablet) {
202-
border-radius: $nhsuk-border-radius;
234+
font-size: inherit;
203235
}
204236
}
205237

@@ -208,18 +240,12 @@
208240
border: 0;
209241
border-radius: 0 $nhsuk-border-radius $nhsuk-border-radius 0;
210242
color: $color_nhsuk-blue;
243+
flex-shrink: 0;
211244
height: nhsuk-spacing(6);
212245
line-height: 1;
213-
outline: none;
214246
margin: 0;
215247
width: 44px;
216-
217-
@include nhsuk-media-query($until: tablet) {
218-
position: absolute;
219-
right: 0;
220-
top: 0;
221-
z-index: 9;
222-
}
248+
z-index: 9;
223249

224250
&:hover {
225251
background-color: $color_shade_nhsuk-blue-35;
@@ -235,6 +261,7 @@
235261
&:focus {
236262
background-color: $nhsuk-focus-color;
237263
box-shadow: inset 0 -4px 0 0 $nhsuk-focus-text-color;
264+
238265
@include nhsuk-focused-button;
239266
}
240267
}
@@ -447,20 +474,31 @@
447474
}
448475

449476
.nhsuk-header__account,
450-
.nhsuk-header__account-item {
477+
.nhsuk-header__account::before {
451478
background-color: $color_nhsuk-grey-5;
479+
}
480+
481+
.nhsuk-header__account::before {
482+
border-color: $color_nhsuk-grey-4;
483+
}
484+
485+
.nhsuk-header__account-item {
452486
outline-color: $color_nhsuk-grey-4;
453487
}
454488

455489
.nhsuk-header__account-link {
456490
@include nhsuk-link-style-no-visited-state;
457491
}
458492

459-
.nhsuk-header__search-input {
493+
.nhsuk-header__search-input.nhsuk-input {
460494
border-color: $color_nhsuk-grey-3;
495+
border-width: 1px;
496+
margin-right: -1px;
461497

462498
&:focus {
463499
border-color: $nhsuk-focus-text-color;
500+
border-width: 2px;
501+
margin-right: -2px;
464502
}
465503
}
466504

@@ -513,7 +551,7 @@
513551
}
514552

515553
.nhsuk-header__navigation-container {
516-
border-top-color: $color_nhsuk-grey-5;
554+
border-color: $color_nhsuk-grey-4;
517555
border-top-width: 1px;
518556
}
519557

packages/components/header/template.njk

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@
6969
<search class="nhsuk-header__search">
7070
<form class="nhsuk-header__search-form" id="search" action="{{ searchAction }}" method="get">
7171
<label class="nhsuk-u-visually-hidden" for="search-field">{{ searchVisuallyHiddenLabel }}</label>
72-
<input class="nhsuk-header__search-input" id="search-field" name="{{ searchName }}" type="search" placeholder="{{ searchPlaceholder }}" autocomplete="off">
72+
<input class="nhsuk-header__search-input nhsuk-input" id="search-field" name="{{ searchName }}" type="search" placeholder="{{ searchPlaceholder }}" autocomplete="off">
7373
<button class="nhsuk-header__search-submit" type="submit">
7474
<svg class="nhsuk-icon nhsuk-icon__search" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" aria-hidden="true" focusable="false">
7575
<path d="M19.71 18.29l-4.11-4.1a7 7 0 1 0-1.41 1.41l4.1 4.11a1 1 0 0 0 1.42 0 1 1 0 0 0 0-1.42zM5 10a5 5 0 1 1 5 5 5 5 0 0 1-5-5z"></path>
Binary file not shown.
Binary file not shown.

0 commit comments

Comments
 (0)