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

fix(listbox): set default title attributes to item text #5102

Merged
10 changes: 5 additions & 5 deletions packages/components/src/components/dropdown/dropdown.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
</button>
<ul class="{{@root.prefix}}--dropdown-list" id="{{default.idSuffix}}-menu" role="menu" tabindex="0" id="{{default.idSuffix}}-menu" aria-hidden="true" wh-menu-anchor="left" aria-labelledby="{{default.idSuffix}}-label">
{{#each items as |item index|}}
<li data-option data-value="{{value}}" class="{{@root.prefix}}--dropdown-item">
<li data-option data-value="{{value}}" class="{{@root.prefix}}--dropdown-item" title="{{label}}">
<a class="{{@root.prefix}}--dropdown-link" href="javascript:void(0)" tabindex="-1" role="menuitemradio" aria-checked="{{#if index}}false{{else}}true{{/if}}" id="{{../default.idSuffix}}-item{{@index}}">{{label}}</a>
</li>
{{/each}}
Expand All @@ -45,7 +45,7 @@
</button>
<ul class="{{@root.prefix}}--dropdown-list" role="menu" tabindex="0" id="{{helper.idSuffix}}-menu" aria-hidden="true" wh-menu-anchor="left" aria-labelledby="{{helper.idSuffix}}-label">
{{#each items as |item index|}}
<li data-option data-value="{{value}}" class="{{@root.prefix}}--dropdown-item">
<li data-option data-value="{{value}}" class="{{@root.prefix}}--dropdown-item" title="{{label}}">
<a class="{{@root.prefix}}--dropdown-link" href="javascript:void(0)" tabindex="-1" role="menuitemradio" aria-checked="{{#if index}}false{{else}}true{{/if}}" id="{{../helper.idSuffix}}-item{{@index}}">{{label}}</a>
</li>
{{/each}}
Expand Down Expand Up @@ -74,7 +74,7 @@
<!-- Note: remove `tabindex` from disabled dropdown lists -->
<ul class="{{@root.prefix}}--dropdown-list" id="{{disabled.idSuffix}}-menu" role="menu" id="{{disabled.idSuffix}}-menu" aria-hidden="true" wh-menu-anchor="left" aria-labelledby="{{disabled.idSuffix}}-label">
{{#each items as |item index|}}
<li data-option data-value="{{value}}" class="{{@root.prefix}}--dropdown-item">
<li data-option data-value="{{value}}" class="{{@root.prefix}}--dropdown-item" title="{{label}}">
<a class="{{@root.prefix}}--dropdown-link" href="javascript:void(0)" tabindex="-1" role="menuitemradio" aria-checked="{{#if index}}false{{else}}true{{/if}}" id="{{../disabled.idSuffix}}-item{{@index}}">{{label}}</a>
</li>
{{/each}}
Expand Down Expand Up @@ -103,7 +103,7 @@
</button>
<ul class="{{@root.prefix}}--dropdown-list" id="{{invalid.idSuffix}}-menu" role="menu" tabindex="0" id="{{invalid.idSuffix}}-menu" aria-hidden="true" wh-menu-anchor="left" aria-labelledby="{{invalid.idSuffix}}-label">
{{#each items as |item index|}}
<li data-option data-value="{{value}}" class="{{@root.prefix}}--dropdown-item">
<li data-option data-value="{{value}}" class="{{@root.prefix}}--dropdown-item" title="{{label}}">
<a class="{{@root.prefix}}--dropdown-link" href="javascript:void(0)" tabindex="-1" role="menuitemradio" aria-checked="{{#if index}}false{{else}}true{{/if}}" id="{{../invalid.idSuffix}}-item{{@index}}">{{label}}</a>
</li>
{{/each}}
Expand Down Expand Up @@ -138,7 +138,7 @@
</button>
<ul class="{{@root.prefix}}--dropdown-list" id="{{default.idSuffix}}-menu" role="menu" tabindex="0" id="{{default.idSuffix}}-menu" aria-hidden="true" wh-menu-anchor="left" aria-labelledby="{{default.idSuffix}}-label">
{{#each items as |item index|}}
<li data-option data-value="{{value}}" class="{{@root.prefix}}--dropdown-item">
<li data-option data-value="{{value}}" class="{{@root.prefix}}--dropdown-item" title="{{label}}">
<a class="{{@root.prefix}}--dropdown-link" href="javascript:void(0)" tabindex="-1" role="menuitemradio" aria-checked="{{#if index}}false{{else}}true{{/if}}" id="{{../default.idSuffix}}-item{{@index}}">{{label}}</a>
{{ carbon-icon 'Checkmark16' class=(add @root.prefix '--list-box__menu-item__selected-icon') aria-hidden="true" }}
</li>
Expand Down
1 change: 1 addition & 0 deletions packages/react/src/components/ComboBox/ComboBox.js
Original file line number Diff line number Diff line change
Expand Up @@ -401,6 +401,7 @@ export default class ComboBox extends React.Component {
(selectedItem && selectedItem.id === item.id) ||
false
}
title={itemToElement ? item.text : itemToString(item)}
{...itemProps}>
{itemToElement ? (
<ItemToElement key={itemProps.id} {...item} />
Expand Down
25 changes: 20 additions & 5 deletions packages/react/src/components/Dropdown/Dropdown-story.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,19 @@ const items = [
id: 'option-4',
text: 'Option 4',
},
{
id: 'option-5',
text:
'Lorem, ipsum dolor sit amet consectetur adipisicing elit. Vitae, aliquam. Blanditiis quia nemo enim voluptatibus quos ducimus porro molestiae nesciunt error cumque quaerat, tempore vero unde eum aperiam eligendi repellendus.',
},
];

const stringItems = ['Option 1', 'Option 2', 'Option 3'];
const stringItems = [
'Option 1',
'Option 2',
'Option 3',
'Lorem, ipsum dolor sit amet consectetur adipisicing elit. Vitae, aliquam. Blanditiis quia nemo enim voluptatibus quos ducimus porro molestiae nesciunt error cumque quaerat, tempore vero unde eum aperiam eligendi repellendus.',
];

const types = {
'Default (default)': 'default',
Expand Down Expand Up @@ -63,11 +73,16 @@ const props = () => ({
});

const itemToElement = item => {
const itemAsArray = item.text.split(' ');
const [first, ...rest] = item.text.split(' ');
return (
<div>
<span>{itemAsArray[0]}</span>
<span style={{ color: 'blue' }}> {itemAsArray[1]}</span>
<div
style={{
textOverflow: 'ellipsis',
overflow: 'hidden',
whiteSpace: 'nowrap',
}}>
<span>{first}</span>
<span style={{ color: 'blue' }}> {rest.join(' ')}</span>
</div>
);
};
Expand Down
1 change: 1 addition & 0 deletions packages/react/src/components/Dropdown/Dropdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,7 @@ export default class Dropdown extends React.Component {
isHighlighted={
highlightedIndex === index || selectedItem === item
}
title={itemToElement ? item.text : itemToString(item)}
{...itemProps}>
{itemToElement ? (
<ItemToElement key={itemProps.id} {...item} />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -689,13 +689,15 @@ exports[`Dropdown should render with strings as items 1`] = `
onClick={[Function]}
onMouseDown={[Function]}
onMouseMove={[Function]}
title="zar"
>
<div
className="bx--list-box__menu-item"
id="downshift-3-item-0"
onClick={[Function]}
onMouseDown={[Function]}
onMouseMove={[Function]}
title="zar"
>
<div
className="bx--list-box__menu-item__option"
Expand All @@ -712,13 +714,15 @@ exports[`Dropdown should render with strings as items 1`] = `
onClick={[Function]}
onMouseDown={[Function]}
onMouseMove={[Function]}
title="doz"
>
<div
className="bx--list-box__menu-item"
id="downshift-3-item-1"
onClick={[Function]}
onMouseDown={[Function]}
onMouseMove={[Function]}
title="doz"
>
<div
className="bx--list-box__menu-item__option"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -435,6 +435,7 @@ export default class FilterableMultiSelect extends React.Component {
key={itemProps.id}
isActive={isChecked}
isHighlighted={highlightedIndex === index}
title={itemText}
{...itemProps}>
<Checkbox
id={itemProps.id}
Expand Down
1 change: 1 addition & 0 deletions packages/react/src/components/MultiSelect/MultiSelect.js
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,7 @@ export default class MultiSelect extends React.Component {
key={itemProps.id}
isActive={isChecked}
isHighlighted={highlightedIndex === index}
title={itemText}
{...itemProps}>
<Checkbox
id={`${itemProps.id}__checkbox`}
Expand Down