Skip to content

Commit

Permalink
feat: enhance WeekdayPicker accessibility with aria-label and aria-li…
Browse files Browse the repository at this point in the history
…ve support

- Add `aria-label` and `aria-live` for improved screen reader compatibility.
- Add CSS styling for the `aria-live` region to ensure proper visibility and user experience.
- remove aria-pressed
  • Loading branch information
Abishekcs committed Dec 11, 2024
1 parent 0115737 commit 82281b9
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 7 deletions.
22 changes: 17 additions & 5 deletions app/assets/javascripts/components/common/weekday_picker.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ const WeekdayPicker = ({
style,
tabIndex,

ariaModifier,
modifiers,

locale,
Expand Down Expand Up @@ -145,7 +144,7 @@ const WeekdayPicker = ({

dayClassName += customModifiers.map(modifier => ` ${dayClassName}--${modifier}`).join('');

const ariaSelected = customModifiers.indexOf(ariaModifier) > -1;
const ariaSelected = customModifiers.indexOf('selected') > -1;

let tabIndexValue = null;
if (onWeekdayClick) {
Expand All @@ -159,10 +158,20 @@ const WeekdayPicker = ({
const onMouseEnterHandler = onWeekdayMouseEnter ? e => handleWeekdayMouseEnter(e, weekday, customModifiers) : null;
const onMouseLeaveHandler = onWeekdayMouseLeave ? e => handleWeekdayMouseLeave(e, weekday, customModifiers) : null;

const ariaLabelMessage = ariaSelected
? I18n.t('weekday_picker.aria.weekday_selected', { weekday: localeUtils.formatWeekdayLong(weekday), })
: I18n.t('weekday_picker.aria.weekday_select', { weekday: localeUtils.formatWeekdayLong(weekday), });

const ariaLiveMessage = ariaSelected
? I18n.t('weekday_picker.aria.weekday_selected', { weekday: localeUtils.formatWeekdayLong(weekday), })
: I18n.t('weekday_picker.aria.weekday_unselected', { weekday: localeUtils.formatWeekdayLong(weekday), });

return (
<button
key={weekday} className={dayClassName} tabIndex={tabIndexValue}
aria-pressed={ariaSelected}
key={weekday}
className={dayClassName}
tabIndex={tabIndexValue}
aria-label= {ariaLabelMessage}
onClick={onClickHandler}
onKeyDown={e => handleDayKeyDown(e, weekday, customModifiers)}
onMouseEnter={onMouseEnterHandler}
Expand All @@ -171,6 +180,10 @@ const WeekdayPicker = ({
<span title={localeUtils.formatWeekdayLong(weekday)}>
{localeUtils.formatWeekdayShort(weekday)}
</span>
{/* Aria-live region for screen reader announcements for confirmation of when a week day is selected or unselected */}
<div aria-live="assertive" aria-atomic="true" className="sr-WeekdayPicker-aria-live">
{ariaLiveMessage}
</div>
</button>
);
};
Expand Down Expand Up @@ -201,7 +214,6 @@ WeekdayPicker.propTypes = {
style: PropTypes.object,
tabIndex: PropTypes.number,

ariaModifier: PropTypes.string,
modifiers: PropTypes.object,

locale: PropTypes.string,
Expand Down
12 changes: 12 additions & 0 deletions app/assets/stylesheets/modules/_calendar.styl
Original file line number Diff line number Diff line change
Expand Up @@ -172,3 +172,15 @@

.DayPicker--ar
direction rtl

// CSS for screen reader support for weekday picker
.sr-WeekdayPicker-aria-live {
position: absolute;
width: 1px;
height: 1px;
margin: -1px;
padding: 0;
overflow: hidden;
clip: rect(0, 0, 0, 0);
border: 0;
}
11 changes: 9 additions & 2 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1869,9 +1869,16 @@ en:
note_edit_cancel_button_focused: "Cancel note edit {{title}}"
note_delete_button_focused: "Delete the note {{title}}"
note_edit_mode: "Entered Edit mode for note titled: {{title}}. You can now edit the title and content."

customize_error_message:
JSONP_request_failed: "The request to fetch data from Wikipedia has timed out. This may be due to a slow internet connection or temporary server issues. Please try again later."

tagged_courses:
download_csv: 'Download CSV'
download_csv: 'Download CSV'

weekday_picker:
aria:
weekday_select: "{{weekday}} Press Return key to select"
weekday_selected: "{{weekday}} Selected Press Return Key to unselect"
weekday_unselected: "{{weekday}} Unselected"

0 comments on commit 82281b9

Please sign in to comment.