Skip to content
This repository has been archived by the owner on Oct 12, 2023. It is now read-only.

Commit

Permalink
Merge pull request #26 from misteinb/bugfix/screen-reader-support-for…
Browse files Browse the repository at this point in the history
…-calendar

add aria label to calendar days
  • Loading branch information
misteinb authored Aug 14, 2018
2 parents 11c62ca + 7b28f58 commit 7341e65
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 38 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# CHANGELOG

## v3.0.3
### Fixed
- screen reader support for calendar
- take in props to override browser locale for calendar

## v3.0.2
### Fixed
- expose callback for clicking calendar icon in date picker. includes next visible state.
Expand Down
48 changes: 11 additions & 37 deletions lib/components/DateTime/Calendar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ export interface CalendarAttributes {
export interface CalendarProps extends React.Props<CalendarComponentType> {
/** Current selected date */
value?: Date | string;
/** i18n locale */
locale?: string;

/** Year to display (otherwise shows the year from value) */
year?: number;
Expand Down Expand Up @@ -52,8 +54,6 @@ export interface CalendarState {
currentDate: MethodDate;
/** Whether or not props.year/month updates update the view */
detached: boolean;
/** Whether accessibility is activated */
accessibility: boolean;
}

/**
Expand Down Expand Up @@ -86,7 +86,6 @@ export class Calendar extends React.Component<CalendarProps, Partial<CalendarSta


constructor(props: CalendarProps) {
const locale = navigator['userLanguage'] || (navigator.language || 'en-us');
super(props);

if (typeof (this.props.value) === 'string') {
Expand All @@ -107,36 +106,19 @@ export class Calendar extends React.Component<CalendarProps, Partial<CalendarSta
currentDate.date = 1;
this.state = {
currentDate: currentDate,
detached: false,
accessibility: false
detached: false
};

this.monthNames = getLocalMonths(locale);
this.monthNames = getLocalMonths(this.props.locale);

this.dayNames = getLocalWeekdays(locale);
this.dayNames = getLocalWeekdays(this.props.locale);

this.onPrevMonth = this.onPrevMonth.bind(this);
this.onNextMonth = this.onNextMonth.bind(this);
this.onKeyDown = this.onKeyDown.bind(this);
this.setContainerRef = this.setContainerRef.bind(this);
}

public startAccessibility() {
const newDate = this.state.currentDate.copy();
newDate.date = 1;

this.setState({
accessibility: true,
currentDate: newDate
});
}

public stopAccessibility() {
this.setState({
accessibility: false
});
}

componentWillReceiveProps(newProps: CalendarProps) {
const date = this.state.currentDate.copy();
let update = false;
Expand Down Expand Up @@ -182,20 +164,11 @@ export class Calendar extends React.Component<CalendarProps, Partial<CalendarSta
this.props.onChange(date.dateObject);
this.setState({
currentDate: MethodDate.fromDate(this.props.localTimezone, date.dateObject),
detached: false,
accessibility: false
detached: false
});
}
}

onFocus(date: number, event) {
if (!this.state.accessibility) {
const newDate = this.state.currentDate.copy();
newDate.date = date;
this.setState({ currentDate: newDate, accessibility: true });
}
}

onPrevMonth(event) {
event.preventDefault();

Expand Down Expand Up @@ -349,16 +322,17 @@ export class Calendar extends React.Component<CalendarProps, Partial<CalendarSta
event.preventDefault();
};

// TODO aria-label with date

const date = col.date;
const colMonth = col.month;
const key = `${colMonth}-${date}`;
const ariaLabel = new Date(`${curYear}-${colMonth + 1}-${date}`).toLocaleDateString(this.props.locale, { weekday: 'long', year: 'numeric', month: 'long', day: 'numeric' });

/** Grayed out day from another month */
if (colMonth !== curMonth) {
return (
<Attr.button
type='button'
aria-label={ariaLabel}
data-row={rowIndex}
data-col={colIndex}
onKeyDown={this.onKeyDown}
Expand All @@ -384,13 +358,13 @@ export class Calendar extends React.Component<CalendarProps, Partial<CalendarSta
return (
<Attr.button
type='button'
aria-label={ariaLabel}
data-row={rowIndex}
data-col={colIndex}
onKeyDown={this.onKeyDown}
className={css('selected')}
onClick={onClick}
key={key}
onFocus={this.onFocus.bind(this, date)}
attr={this.props.attr.dateButton}
>
{date}
Expand All @@ -403,12 +377,12 @@ export class Calendar extends React.Component<CalendarProps, Partial<CalendarSta
return (
<Attr.button
type='button'
aria-label={ariaLabel}
data-row={rowIndex}
data-col={colIndex}
onKeyDown={this.onKeyDown}
onClick={onClick}
key={key}
onFocus={this.onFocus.bind(this, date)}
attr={this.props.attr.dateButton}
>
{date}
Expand Down
3 changes: 3 additions & 0 deletions lib/components/DateTime/DateField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ export interface DateFieldProps extends React.Props<DateFieldType> {
* Default: true
*/
localTimezone?: boolean;
/** i18n locale */
locale?: string;
/**
* Show Calendar below date picker input
*/
Expand Down Expand Up @@ -114,6 +116,7 @@ export const DateField: React.StatelessComponent<DateFieldProps> = (props: DateF
<DatePicker
name={props.name}
initialValue={props.initialValue}
locale={props.locale}
localTimezone={props.localTimezone}
tabIndex={props.tabIndex}
showAbove={props.showAbove}
Expand Down
4 changes: 4 additions & 0 deletions lib/components/DateTime/DatePicker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ export interface DatePickerProps extends React.Props<DatePickerType> {
* Default: true
*/
localTimezone?: boolean;

/** i18n locale */
locale?: string;
/**
* Show Calendar below date picker input
*/
Expand Down Expand Up @@ -446,6 +449,7 @@ export class DatePicker extends React.Component<DatePickerProps, Partial<DatePic
className={css('date-picker-calendar')}
year={parsed.year || null}
month={parsed.month - 1}
locale={this.props.locale}
attr={this.props.attr.calendar}
/>
<div className={css('date-picker-dropdown-triangle')}></div>
Expand Down
3 changes: 3 additions & 0 deletions lib/components/DateTime/DateTimeField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ export interface DateTimeFieldProps extends React.Props<DateTimeFieldType> {
* Default: true
*/
localTimezone?: boolean;
/** i18n locale */
locale?: string;
/**
* Show Calendar below date picker input
*/
Expand Down Expand Up @@ -370,6 +372,7 @@ export class DateTimeField extends React.Component<DateTimeFieldProps, Partial<D
tabIndex={this.props.tabIndex}
error={!!this.props.error}
disabled={this.props.disabled}
locale={this.props.locale}
localTimezone={this.props.localTimezone}
showAbove={this.props.showAbove}
format={this.props.format}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@azure-iot/ux-fluent-controls",
"version": "3.0.2",
"version": "3.0.3",
"description": "Azure IoT Fluent React Controls",
"main": "./lib/index.js",
"types": "./lib/index.d.ts",
Expand Down

0 comments on commit 7341e65

Please sign in to comment.