Skip to content

Commit

Permalink
Add parameter to localise mobile menu toggle button
Browse files Browse the repository at this point in the history
Adds the `menuButton` parameter to customise the text of the menu toggle button that appears on narrow screens.
  • Loading branch information
querkmachine authored and domoscargin committed Jul 21, 2022
1 parent dbe4b0b commit fa18951
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 1 deletion.
19 changes: 19 additions & 0 deletions src/govuk/components/header/header.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,10 @@ params:
type: string
required: false
description: Text for the `aria-label` attribute of the button that toggles the navigation. Defaults to 'Show or hide menu'.
- name: menuButtonText
type: string
required: false
description: Text for the button that toggles the navigation. Defaults to 'Menu'.
- name: containerClasses
type: string
required: false
Expand Down Expand Up @@ -131,6 +135,21 @@ examples:
text: Navigation item 3
- href: '#4'
text: Navigation item 4

- name: with custom menu button text
description: Button translated into Welsh
data:
menuButtonText: Dewislen
navigation:
- href: '#1'
text: Eitem llywio 1
active: true
- href: '#2'
text: Eitem llywio 2
- href: '#3'
text: Eitem llywio 3
- href: '#4'
text: Eitem llywio 4

- name: with custom menu button label
data:
Expand Down
2 changes: 1 addition & 1 deletion src/govuk/components/header/template.njk
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
{% endif %}
{% if params.navigation %}
<nav aria-label="{{ params.navigationLabel | default('Menu') }}" class="govuk-header__navigation {{ params.navigationClasses if params.navigationClasses }}">
<button type="button" class="govuk-header__menu-button govuk-js-header-toggle" aria-controls="navigation" aria-label="{{ params.menuButtonLabel | default('Show or hide menu') }}">Menu</button>
<button type="button" class="govuk-header__menu-button govuk-js-header-toggle" aria-controls="navigation" aria-label="{{ params.menuButtonLabel | default('Show or hide menu') }}">{{ params.menuButtonText | default('Menu') }}</button>

<ul id="navigation" class="govuk-header__navigation-list">
{% for item in params.navigation %}
Expand Down
14 changes: 14 additions & 0 deletions src/govuk/components/header/template.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,20 @@ describe('header', () => {

expect($button.attr('aria-label')).toEqual('Custom button label')
})
it('renders default text correctly', () => {
const $ = render('header', examples['with navigation'])

const $button = $('.govuk-header__menu-button')

expect($button.text()).toEqual('Menu')
})
it('allows text to be customised', () => {
const $ = render('header', examples['with custom menu button text'])

const $button = $('.govuk-header__menu-button')

expect($button.text()).toEqual('Dewislen')
})
})
})

Expand Down

0 comments on commit fa18951

Please sign in to comment.