Skip to content

Commit 9fa4519

Browse files
authored
feat(select): add support for a separate selected label (#607)
1 parent abcfcad commit 9fa4519

File tree

4 files changed

+11
-5
lines changed

4 files changed

+11
-5
lines changed

projects/components/src/select/select-option.component.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ export class SelectOptionComponent<V> implements OnChanges, SelectOption<V> {
1515
@Input()
1616
public label!: string;
1717

18+
@Input()
19+
public selectedLabel?: string;
20+
1821
@Input()
1922
public style: SelectOptionStyle = SelectOptionStyle.Default;
2023

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
export interface SelectOption<V> {
22
value: V;
33
label: string;
4+
selectedLabel?: string;
45
icon?: string;
56
iconColor?: string;
67
}

projects/components/src/select/select.component.test.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,10 @@ describe('Select Component', () => {
2727
const selectionOptions = [
2828
{ label: 'first', value: 'first-value' },
2929
{ label: 'second', value: 'second-value' },
30-
{ label: 'third', value: 'third-value' }
30+
{ label: 'third', value: 'third-value', selectedLabel: 'Third Value!!!' }
3131
];
3232

33-
test('should display intial selection', fakeAsync(() => {
33+
test('should display initial selection', fakeAsync(() => {
3434
spectator = hostFactory(
3535
`
3636
<ht-select [selected]="selected">
@@ -127,7 +127,7 @@ describe('Select Component', () => {
127127
spectator = hostFactory(
128128
`
129129
<ht-select [selected]="selected" (selectedChange)="onChange($event)">
130-
<ht-select-option *ngFor="let option of options" [label]="option.label" [value]="option.value">
130+
<ht-select-option *ngFor="let option of options" [label]="option.label" [value]="option.value" [selectedLabel]="option.selectedLabel">
131131
</ht-select-option>
132132
</ht-select>`,
133133
{
@@ -140,14 +140,15 @@ describe('Select Component', () => {
140140
);
141141

142142
spectator.tick();
143+
expect(spectator.query('.trigger-content')).toHaveText(selectionOptions[1].label);
143144
spectator.click('.trigger-content');
144145

145146
const optionElements = spectator.queryAll('.select-option', { root: true });
146147
spectator.click(optionElements[2]);
147148

148149
expect(onChange).toHaveBeenCalledTimes(1);
149150
expect(onChange).toHaveBeenCalledWith(selectionOptions[2].value);
150-
expect(spectator.element).toHaveText(selectionOptions[2].label);
151+
expect(spectator.query('.trigger-content')).toHaveText(selectionOptions[2].selectedLabel!);
151152
flush();
152153
}));
153154

projects/components/src/select/select.component.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,8 @@ import { SelectSize } from './select-size';
5454
>
5555
<ht-icon *ngIf="this.icon" class="trigger-prefix-icon" [icon]="this.icon" [size]="this.iconSize">
5656
</ht-icon>
57-
<ht-label class="trigger-label" [label]="selected?.label || this.placeholder"> </ht-label>
57+
<ht-label class="trigger-label" [label]="selected?.selectedLabel || selected?.label || this.placeholder">
58+
</ht-label>
5859
<ht-icon class="trigger-icon" icon="${IconType.ChevronDown}" size="${IconSize.ExtraSmall}"> </ht-icon>
5960
</div>
6061
<div

0 commit comments

Comments
 (0)