Skip to content

Commit 6f2219a

Browse files
committed
feat(ui-date-input): add missing role and aria-label to DateInput2 dialog
INSTUI-4915
1 parent 4615b60 commit 6f2219a

4 files changed

Lines changed: 46 additions & 7 deletions

File tree

packages/ui-date-input/src/DateInput2/README.md

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ type: example
2020
screenReaderLabels={{
2121
calendarIcon: 'Calendar',
2222
nextMonthButton: 'Next month',
23-
prevMonthButton: 'Previous month'
23+
prevMonthButton: 'Previous month',
24+
datePickerDialog: 'Date picker'
2425
}}
2526
value={inputValue}
2627
width="20rem"
@@ -69,7 +70,8 @@ const Example = () => {
6970
screenReaderLabels={{
7071
calendarIcon: 'Calendar',
7172
nextMonthButton: 'Next month',
72-
prevMonthButton: 'Previous month'
73+
prevMonthButton: 'Previous month',
74+
datePickerDialog: 'Date picker'
7375
}}
7476
width="20rem"
7577
value={value}
@@ -82,7 +84,8 @@ const Example = () => {
8284
screenReaderLabels={{
8385
calendarIcon: 'Calendar',
8486
nextMonthButton: 'Next month',
85-
prevMonthButton: 'Previous month'
87+
prevMonthButton: 'Previous month',
88+
datePickerDialog: 'Date picker'
8689
}}
8790
width="20rem"
8891
value={value2}
@@ -96,7 +99,8 @@ const Example = () => {
9699
screenReaderLabels={{
97100
calendarIcon: 'Calendar',
98101
nextMonthButton: 'Next month',
99-
prevMonthButton: 'Previous month'
102+
prevMonthButton: 'Previous month',
103+
datePickerDialog: 'Date picker'
100104
}}
101105
width="20rem"
102106
value={value3}
@@ -147,7 +151,8 @@ type: example
147151
screenReaderLabels={{
148152
calendarIcon: 'Calendar',
149153
nextMonthButton: 'Next month',
150-
prevMonthButton: 'Previous month'
154+
prevMonthButton: 'Previous month',
155+
datePickerDialog: 'Date picker'
151156
}}
152157
value={inputValue}
153158
width="20rem"
@@ -216,7 +221,8 @@ const Example = () => {
216221
screenReaderLabels={{
217222
calendarIcon: 'Calendar',
218223
nextMonthButton: 'Next month',
219-
prevMonthButton: 'Previous month'
224+
prevMonthButton: 'Previous month',
225+
datePickerDialog: 'Date picker'
220226
}}
221227
width="20rem"
222228
value={value}
@@ -257,7 +263,8 @@ const Example = () => {
257263
screenReaderLabels={{
258264
calendarIcon: 'Calendar',
259265
nextMonthButton: 'Next month',
260-
prevMonthButton: 'Previous month'
266+
prevMonthButton: 'Previous month',
267+
datePickerDialog: 'Date picker'
261268
}}
262269
value={inputValue}
263270
locale="en-us"

packages/ui-date-input/src/DateInput2/__tests__/DateInput2.test.tsx

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -416,4 +416,30 @@ describe('<DateInput2 />', () => {
416416
expect(screenreaderMessage).toBeInTheDocument()
417417
expect(screenreaderMessage).toHaveClass(/screenReaderContent/)
418418
})
419+
420+
it('should render date picker dialog with proper role and ARIA label', async () => {
421+
const datePickerLabel = 'Date picker'
422+
423+
render(
424+
<DateInput2
425+
renderLabel="Choose a date"
426+
screenReaderLabels={{
427+
calendarIcon: 'Calendar',
428+
nextMonthButton: 'Next month',
429+
prevMonthButton: 'Previous month',
430+
datePickerDialog: datePickerLabel
431+
}}
432+
value=""
433+
/>
434+
)
435+
436+
const calendarButton = screen.getByRole('button', { name: 'Calendar' })
437+
await userEvent.click(calendarButton)
438+
439+
await waitFor(() => {
440+
const dialog = screen.getByRole('dialog', { name: datePickerLabel })
441+
expect(dialog).toBeInTheDocument()
442+
expect(dialog).toHaveAttribute('aria-label', datePickerLabel)
443+
})
444+
})
419445
})

packages/ui-date-input/src/DateInput2/index.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,7 @@ const DateInput2 = forwardRef(
298298
shouldContainFocus
299299
shouldReturnFocus
300300
shouldCloseOnDocumentClick
301+
screenReaderLabel={screenReaderLabels.datePickerDialog}
301302
>
302303
<Calendar
303304
withYearPicker={withYearPicker}

packages/ui-date-input/src/DateInput2/props.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,15 @@ type DateInput2OwnProps = {
3232
* Specifies the input label.
3333
*/
3434
renderLabel: Renderable
35+
/**
36+
* Accessible labels for the calendar button, month navigation buttons, and date picker dialog.
37+
*/
3538
screenReaderLabels: {
3639
calendarIcon: string
3740
prevMonthButton: string
3841
nextMonthButton: string
42+
// TODO: Make this field required in the next version. Currently optional to avoid breaking change.
43+
datePickerDialog?: string
3944
}
4045
/**
4146
* Specifies the input value.

0 commit comments

Comments
 (0)