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

Simplify button types to avoid unnecessary type attribute #1538

Merged
merged 2 commits into from
Aug 28, 2019
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ govukInput({
### Fixes

- [Pull request #1512: Update components to only output items when they are defined](https://github.com/alphagov/govuk-frontend/pull/1512).
- [Pull request #1538: Simplify button types to avoid unnecessary type attribute](https://github.com/alphagov/govuk-frontend/pull/1538).

## 3.0.0 (Breaking release)

Expand Down
6 changes: 3 additions & 3 deletions src/govuk/components/button/template.njk
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ treat it as an interactive element - without this it will be

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

{%- set buttonAttributes %}{% if params.name %} name="{{ params.name }}"{% endif %} type="{{ params.type if params.type else 'submit' }}"{% if params.disabled %} disabled="disabled" aria-disabled="true"{% endif %}{% if params.preventDoubleClick %} data-prevent-double-click="true"{% endif %}{% endset %}
{%- set buttonAttributes %}{% if params.name %} name="{{ params.name }}"{% endif %}{% if params.disabled %} disabled="disabled" aria-disabled="true"{% endif %}{% if params.preventDoubleClick %} data-prevent-double-click="true"{% endif %}{% endset %}

{#- Actually create a button... or a link! #}

Expand All @@ -49,12 +49,12 @@ treat it as an interactive element - without this it will be
</a>

{%- elseif element == 'button' %}
<button {%- if params.value %} value="{{ params.value }}"{% endif %} {{- buttonAttributes | safe }} {{- commonAttributes | safe }}>
<button {%- if params.value %} value="{{ params.value }}"{% endif %}{%- if params.type %} type="{{ params.type }}"{% endif %} {{- buttonAttributes | safe }} {{- commonAttributes | safe }}>
{{ params.html | safe if params.html else params.text }}
{# Indentation is intentional to output HTML nicely #}
{{- iconHtml | safe | trim | indent(2, true) if iconHtml -}}
</button>

{%- elseif element == 'input' %}
<input value="{{ params.text }}" {{- buttonAttributes | safe }} {{- commonAttributes | safe }}>
<input value="{{ params.text }}" type="{{ params.type if params.type else 'submit' }}" {{- buttonAttributes | safe }} {{- commonAttributes | safe }}>
{%- endif %}
1 change: 0 additions & 1 deletion src/govuk/components/button/template.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,6 @@ describe('Button', () => {

const $component = $('.govuk-button')
expect($component.get(0).tagName).toEqual('button')
expect($component.attr('type')).toEqual('submit')
})
})

Expand Down