From c0d8615d2a54f00704301f6c9b0f95c2954f8b07 Mon Sep 17 00:00:00 2001 From: Nick Colley Date: Wed, 28 Aug 2019 11:20:36 +0100 Subject: [PATCH 1/2] Simplify button types to avoid unnecessary type attribute 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. --- src/govuk/components/button/template.njk | 6 +++--- src/govuk/components/button/template.test.js | 1 - 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/src/govuk/components/button/template.njk b/src/govuk/components/button/template.njk index 26d21fc81c..613489a25d 100644 --- a/src/govuk/components/button/template.njk +++ b/src/govuk/components/button/template.njk @@ -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! #} @@ -49,12 +49,12 @@ treat it as an interactive element - without this it will be {%- elseif element == 'button' %} - {%- elseif element == 'input' %} - + {%- endif %} diff --git a/src/govuk/components/button/template.test.js b/src/govuk/components/button/template.test.js index 41b813dfbe..4081929e41 100644 --- a/src/govuk/components/button/template.test.js +++ b/src/govuk/components/button/template.test.js @@ -256,7 +256,6 @@ describe('Button', () => { const $component = $('.govuk-button') expect($component.get(0).tagName).toEqual('button') - expect($component.attr('type')).toEqual('submit') }) }) From f7c8917b9b757b228878def03596b347b9eb8e4e Mon Sep 17 00:00:00 2001 From: Nick Colley Date: Wed, 28 Aug 2019 11:55:05 +0100 Subject: [PATCH 2/2] Update CHANGELOG --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1ec7b2ccd7..4f71f90ded 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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)