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

ComboBox: Option to use ariaLabel prop as preview text #4540

Merged

Conversation

kysedate
Copy link
Contributor

Pull request checklist

  • Addresses an existing issue: Fixes #0000
  • Include a change request file using $ npm run change

Description of changes

There are scenarios where the text passed into a ComboBox option isn't plain text, but rather text with an embedded style. In this case, we want to render a plain text version of the string on the aria-label of the option, in the ComboBox input when selected, and used for that option's autocomplete string. This prop allows for the ComboBox to handle this case by using the ariaLabel prop instead of the text prop when necessary.

@@ -583,18 +583,21 @@ export class ComboBox extends BaseComponent<IComboBoxProps, IComboBoxState> {
if (this.props.autoComplete === 'on') {

// If autoComplete is on, attempt to find a match where the text of an option starts with the updated value
const items = currentOptions.map((item, index) => { return { ...item, index }; }).filter((option) => option.itemType !== SelectableOptionMenuItemType.Header && option.itemType !== SelectableOptionMenuItemType.Divider).filter((option) => option.text.toLocaleLowerCase().indexOf(updatedValue) === 0);
const items = currentOptions.map((item, index) => { return { ...item, index }; }).filter((option) => option.itemType !== SelectableOptionMenuItemType.Header && option.itemType !== SelectableOptionMenuItemType.Divider).filter((option) => this._getPreviewText(option).toLocaleLowerCase().indexOf(updatedValue) === 0);
Copy link
Contributor

Choose a reason for hiding this comment

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

This line is really long, consider breaking it up across multiple line


// remember the index of the match we found
newCurrentPendingValueValidIndex = items[0].index;
}
} else {

// If autoComplete is off, attempt to find a match only when the value is exactly equal to the text of an option
const items = currentOptions.map((item, index) => { return { ...item, index }; }).filter((option) => option.itemType !== SelectableOptionMenuItemType.Header && option.itemType !== SelectableOptionMenuItemType.Divider).filter((option) => option.text.toLocaleLowerCase() === updatedValue);
const items = currentOptions.map((item, index) => { return { ...item, index }; }).filter((option) => option.itemType !== SelectableOptionMenuItemType.Header && option.itemType !== SelectableOptionMenuItemType.Divider).filter((option) => this._getPreviewText(option).toLocaleLowerCase() === updatedValue);
Copy link
Contributor

Choose a reason for hiding this comment

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

same comment here

@@ -1040,7 +1043,7 @@ export class ComboBox extends BaseComponent<IComboBoxProps, IComboBoxState> {
onMouseLeave={ this._onOptionMouseLeave }
role='option'
aria-selected={ isSelected ? 'true' : 'false' }
ariaLabel={ item.text }
ariaLabel={ this._getPreviewText(item) }
Copy link
Contributor

Choose a reason for hiding this comment

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

What about the multiSelect case?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm not sure what you mean..

Copy link
Contributor

Choose a reason for hiding this comment

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

the checkbox below seems to be missing the ariaLabel... we should fix that

@@ -26,6 +26,12 @@ export interface IComboBoxOption extends ISelectableOption {
* the prop comboBoxOptionStyles
*/
styles?: Partial<IComboBoxOptionStyles>;

/**
* In scenarios where embedded data is used at the text prop, we will use the ariaLabel prop to set the aria-label and preview text. Default to false
Copy link
Contributor

@jspurlin jspurlin Apr 13, 2018

Choose a reason for hiding this comment

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

NIT: wrap this to multiple lines as well

@@ -1764,4 +1767,8 @@ export class ComboBox extends BaseComponent<IComboBoxProps, IComboBoxState> {

return retKeys;
}

private _getPreviewText(item: IComboBoxOption): string {
Copy link
Contributor

Choose a reason for hiding this comment

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

this seems like a good place to add a comment explaining why are we doing this

Copy link
Contributor

@ddlbrena ddlbrena left a comment

Choose a reason for hiding this comment

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

:shipit:

@jspurlin jspurlin merged commit 8ef07e5 into microsoft:master Apr 13, 2018
@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