Skip to content

Commit 0a05867

Browse files
feat(grid): add icon on chips
1 parent da5f6bb commit 0a05867

File tree

3 files changed

+32
-0
lines changed

3 files changed

+32
-0
lines changed

projects/angular/components/ui-suggest/src/ui-suggest.component.html

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,14 @@
102102
[matTooltip]="intl.translateLabel(option.text)"
103103
(removed)="deselectItem(option)"
104104
class="chip-selectable">
105+
<mat-icon *ngIf="!!option?.icon?.svgIcon"
106+
[svgIcon]="option!.icon!.svgIcon!"
107+
class="chip-selectable-icon">
108+
</mat-icon>
109+
<mat-icon *ngIf="!!option?.icon?.matIcon"
110+
class="chip-selectable-icon">
111+
{{option?.icon?.matIcon}}
112+
</mat-icon>
105113
<span>
106114
{{ intl.translateLabel(option.text) }}
107115
</span>

projects/angular/components/ui-suggest/src/ui-suggest.component.scss

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,10 @@ $componentName: "ui-suggest";
205205
.mat-chip {
206206
max-width: calc(100% - #{$chips-container-padding * 2});
207207

208+
.chip-selectable-icon {
209+
padding-right: $chips-container-padding;
210+
}
211+
208212
span {
209213
@extend %ellipse;
210214
}

projects/angular/components/ui-suggest/src/ui-suggest.component.spec.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1076,6 +1076,26 @@ const sharedSpecifications = (
10761076
component.defaultValue = undefined;
10771077
});
10781078

1079+
it('should display icon in value if passed', fakeAsync(() => {
1080+
const suggestValue = {
1081+
id: '1',
1082+
text: '1',
1083+
icon: {
1084+
matIcon: 'close',
1085+
},
1086+
};
1087+
1088+
component.items = [suggestValue];
1089+
component.value = [suggestValue];
1090+
1091+
fixture.detectChanges();
1092+
tick();
1093+
1094+
expect(fixture.debugElement.query(By.css('.chip-selectable-icon'))).toBeTruthy();
1095+
1096+
discardPeriodicTasks();
1097+
}));
1098+
10791099
describe('a11y', () => {
10801100
a11y.suite((runOptions) => {
10811101
a11y.it('should have no violations', async () => {

0 commit comments

Comments
 (0)