Skip to content
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 13 commits into from
Jan 26, 2018

Conversation

chang47
Copy link
Contributor

@chang47 chang47 commented Jan 17, 2018

Description of changes

Added a title element to the combo box to help different screen readers better narrate combo box elements. I set the value for our title to be ariaLabel or label whichever value is used in the combo box.

I also updated the aria-activedescendant to use the id of the focused combo box element when we're keyboarding through the elements, instead of always using the id of the previously selected element.

Focus areas to test

The Combo Box component page. Look to see if there's a title attribute and notice how if we were to set focus on the combo box items, we'll change our aria-activedescendant to be the id of the element we're selecting.

@christiango christiango requested a review from jspurlin January 20, 2018 17:47
* 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;
Copy link
Contributor

Choose a reason for hiding this comment

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

doesn't the autoComplete code need to compare against 'on' since it's not a boolean? The current code will be true if this.props.autoComplete === 'off'

Copy link
Contributor

@jspurlin jspurlin left a comment

Choose a reason for hiding this comment

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

The logic needs to be updated in getAriaAutoCompleteValue to account for 'on' vs 'off' instead of true vs false

aria-disabled={ disabled }
aria-owns={ (id + '-list') }
spellCheck={ false }
defaultVisibleValue={ this._currentVisibleValue }
suggestedDisplayValue={ suggestedDisplayValue }
updateValueInWillReceiveProps={ this._onUpdateValueInAutoFillWillReceiveProps }
shouldSelectFullInputValueInComponentDidUpdate={ this._onShouldSelectFullInputValueInAutoFillComponentDidUpdate }
title={ (ariaLabel && !label) ? ariaLabel : label }
Copy link
Contributor

Choose a reason for hiding this comment

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

We shouldn't be setting the title with ariaLabel, actually we shouldn't be setting aria-label, aria-labelledby, or title at the same time. Why not use this.props.title and then check that there's no label or ariaLabel and a title before adding the title. You'll also need to tell getNativeProps to ignore the title attribute

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You're right, actually I don't think any of the labels are even needed. I think the correct approach here is to just add the title and exclude it so it's not added to the div.

return 'both';
} else {
return 'none';
}
Copy link
Contributor

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' or autoComplete ? (allFreeform ? 'inline' : 'both') : 'none' (if you want to be explicit about it). This will make the statements cleaner and remove a duplicate autoComplete check

Copy link
Contributor Author

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.

Copy link
Contributor

@jspurlin jspurlin Jan 23, 2018

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

} else if (this.props.ariaLabel) {
title = this.props.ariaLabel;
}
return title;
Copy link
Contributor

Choose a reason for hiding this comment

The 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)

@jspurlin
Copy link
Contributor

This fixes issue: #3063

chrismohr pushed a commit to chrismohr/office-ui-fabric-react that referenced this pull request Apr 17, 2018
…sibility (microsoft#3738)

* added aria-autocomplete; added title; added activedescendant with focus item

* added comments in combobox

* removed autocomplete value for now

* cleaned up code

* added change files

* fixed for id for label to point to the input element

* updated changes with aria-autocomplete

* fixed lint problem; updated test snap file

* fixed aria autocomplete to have the correct logic in if check

* simplified code and changed priority of title values

* addressed lint problems and updated test

* updated title to only use title attribute for combobox
@microsoft microsoft locked as resolved and limited conversation to collaborators Aug 31, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants