Skip to content

Commit

Permalink
feat: add aria-selected attribute for all entities
Browse files Browse the repository at this point in the history
  • Loading branch information
Feshchenko committed May 18, 2023
1 parent 355b141 commit 302b0e2
Show file tree
Hide file tree
Showing 10 changed files with 1,016 additions and 759 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -472,6 +472,7 @@ export interface DPPropGetter extends Record<string, unknown> {
tabIndex: number;
disabled?: boolean;
'aria-disabled'?: boolean;
'aria-selected'?: boolean;
onClick?(evt: MouseEvent<HTMLElement>): void;
}
```
Expand Down
1,755 changes: 1,001 additions & 754 deletions package-lock.json

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@rehookify/datepicker",
"version": "5.0.0",
"version": "5.1.0",
"description": "The ultimate tool to create a date, range and time picker in your React applications.",
"main": "dist/index.cjs.js",
"module": "dist/index.esm.mjs",
Expand Down Expand Up @@ -70,7 +70,7 @@
"@babel/preset-typescript": "^7.18.6",
"@jest/globals": "^29.3.1",
"@playwright/test": "^1.28.1",
"@rollup/plugin-commonjs": "^24.0.1",
"@rollup/plugin-commonjs": "^25.0.0",
"@rollup/plugin-node-resolve": "^15.0.1",
"@rollup/plugin-terser": "^0.4.0",
"@testing-library/jest-dom": "^5.16.5",
Expand Down
4 changes: 3 additions & 1 deletion src/__test__/create-prop-getters.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,14 @@ describe('createPropGetter', () => {
onClick,
disabled,
'aria-disabled': ariaDisabled,
} = createPropGetter(true, jest.fn(), {});
'aria-selected': ariaSelected,
} = createPropGetter(true, jest.fn(), {}, true);

expect(role).toBe('button');
expect(tabIndex).toBe(0);
expect(onClick).toBeFalsy();
expect(disabled).toBe(true);
expect(ariaDisabled).toBe(true);
expect(ariaSelected).toBe(true);
});
});
1 change: 1 addition & 0 deletions src/types/prop-getters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,6 @@ export interface DPPropGetter extends Record<string, unknown> {
tabIndex: number;
disabled?: boolean;
'aria-disabled'?: boolean;
'aria-selected'?: boolean;
onClick?(evt: MouseEvent<HTMLElement>): void;
}
1 change: 1 addition & 0 deletions src/use-days.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ export const useDaysPropGetters: DPUseDaysPropGetters = ({
},
}),
},
selected,
),
[
mode,
Expand Down
3 changes: 2 additions & 1 deletion src/use-months.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,14 @@ export const useMonthsPropGetters: DPUseMonthsPropGetters = ({

const monthButton = useCallback(
(
{ $date, disabled }: DPMonth,
{ $date, disabled, selected }: DPMonth,
{ onClick, disabled: disabledProps, ...rest }: DPPropsGetterConfig = {},
) =>
createPropGetter(
!!disabledProps || disabled,
(evt) => callAll(onClick, skipFirst(callSetOffset))(evt, $date),
rest,
selected,
),
[callSetOffset],
);
Expand Down
1 change: 1 addition & 0 deletions src/use-time.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ export const useTimePropGetter: DPUseTimePropGetter = ({
)(evt, $date);
},
rest,
selected,
),
[selectedDates, onDatesChange, dispatch, focusDate],
);
Expand Down
3 changes: 2 additions & 1 deletion src/use-years.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,14 @@ export const useYearsPropGetters: DPUseYearsPropGetters = ({

const yearButton = useCallback(
(
{ $date, disabled }: DPYear,
{ $date, disabled, selected }: DPYear,
{ onClick, disabled: disabledProps, ...rest }: DPPropsGetterConfig = {},
) =>
createPropGetter(
!!disabledProps || disabled,
(evt) => callAll(onClick, skipFirst(callSetOffset))(evt, $date),
rest,
selected,
),
[callSetOffset],
);
Expand Down
2 changes: 2 additions & 0 deletions src/utils/create-prop-getter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ export const createPropGetter = (
isDisabled: boolean,
action: (evt: MouseEvent<HTMLElement>) => void,
props: DPPropsGetterConfig = {},
selected = false,
): DPPropGetter => ({
role: 'button',
tabIndex: 0,
Expand All @@ -19,5 +20,6 @@ export const createPropGetter = (
action(evt);
},
}),
...(selected ? { 'aria-selected': true } : {}),
...props,
});

0 comments on commit 302b0e2

Please sign in to comment.