Skip to content

Commit 2ceaa2c

Browse files
author
Kubit
committed
Enhance Calendar Component Accessibility with Role Attribute
This commit focuses on improving the accessibility of the calendar component by introducing role attributes to the day, month, and year selectors. A new role parameter has been added to the renderButtonSelector function within the calendar's selector component, allowing for dynamic assignment of appropriate roles to the Button component for each selector type. Additionally, the ISelector and IConfigAccessibility interfaces have been updated to include properties for monthSelectorRole, yearSelectorRole, and daySelectorRole. These enhancements aim to make the calendar component more accessible and user-friendly for individuals using assistive technologies.
1 parent 4d438ec commit 2ceaa2c

File tree

3 files changed

+23
-16
lines changed

3 files changed

+23
-16
lines changed

src/components/calendar/selector/selector.tsx

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,12 @@ export const Selector = (props: ISelector): JSX.Element => {
4141
);
4242
};
4343

44-
const renderButtonSelector = (type: string, showSelector: boolean, ariaLabel?: string) => {
44+
const renderButtonSelector = (
45+
type: string,
46+
showSelector: boolean,
47+
ariaLabel?: string,
48+
role?: string
49+
) => {
4550
const buttonState = showSelector ? ButtonStateType.DISABLED : ButtonStateType.DEFAULT;
4651

4752
const selectorToShow = () => {
@@ -73,6 +78,7 @@ export const Selector = (props: ISelector): JSX.Element => {
7378
<Button
7479
aria-label={ariaLabel}
7580
disabled={showSelector}
81+
role={role}
7682
size={sizeSelectorButton || props.styles?.selectorOptions?.sizeSelectorButton}
7783
variant={variantSelectorButton || props.styles?.selectorOptions?.variantSelectorButton}
7884
onClick={handleClickButtonSelector}
@@ -101,29 +107,21 @@ export const Selector = (props: ISelector): JSX.Element => {
101107
onChangeCurrentDate(dateHelpers.getAddMonths(auxCurrentDate, 1));
102108
};
103109

104-
const handleOnClickBack: React.MouseEventHandler<HTMLDivElement> = event => {
105-
onClickLeftIcon();
106-
props.onLeftIconClick?.(event);
107-
};
108-
109110
const handleOnClickLeftIcon: React.MouseEventHandler<HTMLButtonElement> = event => {
110111
onClickLeftIcon();
111112
leftArrowIcon.onClick?.(event);
112-
};
113-
114-
const handleOnClickRight: React.MouseEventHandler<HTMLDivElement> = event => {
115-
onClickRightIcon();
116-
props.onRightIconClick?.(event);
113+
props.onLeftIconClick?.(event);
117114
};
118115

119116
const handleOnClickRightIcon: React.MouseEventHandler<HTMLButtonElement> = event => {
120117
onClickRightIcon();
121118
rightArrowIcon.onClick?.(event);
119+
props.onRightIconClick?.(event);
122120
};
123121

124122
return (
125123
<SelectorStyled isDaySelector={isDaySelector} styles={props.styles}>
126-
<IconAndBackTextStyled styles={props.styles} onClick={handleOnClickBack}>
124+
<IconAndBackTextStyled styles={props.styles}>
127125
<ElementOrIcon
128126
color={iconArrowDisabled(props.minDate) ? props.styles?.colorArrowDisabled : undefined}
129127
customIconStyles={props.styles?.leftArrow}
@@ -147,20 +145,23 @@ export const Selector = (props: ISelector): JSX.Element => {
147145
renderButtonSelector(
148146
CalendarElementType.DAY,
149147
props.showDaySelector,
150-
props.configAccesibility?.daySelectorAriaLabel
148+
props.configAccesibility?.daySelectorAriaLabel,
149+
props.configAccesibility?.daySelectorRole
151150
)}
152151
{renderButtonSelector(
153152
CalendarElementType.MONTH,
154153
props.showMonthSelector,
155-
props.configAccesibility?.monthSelectorAriaLabel
154+
props.configAccesibility?.monthSelectorAriaLabel,
155+
props.configAccesibility?.monthSelectorRole
156156
)}
157157
{renderButtonSelector(
158158
CalendarElementType.YEAR,
159159
props.showYearSelector,
160-
props.configAccesibility?.yearSelectorAriaLabel
160+
props.configAccesibility?.yearSelectorAriaLabel,
161+
props.configAccesibility?.yearSelectorRole
161162
)}
162163
</OptionsStyled>
163-
<RightIconStyled showCustomSelector={showCustomSelector} onClick={handleOnClickRight}>
164+
<RightIconStyled showCustomSelector={showCustomSelector}>
164165
<ElementOrIcon
165166
color={iconArrowDisabled(props.maxDate) ? props.styles?.colorArrowDisabled : undefined}
166167
customIconStyles={props.styles?.rightArrow}

src/components/calendar/selector/types/selector.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@ export interface ISelector {
3939
sizeSelectorButton?: string;
4040
};
4141
configAccesibility?: {
42+
monthSelectorRole?: string;
43+
yearSelectorRole?: string;
44+
daySelectorRole?: string;
4245
monthSelectorAriaLabel?: string;
4346
yearSelectorAriaLabel?: string;
4447
daySelectorAriaLabel?: string;

src/components/calendar/types/calendar.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ export type IConfigAccesibility = {
2828
monthSelectorAriaLabel?: string;
2929
yearSelectorAriaLabel?: string;
3030
backToMonthAriaLabel?: string;
31+
monthSelectorRole?: string;
32+
yearSelectorRole?: string;
33+
daySelectorRole?: string;
3134
};
3235
export interface ICalendarStandAlone<V = undefined extends string ? unknown : string> {
3336
id?: string;

0 commit comments

Comments
 (0)