Skip to content

Commit

Permalink
Make button element the default for the macro component
Browse files Browse the repository at this point in the history
Only allow `input` to be used when explicitly asking to use it.

See alphagov/govuk_elements#593
  • Loading branch information
NickColley committed May 8, 2018
1 parent c01b383 commit 14ff765
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 46 deletions.
10 changes: 5 additions & 5 deletions src/button/button.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,15 @@ examples:
text: Start now link button
href: /
classes: 'govuk-button--start'
- name: explicit-button
- name: explicit-input-button
data:
element: button
element: input
name: start-now
text: Start now
- name: explicit-button-disabled
- name: explicit-input-button-disabled
data:
element: button
text: Explicit button disabled
element: input
text: Explicit input button disabled
disabled: true
- name: button-active-state
description: Simulate triggering the :active CSS pseudo-class, not available in the production build.
Expand Down
4 changes: 1 addition & 3 deletions src/button/template.njk
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,8 @@
{% else %}
{% if params.href %}
{% set element = 'a' %}
{% elseif params.html %}
{% set element = 'button' %}
{% else %}
{% set element = 'input' %}
{% set element = 'button' %}
{% endif %}
{% endif %}

Expand Down
75 changes: 37 additions & 38 deletions src/button/template.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,18 @@ describe('Button', () => {
expect(results).toHaveNoViolations()
})

describe('input[type=submit]', () => {
describe('button element', () => {
it('renders the default example', () => {
const $ = render('button', examples.default)

const $component = $('.govuk-button')
expect($component.get(0).tagName).toEqual('input')
expect($component.attr('type')).toEqual('submit')
expect($component.val()).toEqual('Save and continue')
expect($component.get(0).tagName).toEqual('button')
expect($component.text()).toContain('Save and continue')
})

it('renders with attributes', () => {
const $ = render('button', {
element: 'input',
element: 'button',
attributes: {
'aria-controls': 'example-id',
'data-tracking-dimension': '123'
Expand All @@ -40,7 +39,7 @@ describe('Button', () => {

it('renders with classes', () => {
const $ = render('button', {
element: 'input',
element: 'button',
classes: 'app-button--custom-modifier'
})

Expand All @@ -59,7 +58,7 @@ describe('Button', () => {

it('renders with name', () => {
const $ = render('button', {
element: 'input',
element: 'button',
name: 'start-now'
})

Expand All @@ -69,7 +68,7 @@ describe('Button', () => {

it('renders with type', () => {
const $ = render('button', {
element: 'input',
element: 'button',
type: 'button'
})

Expand Down Expand Up @@ -102,6 +101,26 @@ describe('Button', () => {
expect($component.attr('href')).toEqual('#')
})

it('renders with value', () => {
const $ = render('button', {
element: 'button',
value: 'start'
})

const $component = $('.govuk-button')
expect($component.attr('value')).toEqual('start')
})

it('renders with html', () => {
const $ = render('button', {
element: 'button',
html: 'Start <em>now</em>'
})

const $component = $('.govuk-button')
expect($component.html()).toContain('Start <em>now</em>')
})

it('renders with attributes', () => {
const $ = render('button', {
element: 'a',
Expand Down Expand Up @@ -134,18 +153,18 @@ describe('Button', () => {
})
})

describe('with explicit button set by "element"', () => {
describe('with explicit input button set by "element"', () => {
it('renders with anchor, href and an accessible role of button', () => {
const $ = render('button', examples['explicit-button'])
const $ = render('button', examples['explicit-input-button'])

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

it('renders with attributes', () => {
const $ = render('button', {
element: 'button',
element: 'input',
attributes: {
'aria-controls': 'example-id',
'data-tracking-dimension': '123'
Expand All @@ -159,7 +178,7 @@ describe('Button', () => {

it('renders with classes', () => {
const $ = render('button', {
element: 'button',
element: 'input',
classes: 'app-button--custom-modifier'
})

Expand All @@ -169,7 +188,7 @@ describe('Button', () => {

it('renders with disabled', () => {
const $ = render('button', {
element: 'button',
element: 'input',
disabled: true
})

Expand All @@ -181,37 +200,17 @@ describe('Button', () => {

it('renders with name', () => {
const $ = render('button', {
element: 'button',
element: 'input',
name: 'start-now'
})

const $component = $('.govuk-button')
expect($component.attr('name')).toEqual('start-now')
})

it('renders with value', () => {
const $ = render('button', {
element: 'button',
value: 'start'
})

const $component = $('.govuk-button')
expect($component.attr('value')).toEqual('start')
})

it('renders with html', () => {
const $ = render('button', {
element: 'button',
html: 'Start <em>now</em>'
})

const $component = $('.govuk-button')
expect($component.html()).toContain('Start <em>now</em>')
})

it('renders with type', () => {
const $ = render('button', {
element: 'button',
element: 'input',
type: 'button',
text: 'Start now'
})
Expand Down Expand Up @@ -240,11 +239,11 @@ describe('Button', () => {
expect($component.get(0).tagName).toEqual('button')
})

it('renders an input[type=submit] if you don\'t pass anything', () => {
it('renders a button if you don\'t pass anything', () => {
const $ = render('button', {})

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

0 comments on commit 14ff765

Please sign in to comment.