-
Notifications
You must be signed in to change notification settings - Fork 2.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Combo Box - Adding title and Improved aria-activedescendant for accessibility #3738
Merged
Merged
Changes from 12 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
4054f99
added aria-autocomplete; added title; added activedescendant with foc…
5ac2fed
added comments in combobox
658f005
removed autocomplete value for now
10e99a5
cleaned up code
7f460ec
Merge branch 'master' into chiechan/checkboxAcc
a9f0009
added change files
f9ce367
fixed for id for label to point to the input element
8d0ad87
updated changes with aria-autocomplete
ed7eba2
fixed lint problem; updated test snap file
a656591
fixed aria autocomplete to have the correct logic in if check
8d80c5a
simplified code and changed priority of title values
4bf14bd
addressed lint problems and updated test
556fd0c
updated title to only use title attribute for combobox
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
11 changes: 11 additions & 0 deletions
11
common/changes/office-ui-fabric-react/chiechan-checkboxAcc_2018-01-17-19-40.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{ | ||
"changes": [ | ||
{ | ||
"packageName": "office-ui-fabric-react", | ||
"comment": "Combox box: added accessibility changes added a title and changed activedescendant to use focused element", | ||
"type": "patch" | ||
} | ||
], | ||
"packageName": "office-ui-fabric-react", | ||
"email": "chiechan@microsoft.com" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -295,7 +295,7 @@ export class ComboBox extends BaseComponent<IComboBoxProps, IComboBoxState> { | |
return ( | ||
<div {...divProps } ref='root' className={ this._classNames.container }> | ||
{ label && ( | ||
<Label id={ id + '-label' } disabled={ disabled } required={ required } htmlFor={ id } className={ this._classNames.label }>{ label }</Label> | ||
<Label id={ id + '-label' } disabled={ disabled } required={ required } htmlFor={ id + '-input' } className={ this._classNames.label }>{ label }</Label> | ||
) } | ||
<div | ||
ref={ this._resolveRef('_comboBoxWrapper') } | ||
|
@@ -315,21 +315,22 @@ export class ComboBox extends BaseComponent<IComboBoxProps, IComboBoxState> { | |
onClick={ this._onBaseAutofillClick } | ||
onInputValueChange={ this._onInputChange } | ||
aria-expanded={ isOpen } | ||
aria-autocomplete={ (!disabled && autoComplete === 'on') } | ||
aria-autocomplete={ this._getAriaAutoCompleteValue() } | ||
role='combobox' | ||
aria-readonly={ ((allowFreeform || disabled) ? null : 'true') } | ||
readOnly={ disabled || !allowFreeform } | ||
aria-labelledby={ (label && (id + '-label')) } | ||
aria-label={ ((ariaLabel && !label) && ariaLabel) } | ||
aria-describedby={ (id + '-option') } | ||
aria-activedescendant={ (isOpen && (selectedIndex as number) >= 0 ? (id + '-list' + selectedIndex) : null) } | ||
aria-activedescendant={ this._getAriaActiveDescentValue() } | ||
aria-disabled={ disabled } | ||
aria-owns={ (id + '-list') } | ||
spellCheck={ false } | ||
defaultVisibleValue={ this._currentVisibleValue } | ||
suggestedDisplayValue={ suggestedDisplayValue } | ||
updateValueInWillReceiveProps={ this._onUpdateValueInAutoFillWillReceiveProps } | ||
shouldSelectFullInputValueInComponentDidUpdate={ this._onShouldSelectFullInputValueInAutoFillComponentDidUpdate } | ||
title={ this._getTitle() } | ||
/> | ||
<IconButton | ||
className={ 'ms-ComboBox-CaretDown-button' } | ||
|
@@ -1540,4 +1541,46 @@ export class ComboBox extends BaseComponent<IComboBoxProps, IComboBoxState> { | |
|
||
return getOptionStyles(this.props.theme!, customStylesForAllOptions, customStylesForCurrentOption); | ||
} | ||
|
||
/** | ||
* Get the aria-activedescendant value for the comboxbox. | ||
* @returns the id of the current focused combo item, otherwise the id of the currently selected element, null otherwise | ||
*/ | ||
private _getAriaActiveDescentValue(): string | null { | ||
let descendantText = (this.state.isOpen && (this.state.selectedIndex as number) >= 0 ? (this._id + '-list' + this.state.selectedIndex) : null); | ||
if (this.state.isOpen && this.state.focused && this.state.currentPendingValueValidIndex !== -1) { | ||
descendantText = (this._id + '-list' + this.state.currentPendingValueValidIndex); | ||
} | ||
return descendantText; | ||
} | ||
|
||
/** | ||
* Get the aria autocomplete value for the Combobox | ||
* @returns 'inline' if auto-complete automatically dynamic, 'both' if we have a list of possible values to pick from and can | ||
* dynamically populate input, and 'none' if auto-complete is not enabled as we can't give user inputs. | ||
*/ | ||
private _getAriaAutoCompleteValue(): string { | ||
let autoComplete = !this.props.disabled && this.props.autoComplete === 'on'; | ||
return autoComplete ? (this.props.allowFreeform ? 'inline' : 'both') : 'none'; | ||
} | ||
|
||
/** | ||
* Get the string we would use for the title. | ||
* @returns in order of priority: | ||
* 1. The provided title | ||
* 2. The label value that will be used by aria-labelled | ||
* 3. The aria-label value | ||
* 4. Else empty string | ||
*/ | ||
private _getTitle(): string { | ||
let title = ''; | ||
if (this.props.title) { | ||
title = this.props.title; | ||
} else if (this.props.label) { | ||
title = this.props.label; | ||
} else if (this.props.ariaLabel) { | ||
title = this.props.ariaLabel; | ||
} | ||
return title; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should only be setting the title if one was passed in, so instead of having _getTitle you can just use the title if it's given (inside of render) |
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider changing this to a ternary opertation like:
autoComplete ? allFreeform ? 'inline' : 'both' : 'none'
orautoComplete ? (allFreeform ? 'inline' : 'both') : 'none'
(if you want to be explicit about it). This will make the statements cleaner and remove a duplicate autoComplete checkThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will do. I was once told to avoid it, but if you think it's fine, then I'll make the change.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah if it's a complicated ternary statement or you're nesting more than two statements don't do it, is how I usually think about it