Skip to content

Commit

Permalink
[Datepicker] - Fixed a11y violations (#14406)
Browse files Browse the repository at this point in the history
* fix: fixed a11y issues in the avt.e2e tests

* test: updated snapshot
  • Loading branch information
guidari committed Aug 11, 2023
1 parent e28dfdd commit 7d2924a
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 6 deletions.
4 changes: 2 additions & 2 deletions e2e/components/DatePicker/DatePicker-test.avt.e2e.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ test.describe('DatePicker @avt', () => {
});

// skipping for now due to accessibility violation
test.skip('skeleton state @avt', async ({ page }) => {
test('skeleton state @avt', async ({ page }) => {
await visitStory(page, {
component: 'DatePicker',
id: 'components-datepicker--skeleton',
Expand All @@ -63,7 +63,7 @@ test.describe('DatePicker @avt', () => {
});

// skipping for now due to accessibility violation
test.skip('open state @avt', async ({ page }) => {
test('open state @avt', async ({ page }) => {
await visitStory(page, {
component: 'DatePicker',
id: 'components-datepicker--playground',
Expand Down
3 changes: 3 additions & 0 deletions packages/react/__tests__/__snapshots__/PublicAPI-test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -2783,6 +2783,9 @@ Map {
"className": Object {
"type": "string",
},
"hideLabel": Object {
"type": "bool",
},
"id": Object {
"type": "string",
},
Expand Down
16 changes: 12 additions & 4 deletions packages/react/src/components/DatePicker/DatePicker.Skeleton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,24 @@ export interface DatePickerSkeletonProps
extends HTMLAttributes<HTMLDivElement> {
// Specify whether the skeleton should be of range date picker.
range?: boolean;

/**
* Specify whether the label should be hidden, or not
*/
hideLabel?: boolean;
}

const DatePickerSkeleton = ({
range,
id,
hideLabel,
className,
...rest
}: DatePickerSkeletonProps) => {
const prefix = usePrefix();
const dateInput = (
<div className={`${prefix}--date-picker-container`}>
{
/* eslint-disable jsx-a11y/label-has-for,jsx-a11y/label-has-associated-control */
<label className={`${prefix}--label`} htmlFor={id} />
}
{!hideLabel && <span className={`${prefix}--label`} id={id} />}
<div className={`${prefix}--date-picker__input ${prefix}--skeleton`} />
</div>
);
Expand Down Expand Up @@ -74,6 +77,11 @@ DatePickerSkeleton.propTypes = {
*/
className: PropTypes.string,

/**
* Specify whether the label should be hidden, or not
*/
hideLabel: PropTypes.bool,

/**
* Specify the id to add.
*/
Expand Down
1 change: 1 addition & 0 deletions packages/react/src/components/DatePicker/DatePicker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ function updateClassNames(calendar, prefix) {
);
forEach.call(daysContainer.querySelectorAll('.flatpickr-day'), (item) => {
item.classList.add(`${prefix}--date-picker__day`);
item.setAttribute('role', 'button');
if (
item.classList.contains('today') &&
calendar.selectedDates.length > 0
Expand Down

0 comments on commit 7d2924a

Please sign in to comment.