Skip to content

Commit

Permalink
Simplify button types to avoid unnecessary type attribute
Browse files Browse the repository at this point in the history
The button element as an implicit type of submit if it it's not set, since this is what most people need this change reduces a bit of markup for people to copy and paste.
  • Loading branch information
NickColley committed Aug 28, 2019
1 parent bc86463 commit c0d8615
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 4 deletions.
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

0 comments on commit c0d8615

Please sign in to comment.