Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions projects/components/src/select/select-option.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ export class SelectOptionComponent<V> implements OnChanges, SelectOption<V> {
@Input()
public label!: string;

@Input()
public selectedLabel?: string;

@Input()
public style: SelectOptionStyle = SelectOptionStyle.Default;

Expand Down
1 change: 1 addition & 0 deletions projects/components/src/select/select-option.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
export interface SelectOption<V> {
value: V;
label: string;
selectedLabel?: string;
icon?: string;
iconColor?: string;
}
9 changes: 5 additions & 4 deletions projects/components/src/select/select.component.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@ describe('Select Component', () => {
const selectionOptions = [
{ label: 'first', value: 'first-value' },
{ label: 'second', value: 'second-value' },
{ label: 'third', value: 'third-value' }
{ label: 'third', value: 'third-value', selectedLabel: 'Third Value!!!' }
];

test('should display intial selection', fakeAsync(() => {
test('should display initial selection', fakeAsync(() => {
spectator = hostFactory(
`
<ht-select [selected]="selected">
Expand Down Expand Up @@ -127,7 +127,7 @@ describe('Select Component', () => {
spectator = hostFactory(
`
<ht-select [selected]="selected" (selectedChange)="onChange($event)">
<ht-select-option *ngFor="let option of options" [label]="option.label" [value]="option.value">
<ht-select-option *ngFor="let option of options" [label]="option.label" [value]="option.value" [selectedLabel]="option.selectedLabel">
</ht-select-option>
</ht-select>`,
{
Expand All @@ -140,14 +140,15 @@ describe('Select Component', () => {
);

spectator.tick();
expect(spectator.query('.trigger-content')).toHaveText(selectionOptions[1].label);
spectator.click('.trigger-content');

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

expect(onChange).toHaveBeenCalledTimes(1);
expect(onChange).toHaveBeenCalledWith(selectionOptions[2].value);
expect(spectator.element).toHaveText(selectionOptions[2].label);
expect(spectator.query('.trigger-content')).toHaveText(selectionOptions[2].selectedLabel!);
flush();
}));

Expand Down
3 changes: 2 additions & 1 deletion projects/components/src/select/select.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ import { SelectSize } from './select-size';
>
<ht-icon *ngIf="this.icon" class="trigger-prefix-icon" [icon]="this.icon" [size]="this.iconSize">
</ht-icon>
<ht-label class="trigger-label" [label]="selected?.label || this.placeholder"> </ht-label>
<ht-label class="trigger-label" [label]="selected?.selectedLabel || selected?.label || this.placeholder">
</ht-label>
<ht-icon class="trigger-icon" icon="${IconType.ChevronDown}" size="${IconSize.ExtraSmall}"> </ht-icon>
</div>
<div
Expand Down