-
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
ComboBox: Option to use ariaLabel prop as preview text #4540
ComboBox: Option to use ariaLabel prop as preview text #4540
Conversation
Updating fork
merging master
Merge master into kysedate fork
…t. This is necessary for cases where embedded text is used as the option text
@@ -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); |
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.
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); |
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.
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) } |
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.
What about the multiSelect case?
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.
I'm not sure what you mean..
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.
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 |
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.
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 { |
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.
this seems like a good place to add a comment explaining why are we doing this
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.
Pull request checklist
$ 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.