Skip to content

Commit c60dcbd

Browse files
committed
Refactor link styles
Remove `govuk-header__link` and `govuk-header__link—homepage`, replacing them with a dedicated `govuk-header__homepage-link` class.
1 parent 4a19f8e commit c60dcbd

File tree

3 files changed

+99
-104
lines changed

3 files changed

+99
-104
lines changed

packages/govuk-frontend/src/govuk/components/header/_index.scss

Lines changed: 97 additions & 102 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,102 @@
6363
}
6464
}
6565

66+
.govuk-header__logo {
67+
box-sizing: border-box;
68+
@include govuk-responsive-margin($govuk-header-vertical-spacing-value, "bottom");
69+
70+
@media #{govuk-from-breakpoint(desktop)} {
71+
width: 33.33%;
72+
padding-right: $govuk-gutter-half;
73+
float: left;
74+
vertical-align: top;
75+
76+
// Reset float when logo is the last child, without a navigation
77+
&:last-child {
78+
width: auto;
79+
padding-right: 0;
80+
float: none;
81+
}
82+
}
83+
84+
@include _govuk-rebrand {
85+
// Apply margins to internal elements to emulate padding
86+
margin-bottom: 0;
87+
88+
// Magic numbers, set padding to vertically centre align the logo
89+
padding-top: 16px;
90+
padding-bottom: 14px - $govuk-header-rebrand-logo-bottom-margin;
91+
}
92+
}
93+
94+
.govuk-header__homepage-link {
95+
// Avoid using the `govuk-link-common` mixin because the links in the
96+
// header get a special treatment, because:
97+
//
98+
// - underlines are only visible on hover
99+
// - all links get a 3px underline regardless of text size, as there are
100+
// multiple grouped elements close to one another and having slightly
101+
// different underline widths looks unbalanced
102+
//
103+
// Font size needs to be set on the link so that the box sizing is correct
104+
// in Firefox
105+
display: inline-block;
106+
margin-right: govuk-spacing(2);
107+
font-size: 30px; // We don't have a mixin that produces 30px font size
108+
text-decoration: none;
109+
@include govuk-link-style-inverse;
110+
111+
@media #{govuk-from-breakpoint(desktop)} {
112+
display: inline;
113+
}
114+
115+
&:link,
116+
&:visited {
117+
text-decoration: none;
118+
}
119+
120+
&:hover,
121+
&:active {
122+
// Negate the added border
123+
margin-bottom: $govuk-header-link-underline-thickness * -1;
124+
border-bottom: $govuk-header-link-underline-thickness solid;
125+
}
126+
127+
&:hover {
128+
text-decoration: underline;
129+
text-decoration-thickness: $govuk-header-link-underline-thickness;
130+
131+
@if $govuk-link-underline-offset {
132+
text-underline-offset: $govuk-link-underline-offset;
133+
}
134+
}
135+
136+
&:focus {
137+
// Remove any borders that show when focused and hovered.
138+
margin-bottom: 0;
139+
border-bottom: 0;
140+
141+
@include govuk-focused-text;
142+
}
143+
144+
@include _govuk-rebrand {
145+
display: inline;
146+
147+
// Remove word-spacing from within the logo so we can ignore
148+
// whitespace characters in the HTML
149+
word-spacing: govuk-px-to-rem(-6px);
150+
151+
// Reset word-spacing for child elements
152+
> * {
153+
word-spacing: 0;
154+
}
155+
156+
&:not(:focus) {
157+
background-color: $govuk-header-rebrand-background;
158+
}
159+
}
160+
}
161+
66162
.govuk-header__logotype {
67163
display: inline-block;
68164
position: relative;
@@ -180,115 +276,14 @@
180276
}
181277
}
182278

183-
.govuk-header__link {
184-
// Avoid using the `govuk-link-common` mixin because the links in the header
185-
// get a special treatment, because:
186-
//
187-
// - underlines are only visible on hover
188-
// - all links get a 3px underline regardless of text size, as there are
189-
// multiple grouped elements close to one another and having slightly
190-
// different underline widths looks unbalanced
191-
@include govuk-link-style-inverse;
192-
193-
text-decoration: none;
194-
195-
&:hover {
196-
text-decoration: underline;
197-
text-decoration-thickness: $govuk-header-link-underline-thickness;
198-
199-
@if $govuk-link-underline-offset {
200-
text-underline-offset: $govuk-link-underline-offset;
201-
}
202-
}
203-
204-
&:focus {
205-
@include govuk-focused-text;
206-
}
207-
}
208-
209-
.govuk-header__link--homepage {
210-
// Font size needs to be set on the link so that the box sizing is correct
211-
// in Firefox
212-
display: inline-block;
213-
margin-right: govuk-spacing(2);
214-
font-size: 30px; // We don't have a mixin that produces 30px font size
215-
216-
@media #{govuk-from-breakpoint(desktop)} {
217-
display: inline;
218-
}
219-
220-
&:link,
221-
&:visited {
222-
text-decoration: none;
223-
}
224-
225-
&:hover,
226-
&:active {
227-
// Negate the added border
228-
margin-bottom: $govuk-header-link-underline-thickness * -1;
229-
border-bottom: $govuk-header-link-underline-thickness solid;
230-
}
231-
232-
// Remove any borders that show when focused and hovered.
233-
&:focus {
234-
margin-bottom: 0;
235-
border-bottom: 0;
236-
}
237-
238-
@include _govuk-rebrand {
239-
display: inline;
240-
241-
// Remove word-spacing from within the logo so we can ignore
242-
// whitespace characters in the HTML
243-
word-spacing: govuk-px-to-rem(-6px);
244-
245-
// Reset word-spacing for child elements
246-
> * {
247-
word-spacing: 0;
248-
}
249-
250-
&:not(:focus) {
251-
background-color: $govuk-header-rebrand-background;
252-
}
253-
}
254-
}
255-
256-
.govuk-header__logo {
257-
box-sizing: border-box;
258-
@include govuk-responsive-margin($govuk-header-vertical-spacing-value, "bottom");
259-
260-
@media #{govuk-from-breakpoint(desktop)} {
261-
width: 33.33%;
262-
padding-right: $govuk-gutter-half;
263-
float: left;
264-
vertical-align: top;
265-
266-
// Reset float when logo is the last child, without a navigation
267-
&:last-child {
268-
width: auto;
269-
padding-right: 0;
270-
float: none;
271-
}
272-
}
273-
274-
@include _govuk-rebrand {
275-
// Apply margins to internal elements to emulate padding
276-
margin-bottom: 0;
277-
278-
// Magic numbers, set padding to vertically centre align the logo
279-
padding-top: 16px;
280-
padding-bottom: 14px - $govuk-header-rebrand-logo-bottom-margin;
281-
}
282-
}
283-
284279
@media print {
285280
.govuk-header {
286281
border-bottom-width: 0;
287282
color: govuk-colour("black");
288283
background: transparent;
289284
}
290285

291-
.govuk-header__link {
286+
.govuk-header__homepage-link {
292287
&:link,
293288
&:visited {
294289
color: govuk-colour("black");

packages/govuk-frontend/src/govuk/components/header/template.njk

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<header class="govuk-header {%- if params.classes %} {{ params.classes }}{% endif %}" {{- govukAttributes(params.attributes) }}>
77
<div class="govuk-header__container {{ params.containerClasses | default("govuk-width-container", true) }}">
88
<div class="govuk-header__logo">
9-
<a href="{{ params.homepageUrl | default("//gov.uk", true) }}" class="govuk-header__link govuk-header__link--homepage">
9+
<a href="{{ params.homepageUrl | default("//gov.uk", true) }}" class="govuk-header__homepage-link">
1010
{{ govukLogo({
1111
classes: "govuk-header__logotype",
1212
ariaLabelText: "GOV.UK",

packages/govuk-frontend/src/govuk/components/header/template.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ describe('header', () => {
3939
const $ = render('header', examples['custom homepage url'])
4040

4141
const $component = $('.govuk-header')
42-
const $homepageLink = $component.find('.govuk-header__link--homepage')
42+
const $homepageLink = $component.find('.govuk-header__homepage-link')
4343
expect($homepageLink.attr('href')).toBe('/')
4444
})
4545
})

0 commit comments

Comments
 (0)