Skip to content

Commit

Permalink
feat: datepicker: focus trap to datepicker components to enhance keyb…
Browse files Browse the repository at this point in the history
…oard accessibility. (#901)

* feat: datepicker: add datepicker a11y support

* feat: datepicker : updated buttons press for datepicker

* feat: datepicker : updated test snapshots

* feat: datepicker : updated test snapshots

* fix: locale update

* fix: test

* fix: adding focustrap by default

---------

Co-authored-by: Samual Krish Ravichandran <sravichandran@eightfold.ai>
  • Loading branch information
1 parent 34a3a08 commit 9477592
Show file tree
Hide file tree
Showing 69 changed files with 2,018 additions and 45 deletions.
28 changes: 28 additions & 0 deletions src/components/DateTimePicker/DatePicker/DatePicker.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import DatePicker, { DatePickerShape, DatePickerSize } from './';
import type { DatePickerProps, RangePickerProps } from './';
import { ButtonVariant } from '../../Button';
import { Stack } from '../../Stack';
import { ConfigProvider } from '../../ConfigProvider';

export default {
title: 'Date Picker',
Expand Down Expand Up @@ -94,6 +95,26 @@ const Single_Picker_Story: ComponentStory<typeof DatePicker> = (args) => {
console.log(date, dateString);
};

return (
<ConfigProvider themeOptions={{ name: 'blue' }}>
<Stack direction="vertical" flexGap="m">
<DatePicker {...args} onChange={onChange} />
<DatePicker {...args} onChange={onChange} picker="week" />
<DatePicker {...args} onChange={onChange} picker="month" />
<DatePicker {...args} onChange={onChange} picker="quarter" />
<DatePicker {...args} onChange={onChange} picker="year" />
</Stack>
</ConfigProvider>
);
};

const Single_Picker_TrapFocus_Story: ComponentStory<typeof DatePicker> = (
args
) => {
const onChange: DatePickerProps['onChange'] = (date, dateString) => {
console.log(date, dateString);
};

return (
<Stack direction="vertical" flexGap="m">
<DatePicker {...args} onChange={onChange} />
Expand Down Expand Up @@ -537,6 +558,7 @@ const Range_Status_Story: ComponentStory<typeof RangePicker> = (args) => {
};

export const Single_Picker = Single_Picker_Story.bind({});
export const Single_Picker_TrapFocus = Single_Picker_TrapFocus_Story.bind({});
export const Single_Picker_Readonly = Single_Picker_Readonly_Story.bind({});
export const Single_Picker_Disabled = Single_Picker_Disabled_Story.bind({});
export const Single_Picker_Disabled_Date_and_Time =
Expand Down Expand Up @@ -572,6 +594,7 @@ export const Range_Status = Range_Status_Story.bind({});
// See https://www.npmjs.com/package/babel-plugin-named-exports-order
export const __namedExportsOrder = [
'Single_Picker',
'Single_Picker_TrapFocus',
'Single_Picker_Readonly',
'Single_Picker_Disabled',
'Single_Picker_Disabled_Date_and_Time',
Expand Down Expand Up @@ -613,6 +636,11 @@ const pickerArgs: Object = {

Single_Picker.args = {
...pickerArgs,
trapFocus: false,
};

Single_Picker_TrapFocus.args = {
...pickerArgs,
};

Single_Picker_Readonly.args = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ export default function generatePicker<DateType>(
todayButtonProps,
todayActive = true,
todayText: defaultTodayText,
trapFocus = true,
...rest
} = props;
const largeScreenActive: boolean = useMatchMedia(Breakpoints.Large);
Expand Down Expand Up @@ -263,6 +264,7 @@ export default function generatePicker<DateType>(
superPrevIcon={IconName.mdiChevronDoubleLeft}
superNextIcon={IconName.mdiChevronDoubleRight}
allowClear
trapFocus={trapFocus}
{...rest}
{...additionalOverrideProps}
locale={locale!.lang}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ $picker-time-partial-cell-height: 28px;
&-in-view.picker-cell-range-start,
&-in-view.picker-cell-range-end {
background: var(--picker-cell-background-color-active);
border: 1px solid var(--picker-cell-border-color-active);
color: var(--picker-cell-foreground-color-active);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,13 @@ LoadedCheerio {
"children": Array [
Node {
"attribs": Object {
"aria-controls": "dp-dialog-1",
"aria-expanded": "false",
"aria-haspopup": "dialog",
"autocomplete": "off",
"placeholder": "Select date",
"readonly": "",
"role": "combobox",
"size": "12",
"title": "2000-01-01",
"value": "2000-01-01",
Expand Down Expand Up @@ -213,17 +217,25 @@ LoadedCheerio {
"prev": null,
"type": "tag",
"x-attribsNamespace": Object {
"aria-controls": undefined,
"aria-expanded": undefined,
"aria-haspopup": undefined,
"autocomplete": undefined,
"placeholder": undefined,
"readonly": undefined,
"role": undefined,
"size": undefined,
"title": undefined,
"value": undefined,
},
"x-attribsPrefix": Object {
"aria-controls": undefined,
"aria-expanded": undefined,
"aria-haspopup": undefined,
"autocomplete": undefined,
"placeholder": undefined,
"readonly": undefined,
"role": undefined,
"size": undefined,
"title": undefined,
"value": undefined,
Expand Down Expand Up @@ -407,9 +419,13 @@ LoadedCheerio {
"parent": [Circular],
"prev": Node {
"attribs": Object {
"aria-controls": "dp-dialog-1",
"aria-expanded": "false",
"aria-haspopup": "dialog",
"autocomplete": "off",
"placeholder": "Select date",
"readonly": "",
"role": "combobox",
"size": "12",
"title": "2000-01-01",
"value": "2000-01-01",
Expand All @@ -422,17 +438,25 @@ LoadedCheerio {
"prev": null,
"type": "tag",
"x-attribsNamespace": Object {
"aria-controls": undefined,
"aria-expanded": undefined,
"aria-haspopup": undefined,
"autocomplete": undefined,
"placeholder": undefined,
"readonly": undefined,
"role": undefined,
"size": undefined,
"title": undefined,
"value": undefined,
},
"x-attribsPrefix": Object {
"aria-controls": undefined,
"aria-expanded": undefined,
"aria-haspopup": undefined,
"autocomplete": undefined,
"placeholder": undefined,
"readonly": undefined,
"role": undefined,
"size": undefined,
"title": undefined,
"value": undefined,
Expand Down Expand Up @@ -612,9 +636,13 @@ LoadedCheerio {
"parent": [Circular],
"prev": Node {
"attribs": Object {
"aria-controls": "dp-dialog-1",
"aria-expanded": "false",
"aria-haspopup": "dialog",
"autocomplete": "off",
"placeholder": "Select date",
"readonly": "",
"role": "combobox",
"size": "12",
"title": "2000-01-01",
"value": "2000-01-01",
Expand All @@ -627,17 +655,25 @@ LoadedCheerio {
"prev": null,
"type": "tag",
"x-attribsNamespace": Object {
"aria-controls": undefined,
"aria-expanded": undefined,
"aria-haspopup": undefined,
"autocomplete": undefined,
"placeholder": undefined,
"readonly": undefined,
"role": undefined,
"size": undefined,
"title": undefined,
"value": undefined,
},
"x-attribsPrefix": Object {
"aria-controls": undefined,
"aria-expanded": undefined,
"aria-haspopup": undefined,
"autocomplete": undefined,
"placeholder": undefined,
"readonly": undefined,
"role": undefined,
"size": undefined,
"title": undefined,
"value": undefined,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,13 @@ LoadedCheerio {
"children": Array [
Node {
"attribs": Object {
"aria-controls": "dp-dialog-1",
"aria-expanded": "false",
"aria-haspopup": "dialog",
"autocomplete": "off",
"placeholder": "Select date",
"readonly": "",
"role": "combobox",
"size": "21",
"title": "2000-01-01 00:00:00",
"value": "2000-01-01 00:00:00",
Expand Down Expand Up @@ -213,17 +217,25 @@ LoadedCheerio {
"prev": null,
"type": "tag",
"x-attribsNamespace": Object {
"aria-controls": undefined,
"aria-expanded": undefined,
"aria-haspopup": undefined,
"autocomplete": undefined,
"placeholder": undefined,
"readonly": undefined,
"role": undefined,
"size": undefined,
"title": undefined,
"value": undefined,
},
"x-attribsPrefix": Object {
"aria-controls": undefined,
"aria-expanded": undefined,
"aria-haspopup": undefined,
"autocomplete": undefined,
"placeholder": undefined,
"readonly": undefined,
"role": undefined,
"size": undefined,
"title": undefined,
"value": undefined,
Expand Down Expand Up @@ -407,9 +419,13 @@ LoadedCheerio {
"parent": [Circular],
"prev": Node {
"attribs": Object {
"aria-controls": "dp-dialog-1",
"aria-expanded": "false",
"aria-haspopup": "dialog",
"autocomplete": "off",
"placeholder": "Select date",
"readonly": "",
"role": "combobox",
"size": "21",
"title": "2000-01-01 00:00:00",
"value": "2000-01-01 00:00:00",
Expand All @@ -422,17 +438,25 @@ LoadedCheerio {
"prev": null,
"type": "tag",
"x-attribsNamespace": Object {
"aria-controls": undefined,
"aria-expanded": undefined,
"aria-haspopup": undefined,
"autocomplete": undefined,
"placeholder": undefined,
"readonly": undefined,
"role": undefined,
"size": undefined,
"title": undefined,
"value": undefined,
},
"x-attribsPrefix": Object {
"aria-controls": undefined,
"aria-expanded": undefined,
"aria-haspopup": undefined,
"autocomplete": undefined,
"placeholder": undefined,
"readonly": undefined,
"role": undefined,
"size": undefined,
"title": undefined,
"value": undefined,
Expand Down Expand Up @@ -612,9 +636,13 @@ LoadedCheerio {
"parent": [Circular],
"prev": Node {
"attribs": Object {
"aria-controls": "dp-dialog-1",
"aria-expanded": "false",
"aria-haspopup": "dialog",
"autocomplete": "off",
"placeholder": "Select date",
"readonly": "",
"role": "combobox",
"size": "21",
"title": "2000-01-01 00:00:00",
"value": "2000-01-01 00:00:00",
Expand All @@ -627,17 +655,25 @@ LoadedCheerio {
"prev": null,
"type": "tag",
"x-attribsNamespace": Object {
"aria-controls": undefined,
"aria-expanded": undefined,
"aria-haspopup": undefined,
"autocomplete": undefined,
"placeholder": undefined,
"readonly": undefined,
"role": undefined,
"size": undefined,
"title": undefined,
"value": undefined,
},
"x-attribsPrefix": Object {
"aria-controls": undefined,
"aria-expanded": undefined,
"aria-haspopup": undefined,
"autocomplete": undefined,
"placeholder": undefined,
"readonly": undefined,
"role": undefined,
"size": undefined,
"title": undefined,
"value": undefined,
Expand Down
Loading

0 comments on commit 9477592

Please sign in to comment.