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
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ 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 }
Expand Down Expand Up @@ -1553,4 +1553,20 @@ export class ComboBox extends BaseComponent<IComboBoxProps, IComboBoxState> {
}
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;
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'

if (autoComplete && this.props.allowFreeform) {
return 'inline';
} else if (autoComplete && !this.props.allowFreeform) {
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

}
}