ba-input-date
A form field for entering dates
Airframe
Web Components
React
React Native
Anatomy
Date label
A short, descriptive text that identifies the group of inputs and the date the user is being asked to enter
Field labels
The DD, MM and YYYY labels above each input that indicate the expected format for the day, month and year
Input fields
The separate day, month and year fields where users enter each portion of the date
Design Documentation
This component can be used for entering a range of different date types such as dates of births, credit/debit expiries and other dates.
Live Demo
<ba-input-date
legend="Date of Birth"
name="dateOfBirth"
required
></ba-input-date>
Properties and attributes
| Property | Attribute | Description | Type | Default |
|---|---|---|---|---|
autocompleteDay |
autocomplete-day |
Indicates whether the value of the control can be automatically completed by the browser. Valid values are 'on' or 'off' but Chrome ignores 'off' so we use another value to disable autocomplete. |
string | undefined |
'null' |
autocompleteMonth |
autocomplete-month |
Indicates whether the value of the control can be automatically completed by the browser. Valid values are 'on' or 'off' but Chrome ignores 'off' so we use another value to disable autocomplete. |
string | undefined |
'null' |
autocompleteYear |
autocomplete-year |
Indicates whether the value of the control can be automatically completed by the browser. Valid values are 'on' or 'off' but Chrome ignores 'off' so we use another value to disable autocomplete. |
string | undefined |
'null' |
dayLabel |
day-label |
Label text for the day field | string | undefined |
undefined |
ignoreDay |
ignore-day |
If true then the day input will not be displayed. | boolean | undefined |
false |
inputId |
input-id |
ID for the host and also used in IDs for the child inputs. Randomised value used as fallback but an id value should always be given in the application. | string | undefined |
`id${Math.round(
Math.random() * 1e10
)}` |
invalid |
invalid |
If true then the error will be displayed. | boolean | undefined |
false |
legend(required) |
legend |
Text for the legend | string |
undefined |
monthLabel |
month-label |
Label text for the month field | string | undefined |
undefined |
name(required) |
name |
The name of the input | string |
undefined |
required |
required |
If the input is required | boolean | undefined |
false |
value |
value |
The value of the input. | null | string | undefined |
'' |
yearDigits |
year-digits |
The number of digits for the year field. | number | undefined |
4 |
yearLabel |
year-label |
Label text for the year field | string | undefined |
undefined |
Permitted ARIA roles
- None
Slots
| Slot | Description | Permitted elements |
|---|---|---|
"error" |
Text to show in an error message | <p> |
Parent components
ba-input-date can be slotted into:
<ba‑grid><ba‑form‑group‑dropdown><ba‑form‑group><ba‑form><ba‑flex><ba‑details><ba‑card‑segmented><ba‑card><ba‑accordion>
Events
| Event | Description | Type |
|---|---|---|
baBlur |
Emitted when the input loses focus. | CustomEvent<void> |
baChange |
Emitted when the value has changed. | CustomEvent<InputDateChangeEventDetail> |
baFocus |
Emitted when the input has focus. | CustomEvent<void> |
Methods
isValid() => Promise<boolean>
An exposed method for triggering the inputs required validation
reset() => Promise<void>
Resets the input back to its initial value
Returns
Type: Promise<void>
Usage
Basic usage
Most scenarios will only require the legend attribute and the required attribute.
<ba-input-date
legend="Date of Birth"
required
></ba-input-date>
Card expiry usage
Use year-digits and ignore-day together with the relevant autocomplete settings for card expiry details.
<ba-input-date
legend="Card Expiry"
year-digits="2"
ignore-day
autocomplete-month="cc-exp-month"
autocomplete-year="cc-exp-year"
required
></ba-input-date>
Error messages
It is sometimes useful to add custom validation messages. For example you may wish to:
- Add translations
- Provide more detail and/or contextual advice
- Add links to further information on the error
BAgel provides error messages with translations for:
- required
- numeric
- 30 day month
- leap years
- february
<ba-input-date
legend="Date of Birth"
required
>
<p slot="error">We need to know this. <a href="#">Why we need to know</a>
</p>
</ba-input-date>
Guidelines
The legend text helps users of assistive technologies understand that this component is a group of related form fields.
Disabled form elements are not supported in BAgel because they create accessibility challenges, such as preventing keyboard navigation, confusing screen reader users, and reducing visual clarity for those with impairments
Further reading:
The autocomplete attribute can be set for each of the inputs (day, month and year). This helps the user by allowing the browser to suggest saved details.
Some screen readers (NVDA) may interpret abbreviations like "MM" using their own pronunciation rules and read it as "millimetres." This behaviour comes from the assistive technology rather than the component, and forcing custom pronunciation is not recommended. Providing clear contextual labels (for example, including "month" alongside "MM") helps ensure the field remains understandable across screen readers.
Further reading:
Keyboard navigation
State: Previous element in DOM has focus
Moves focus to the day input
State: Day input has focus
Moves focus to the month input
Moves focus to the previous focusable element
State: Month input has focus
Moves focus to the year input
Moves focus back to the day input
State: Year input has focus
Moves focus to the next focusable element
Moves focus back to the month input
Usage and accessibility checklist
Use this checklist to confirm the component has been configured and used correctly.
UX checklist
- ba-input-date is used for entering full dates such as dates of birth, card expiry, and other dates
- year-digits and ignore-day are used to adapt the component for shortened dates such as card expiry (MM/YY)
- A concise and descriptive legend has been provided for the group of inputs
- Required fields are marked with the required attribute
- The correct autocomplete settings are applied to the day, month, and year inputs
Accessibility checklist
- A meaningful legend is provided to describe the group of day, month, and year inputs
- The correct autocomplete attribute is set for each input so the browser can suggest saved details
- Error messages are descriptive and explain how to resolve the validation failure
- The inputs have not been disabled
- The focus indicator has not been obscured on all sides of the component
These checks are handled by the component and do not need to be repeated each time it is used.
- Contextual labels are provided so abbreviations such as "MM" remain understandable across screen readers
- ba-input-date is operable using assistive technology
- The field is keyboard operable and receives a visible focus indicator
- Colour contrast for all states in all BAgel themes
- High contrast mode adjustments