Skip to content

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

Merged
jspurlin merged 8 commits intomicrosoft:masterfrom
kysedate:kysedate/combobox-handle-weird-text
Apr 13, 2018
Merged

ComboBox: Option to use ariaLabel prop as preview text#4540
jspurlin merged 8 commits intomicrosoft:masterfrom
kysedate:kysedate/combobox-handle-weird-text

Conversation

@kysedate
Copy link
Copy Markdown
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.


// 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
Copy Markdown
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


// 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
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

same comment here

role='option'
aria-selected={ isSelected ? 'true' : 'false' }
ariaLabel={ item.text }
ariaLabel={ this._getPreviewText(item) }
Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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

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
Copy Markdown
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

return retKeys;
}

private _getPreviewText(item: IComboBoxOption): string {
Copy link
Copy Markdown
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
Copy Markdown
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