Skip to content

Commit

Permalink
fix(list): disabled items not handled correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
jgroth authored and adrianschmidt committed Sep 10, 2019
1 parent 49bdc0d commit 7d822e3
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 6 deletions.
7 changes: 6 additions & 1 deletion src/components/list/list-renderer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -181,13 +181,18 @@ export class ListRenderer {
<CheckboxTemplate
id={`c_${index}`}
checked={item.selected}
disabled={item.disabled}
/>
</div>,
];
}
return [
<div class="mdc-list-item__graphic">
<CheckboxTemplate id={`c_${index}`} checked={item.selected} />
<CheckboxTemplate
id={`c_${index}`}
checked={item.selected}
disabled={item.disabled}
/>
</div>,
this.renderText(item.text, item.secondaryText),
];
Expand Down
4 changes: 3 additions & 1 deletion src/components/list/list.scss
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@
}

.mdc-list {
cursor: pointer;
&.selectable .mdc-list-item:not(.mdc-list-item--disabled) {
cursor: pointer;
}

&.mdc-list--avatar-list {
limel-icon {
Expand Down
4 changes: 2 additions & 2 deletions src/components/list/list.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ export class List {

private handleSingleSelect(index: number) {
const listItems: ListItem[] = this.items.filter(item => {
return !('separator' in item);
return !('separator' in item) && !item.disabled;
}) as ListItem[];
const selectedItem: ListItem = listItems.find((item: ListItem) => {
return !!item.selected;
Expand All @@ -109,7 +109,7 @@ export class List {

private handleMultiSelect(index: number) {
const listItems = this.items.filter(item => {
return !('separator' in item);
return !('separator' in item) && !item.disabled;
});
const selectedItems: ListItem[] = listItems
.filter((item: ListItem, listIndex: number) => {
Expand Down
2 changes: 2 additions & 0 deletions src/examples/list/list-checkbox-icons.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export class ListCheckboxIconsExample {
text: 'Charmander',
value: 2,
selected: false,
disabled: true,
icon: 'fire_element',
iconColor: 'var(--lime-red)',
},
Expand All @@ -34,6 +35,7 @@ export class ListCheckboxIconsExample {
text: 'Yoshi',
value: 4,
selected: false,
disabled: true,
icon: 'easter_egg',
iconColor: 'var(--lime-green)',
},
Expand Down
4 changes: 2 additions & 2 deletions src/examples/list/list-checkbox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ export class ListCheckboxExample {
@State()
private allItems: Array<ListItem | ListSeparator> = [
{ text: 'Pikachu', value: 1, selected: true },
{ text: 'Charmander', value: 2, selected: false },
{ text: 'Charmander', value: 2, selected: false, disabled: true },
{ text: 'Super Mario', value: 3, selected: false },
{ separator: true },
{ text: 'Yoshi', value: 4, selected: false },
{ text: 'Yoshi', value: 4, selected: false, disabled: true },
{ text: 'Minion', value: 6, selected: true },
{ text: 'Pokéball', value: 5, selected: false },
];
Expand Down

0 comments on commit 7d822e3

Please sign in to comment.