Skip to content

Commit

Permalink
[datetime] fix(a11y): add aria-labels for various controls (#5358)
Browse files Browse the repository at this point in the history
Co-authored-by: Adi Dahiya <adi.dahiya14@gmail.com>
  • Loading branch information
bvandercar-vt and adidahiya committed Jun 7, 2022
1 parent 0c5823b commit d9d20dc
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 2 deletions.
9 changes: 8 additions & 1 deletion packages/core/src/components/html-select/htmlSelect.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,14 @@ export class HTMLSelect extends AbstractPureComponent2<HTMLSelectProps> {

const optionChildren = options.map(option => {
const props: OptionProps = typeof option === "object" ? option : { value: option };
return <option {...props} key={props.value} children={props.label || props.value} />;
return (
<option
{...props}
key={props.value}
children={props.label || props.value}
selected={this.props.value === props.value}
/>
);
});

return (
Expand Down
2 changes: 2 additions & 0 deletions packages/datetime/src/datePickerCaption.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ export class DatePickerCaption extends AbstractPureComponent2<IDatePickerCaption

const monthSelect = (
<HTMLSelect
aria-label="Month"
iconProps={{ style: { right: this.state.monthRightOffset } }}
className={Classes.DATEPICKER_MONTH_SELECT}
key="month"
Expand All @@ -86,6 +87,7 @@ export class DatePickerCaption extends AbstractPureComponent2<IDatePickerCaption
);
const yearSelect = (
<HTMLSelect
aria-label="Year"
className={Classes.DATEPICKER_YEAR_SELECT}
key="year"
minimal={true}
Expand Down
2 changes: 2 additions & 0 deletions packages/datetime/src/datePickerNavbar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ export class DatePickerNavbar extends React.PureComponent<IDatePickerNavbarProps
<div className={classNames(Classes.DATEPICKER_NAVBAR, classes.navBar)}>
{this.props.hideLeftNavButton || (
<Button
aria-label="Go to previous month"
className={classes.navButtonPrev}
disabled={areSameMonth(month, minDate)}
icon="chevron-left"
Expand All @@ -48,6 +49,7 @@ export class DatePickerNavbar extends React.PureComponent<IDatePickerNavbarProps
)}
{this.props.hideRightNavButton || (
<Button
aria-label="Go to next month"
className={classes.navButtonNext}
disabled={areSameMonth(month, maxDate)}
icon="chevron-right"
Expand Down
2 changes: 1 addition & 1 deletion packages/datetime/src/shortcuts.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ export class Shortcuts extends React.PureComponent<IShortcutsProps> {
));

return (
<Menu className={DATERANGEPICKER_SHORTCUTS} tabIndex={0}>
<Menu aria-label="Date picker shortcuts" className={DATERANGEPICKER_SHORTCUTS} tabIndex={0}>
{shortcutElements}
</Menu>
);
Expand Down

2 comments on commit d9d20dc

@blueprint-bot
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[datetime] fix(a11y): add aria-labels for various controls (#5358)

Previews: documentation | landing | table | demo

@blueprint-bot
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[datetime] fix(a11y): add aria-labels for various controls (#5358)

Previews: documentation | landing | table | demo

Please sign in to comment.