Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add heading level option to label component called headingLevel #5240

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions packages/govuk-frontend/src/govuk/components/label/label.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,11 @@ examples:
options:
text: National Insurance number
isPageHeading: true
- name: as page heading with defined heading level
options:
text: National Insurance number
isPageHeading: true
headingLevel: 2

# Hidden examples are not shown in the review app, but are used for tests and HTML fixtures
- name: empty
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,12 @@
{% endset -%}

{% if params.isPageHeading %}
<h1 class="govuk-label-wrapper">
{#- Optional. The page heading level(1-6) to be used with ``isPageHeading` defaults to heading level 1-#}
{% set headingLevel = params.headingLevel if params.headingLevel else 1 %}

<h{{ headingLevel }} class="govuk-label-wrapper">
{{ labelHtml | safe | trim | indent(2) }}
</h1>
</h{{ headingLevel }}>
{% else %}
{{ labelHtml | safe | trim }}
{% endif %}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,13 @@ describe('Label', () => {
expect($selector.length).toBeTruthy()
})

it('can be nested inside an heading tag using isPageHeading and headingLevel', () => {
const $ = render('label', examples['as page heading with defined level'])

const $selector = $('h2 > .govuk-label')
expect($selector.length).toBeTruthy()
})

it('allows additional attributes to be added to the component', () => {
const $ = render('label', examples.attributes)

Expand Down