Skip to content

[v10] Add date input day, month and year options#1869

Open
colinrotherham wants to merge 3 commits intosupport/10.xfrom
date-input-fields
Open

[v10] Add date input day, month and year options#1869
colinrotherham wants to merge 3 commits intosupport/10.xfrom
date-input-fields

Conversation

@colinrotherham
Copy link
Copy Markdown
Contributor

Description

This PR adds individual date input Nunjucks options per field

Closes #1853

Checklist

@colinrotherham colinrotherham temporarily deployed to nhsuk-frontend-pr-1869 March 24, 2026 08:26 Inactive
@colinrotherham colinrotherham changed the base branch from main to support/10.x March 24, 2026 08:27
@colinrotherham colinrotherham temporarily deployed to nhsuk-frontend-pr-1869 March 24, 2026 08:28 Inactive
@colinrotherham colinrotherham temporarily deployed to nhsuk-frontend-pr-1869 March 24, 2026 08:31 Inactive
@colinrotherham
Copy link
Copy Markdown
Contributor Author

colinrotherham commented Mar 24, 2026

I've gone with this syntax:

{{ dateInput({
  fieldset: {
    legend: {
      text: "What is your date of birth?",
      size: "l",
      isPageHeading: true
    }
  },
  year: {
    value: "2025"
    error: true
  },
  values: {
    year: "1984"
  }
}) }}

But which values wins?

We currently prioritise the items[] item.value over values so 2025 is the year value

E.g. We've had this line in the Nunjucks template for a while:

value: item.value or params.values[item.name],

So I've assumed this behaviour should stay, with values set in this priority order:

  1. When items is set with value(s)
  2. When day, month, or year have value(s)
  3. When values is set with values(s)

We do something similar in radios/checkboxes where items[] item.checked overrides values

@frankieroberto
Copy link
Copy Markdown
Contributor

@colinrotherham that priority order makes sense to me. There's also the option of not supporting day.value at all, in order to just limit it to 2 ways to set the value. But I don't think supporting the 3rd way does much harm.

For prototyping at least, I'd expect values to be set using values: data.dateOfBirth and then the day, month and year keys to be used only if you need to change the label or set the error state, or the autocomplete value (day: { autocomplete: 'bday-day } ).

@colinrotherham colinrotherham changed the base branch from support/10.x to macro-options-info March 24, 2026 14:10
@colinrotherham colinrotherham temporarily deployed to nhsuk-frontend-pr-1869 March 24, 2026 14:18 Inactive
Copy link
Copy Markdown
Contributor

@frankieroberto frankieroberto left a comment

Choose a reason for hiding this comment

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

Looks good to me. This’ll make using the date input component in prototypes a lot easier.

@colinrotherham
Copy link
Copy Markdown
Contributor Author

Thanks! Happy for this to go in v10.5.0 with icon buttons and search input?

@frankieroberto
Copy link
Copy Markdown
Contributor

Thanks! Happy for this to go in v10.5.0 with icon buttons and search input?

Yep. It’s entirely backwards-compatible.

@edwardhorsford
Copy link
Copy Markdown
Contributor

I agree with the base idea of this, but unsure we should immediately merge this, and wonder if we should think on it for a bit.

@anandamaryon1 any thoughts?

@sonarqubecloud
Copy link
Copy Markdown

Base automatically changed from macro-options-info to support/10.x March 24, 2026 16:06
@anandamaryon1
Copy link
Copy Markdown
Contributor

I like how it abstracts away lots of the code for individual items. Seems much cleaner and more bespoke.

I don't really grasp why the standalone value is still needed if each has it's own value anyway?

And not sure why we still need items if we're now naming them each as options, is that for backwards-compatibility? Or flexibility?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Needs review

Development

Successfully merging this pull request may close these issues.

Proposal: support day, month and year params in Date input

4 participants