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

feat(date-picker): add date picker component #550

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

gregtyler
Copy link
Contributor

Can be initialised in Nunjucks with the mojDatePicker macro, or in JavaScript with the data-module="moj-date-picker" attribute.

Fixes MDS-72

@gregtyler gregtyler added the staging:request Add this label to request a staging environment for a pull request label Jan 3, 2024
Copy link

github-actions bot commented Jan 3, 2024

🚀 Deploying to staging environment

Username: staging, Password: moj

@github-actions github-actions bot added staging:active Automatic label added when the PR is on the staging environment and removed staging:request Add this label to request a staging environment for a pull request labels Jan 3, 2024
Comment on lines +4 to +8
&--fixed-width {
.moj-datepicker-input__wrapper {
width: 215px;
}
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Rather than fixing the width of the wrapper, we should let people set the input width with the existing GDS classes (e.g. govuk-input--width-10)

<div class="moj-datepicker__dialog__navbuttons">
<button class="js-datepicker-prev-year" aria-label="previous year" data-button="button-datepicker-prevyear">
<span class="govuk-visually-hidden">Previous year</span>
<svg focusable="false" class="moj-datepicker-icon" aria-hidden="true" role="img"><use href="/assets/images/icons.stack.svg#double_chevron_left"></use></svg>
Copy link
Contributor Author

Choose a reason for hiding this comment

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

We don't have icons.stack.svg so will need to define these SVGs inline

Datepicker.prototype.createDialogMarkup = function (titleId) {
return `<div class="moj-datepicker__dialog__header ">
<div class="moj-datepicker__dialog__navbuttons">
<button class="js-datepicker-prev-year" aria-label="previous year" data-button="button-datepicker-prevyear">
Copy link
Contributor Author

@gregtyler gregtyler Jan 4, 2024

Choose a reason for hiding this comment

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

js-datepicker-prev-year needs to be moj- namespaced

aria-label isn't needed if <span class="govuk-visually-hidden">Previous year</span> is included below

I don't think data-button="button-datepicker-prevyear" is used

I wonder if we could/should use secondary GDS buttons as a basis here

Comment on lines +399 to +400
// position the dialog
this.dialogElement.style.left = `${this.$input.offsetWidth + 16}px`
Copy link
Contributor Author

@gregtyler gregtyler Jan 4, 2024

Choose a reason for hiding this comment

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

If the button is on the right-hand side of the window, this overflows and stretches the page width (or is inaccessible if in an unscrollable container). We'll need to fix that so it's definitely visible, perhaps by floating it underneath the button in this situation:
image

value: params.value,
autocomplete: "off",
attributes: {
"maxlength": "10",
Copy link
Contributor Author

Choose a reason for hiding this comment

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

GDS advise against creating hard-restrictions for users like this, it should be handled by post-submission validation instead

</button>
</div>

<h2 id="${titleId}" class="moj-datepicker__dialog__title js-datepicker-month-year" aria-live="polite">June 2020</h2>
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This also needs to namespace the js-datepicker-month-year class

<caption class="moj-datepicker__dialog__table-caption">You can use the arrow keys to select a date</caption>
<thead>
<tr>
<th scope="col" abbr="Monday">Mo</th>
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Should probably add aria-label to these to avoid screenreaders announcing "Mo"

// create cell (day)
const cell = document.createElement('td')
const dateButton = document.createElement('button')
dateButton.dataset.form = 'date-select'
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm not sure what .dataset.form is doing here or if it's needed.

We might need to add aria-label to explain what the button does (e.g. "28th January 2024"), but I'm not sure what state of the art is here

Copy link
Contributor Author

@gregtyler gregtyler left a comment

Choose a reason for hiding this comment

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

Some general thoughts:

  • The popup doesn't close on clickaway, which could lead to a violation of WCAG 2.2 Focus Not Obscured
  • If JavaScript isn't available, it doesn't gracefully degrade as the button is still visible. The button should be added by JavaScript rather than in the template HTML.
    • In general, I think the template shouldn't contain form groups, error messages, etc. It should just be {{ govukInput({attributes: {'data-module': 'moj-date-picker'}}) }}
  • Whilst we haven't back-filled it to existing components, we should make sure this has localisation support for all text on release

Can be initialised in Nunjucks with the `mojDatePicker` macro, or in JavaScript with the
`data-module="moj-date-picker"` attribute.

Fixes MDS-72
@github-actions github-actions bot removed the staging:active Automatic label added when the PR is on the staging environment label Jan 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants