DatePicker: Improve screenreader accessibility #1453
Conversation
| <div className={ css('ms-DatePicker-month', styles.month) }>{ strings.months[navigatedDate.getMonth()] }</div> | ||
| <div className={ css('ms-DatePicker-year', styles.year) }>{ navigatedDate.getFullYear() }</div> | ||
| <div role='heading' id={ monthAndYearId } aria-live='assertive' aria-relevant='text' aria-atomic='true'> | ||
| <div className={ css('ms-DatePicker-month', styles.month) }>{ strings.months[navigatedDate.getMonth()] }</div> |
There was a problem hiding this comment.
Does this localize well? Won't it be wrong in EMEA?
There was a problem hiding this comment.
I agree, the localization approach taken here is likely not ideal. Fixing that is beyond the scope of this pull-request though: I'd just like to focus on the accessibility improvements and leave the localization logic as it currently stands.
| <div className={ css('ms-DatePicker-header', styles.header) }> | ||
| <div className={ css('ms-DatePicker-month', styles.month) }>{ strings.months[navigatedDate.getMonth()] }</div> | ||
| <div className={ css('ms-DatePicker-year', styles.year) }>{ navigatedDate.getFullYear() }</div> | ||
| <div role='heading' id={ monthAndYearId } aria-live='assertive' aria-relevant='text' aria-atomic='true'> |
There was a problem hiding this comment.
Add a heading level if you're adding heading.
There was a problem hiding this comment.
We have no way of knowing what the correct level here would be, so I removed the role.
| </div> | ||
| <div className={ css('ms-DatePicker-monthComponents', styles.monthComponents) }> | ||
| <div className={ css('ms-DatePicker-navContainer', styles.navContainer) }> | ||
| <span |
There was a problem hiding this comment.
Why do we not use a true button?
There was a problem hiding this comment.
This was here before my pull-request, so that's a question for the original author: @dzearing.
| onKeyDown={ this._onPrevMonthKeyDown } | ||
| aria-controls={ monthAndYearId } | ||
| aria-label={ strings.nextMonthAriaLabel } | ||
| role='button' |
There was a problem hiding this comment.
button implies we handle spacebar as well.
| <div className={ css('ms-DatePicker-header', styles.header) }> | ||
| <div className={ css('ms-DatePicker-month', styles.month) }>{ strings.months[navigatedDate.getMonth()] }</div> | ||
| <div className={ css('ms-DatePicker-year', styles.year) }>{ navigatedDate.getFullYear() }</div> | ||
| <div role='heading' id={ monthAndYearId } aria-live='assertive' aria-relevant='text' aria-atomic='true'> |
There was a problem hiding this comment.
Making the month display assertive makes the control much nicer to use with a screen reader: when navigating between a month boundary (e.g. from the 30th of one month to the 1st of the next month), we'll re-announce the month's name which provides more context to the user. It's better to hear "1 January 2017" than just "1".
|
@cschlechty: I addressed your comments -- could you please take another look? |
| <div className={ css('ms-DatePicker-header', styles.header) }> | ||
| <div className={ css('ms-DatePicker-month', styles.month) }>{ strings.months[navigatedDate.getMonth()] }</div> | ||
| <div className={ css('ms-DatePicker-year', styles.year) }>{ navigatedDate.getFullYear() }</div> | ||
| <div id={ monthAndYearId } aria-live='assertive' aria-relevant='text' aria-atomic='true'> |
There was a problem hiding this comment.
Can you use passive, instead?
| className={ css('ms-DatePicker-prevMonth js-prevMonth', styles.prevMonth) } | ||
| onClick={ this._onSelectPrevMonth } | ||
| onKeyDown={ this._onPrevMonthKeyDown } | ||
| aria-controls={ monthAndYearId } |
There was a problem hiding this comment.
aria-controls specifies the html it has control over. shouldn't this point to the body of the calendar?
cschlechty
left a comment
There was a problem hiding this comment.
There's a few suggestions.
Pull request checklist
Description of changes
The previous/next month/year buttons don't have aria-labels and therefore are indiscernible to screen reader users. This pull request fixes this by enabling consumers of the date-picker to provide aria-labels for the buttons.
This pull request also improves the navigation of the date picker for screen reader users by re-announcing the month and year whenever the user navigates across a month/year boundary. This behavior is adapted from some accessibility best practices laid out by the OAA.
Focus areas to test
Test steps (verified manually on DatePicker.Basic.Example):