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

Adding optional id attribute to button component #3344

Merged
Merged
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
13 changes: 13 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,19 @@ If you're not using the Nunjucks macro, you can disable it using the `data-remem

This was added in [pull request #3342: Add option to disable sessionState in Accordion](https://github.com/alphagov/govuk-frontend/pull/3342).

#### Added `id` parameter to Buttons

The [Button](https://design-system.service.gov.uk/components/button/) Nunjucks macro has been updated to include an optional `id` parameter.

```nunjucks
{{ govukButton({
text: "Save and continue",
id: "continue-button"
}) }}
```

This was added in [pull request #3344: Adding optional id attribute to button component](https://github.com/alphagov/govuk-frontend/pull/3344). Thanks to [Tom Billington](https://github.com/TomBillingtonUK) for this contribution.

### Deprecated features

#### Stop using the `govuk-button--disabled` class on buttons
Expand Down
10 changes: 10 additions & 0 deletions src/govuk/components/button/button.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ params:
type: boolean
required: false
description: Use for the main call to action on your service's start page.
- name: id
type: string
required: false
description: The ID of the button.

examples:
- name: default
Expand Down Expand Up @@ -242,3 +246,9 @@ examples:
data:
text: Submit
preventDoubleClick: false
- name: id
hidden: true
data:
text: Submit
element: input
id: submit
2 changes: 1 addition & 1 deletion src/govuk/components/button/template.njk
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ treat it as an interactive element - without this it will be

{#- Define common attributes that we can use across all element types #}

{%- set commonAttributes %} class="{{ classNames }}" data-module="govuk-button"{% for attribute, value in params.attributes %} {{attribute}}="{{value}}"{% endfor %}{% endset %}
{%- set commonAttributes %} class="{{ classNames }}" data-module="govuk-button"{% for attribute, value in params.attributes %} {{attribute}}="{{value}}"{% endfor %}{% if params.id %} id="{{ params.id }}"{% endif %}{% endset %}

{#- Define common attributes we can use for both button and input types #}

Expand Down
7 changes: 7 additions & 0 deletions src/govuk/components/button/template.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,13 @@ describe('Button', () => {
expect($component.attr('name')).toEqual('start-now')
})

it('renders with id', () => {
const $ = render('button', examples.id)

const $component = $('.govuk-button')
expect($component.attr('id')).toEqual('submit')
})

it('renders with value', () => {
const $ = render('button', examples.value)

Expand Down