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

Add inputmode option to the input component #1527

Merged
merged 2 commits into from
Aug 27, 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
13 changes: 13 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,19 @@

## Unreleased

### Inputmode

Adds the ability to pass an optional [inputmode](https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/inputmode) into the input component

```javascript
govukInput({
inputmode: 'email'
})
```

- [Pull request #1527: Adding inputmode to input component](https://github.com/alphagov/govuk-frontend/pull/1527)


### Fixes

- [Pull request #1512: Update components to only output items when they are defined](https://github.com/alphagov/govuk-frontend/pull/1512).
Expand Down
4 changes: 4 additions & 0 deletions src/govuk/components/input/input.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ params:
type: string
required: false
description: Type of input control to render. Defaults to "text".
- name: inputmode
type: string
require: false
description: Optional value for [inputmode](https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/inputmode).
- name: value
type: string
required: false
Expand Down
1 change: 1 addition & 0 deletions src/govuk/components/input/template.njk
Original file line number Diff line number Diff line change
Expand Up @@ -42,5 +42,6 @@
{%- if describedBy %} aria-describedby="{{ describedBy }}"{% endif %}
{%- if params.autocomplete %} autocomplete="{{ params.autocomplete}}"{% endif %}
{%- if params.pattern %} pattern="{{ params.pattern }}"{% endif %}
{%- if params.inputmode %} inputmode="{{ params.inputmode }}"{% endif %}
{%- for attribute, value in params.attributes %} {{ attribute }}="{{ value }}"{% endfor -%}>
</div>
11 changes: 11 additions & 0 deletions src/govuk/components/input/template.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -341,4 +341,15 @@ describe('Input', () => {
expect($component.attr('autocomplete')).toEqual('postal-code')
})
})

describe('when it includes an inputmode', () => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for adding a test for this 💯

it('renders with an inputmode attached to the input', () => {
const $ = render('input', {
inputmode: 'decimal'
})

const $component = $('.govuk-form-group > .govuk-input')
expect($component.attr('inputmode')).toEqual('decimal')
})
})
})