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

Fix undefined class date input #913

Merged
merged 4 commits into from
Jul 17, 2018
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
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@
the name ‘year’ use any other width than 2 characters
([PR #908])(https://github.com/alphagov/govuk-frontend/pull/908)

- Fix undefined class displaying in date input
([PR #913])(https://github.com/alphagov/govuk-frontend/pull/913)

## 1.1.0 (feature release)

🆕 New features:
Expand Down
2 changes: 1 addition & 1 deletion src/components/date-input/template.njk
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@
classes: "govuk-date-input__label"
},
id: item.id if item.id else (params.id + "-" + item.name),
classes: "govuk-date-input__input " + inputWidthClass + item.classes,
classes: "govuk-date-input__input " + inputWidthClass + (item.classes if item.classes),
name: (params.name + "-" + item.name) if params.name else item.name,
value: item.value,
type: "number",
Expand Down
49 changes: 49 additions & 0 deletions src/components/date-input/template.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,55 @@ describe('Date input', () => {
expect(htmlWithClassName($, '.govuk-fieldset')).toMatchSnapshot()
})

it('can have classes for individual items', () => {
const $ = render('date-input', {
items: [
{
'name': 'day',
'classes': 'app-date-input__day'
},
{
'name': 'month',
'classes': 'app-date-input__month'
},
{
'name': 'year',
'classes': 'app-date-input__year'
}
]
})

const $dayInput = $('[name="day"]')
const $monthInput = $('[name="month"]')
const $yearInput = $('[name="year"]')
expect($dayInput.hasClass('app-date-input__day')).toBeTruthy()
expect($monthInput.hasClass('app-date-input__month')).toBeTruthy()
expect($yearInput.hasClass('app-date-input__year')).toBeTruthy()
})

it('does not set classes as undefined if none are defined', () => {
const $ = render('date-input', {
items: [
{
'name': 'day'
},
{
'name': 'month'
},
{
'name': 'year'
}
]
})

const $dayInput = $('[name="day"]')
const $monthInput = $('[name="month"]')
const $yearInput = $('[name="year"]')
expect($dayInput.hasClass('undefined')).toBeFalsy()
expect($monthInput.hasClass('undefined')).toBeFalsy()
expect($yearInput.hasClass('undefined')).toBeFalsy()
})

// https://github.com/alphagov/govuk-frontend/issues/905
describe('to maintain backwards compatibility', () => {
it('automatically sets width for the day input if no width class provided', () => {
Expand Down