diff --git a/projects/common/src/telemetry/providers/google-analytics/google-analytics-provider.ts b/projects/common/src/telemetry/providers/google-analytics/google-analytics-provider.ts index 9c005dbb1..c78608278 100644 --- a/projects/common/src/telemetry/providers/google-analytics/google-analytics-provider.ts +++ b/projects/common/src/telemetry/providers/google-analytics/google-analytics-provider.ts @@ -1,5 +1,5 @@ -import { Dictionary } from './../../../utilities/types/types'; import { TelemetryProviderConfig, UserTelemetryProvider, UserTraits } from '../../telemetry'; +import { Dictionary } from './../../../utilities/types/types'; import { loadGA } from './load-snippet'; export class GoogleAnalyticsTelemetry diff --git a/projects/components/src/select/directive/select-option-renderer.directive.test.ts b/projects/components/src/select/directive/select-option-renderer.directive.test.ts new file mode 100644 index 000000000..e94b999df --- /dev/null +++ b/projects/components/src/select/directive/select-option-renderer.directive.test.ts @@ -0,0 +1,21 @@ +import { createDirectiveFactory, SpectatorDirective } from '@ngneat/spectator/jest'; +import { SelectOptionRendererDirective } from './select-option-renderer.directive'; + +describe('Select Option Renderer directive', () => { + let spectator: SpectatorDirective; + + const createDirective = createDirectiveFactory({ + directive: SelectOptionRendererDirective + }); + + beforeEach(() => { + spectator = createDirective(` +
content
+ `); + }); + + test('should render content', () => { + const content = spectator.directive.getTemplateRef(); + expect(content).toExist(); + }); +}); diff --git a/projects/components/src/select/directive/select-option-renderer.directive.ts b/projects/components/src/select/directive/select-option-renderer.directive.ts new file mode 100644 index 000000000..0287699b8 --- /dev/null +++ b/projects/components/src/select/directive/select-option-renderer.directive.ts @@ -0,0 +1,12 @@ +import { Directive, TemplateRef } from '@angular/core'; + +@Directive({ + selector: '[htSelectOptionRenderer]' +}) +export class SelectOptionRendererDirective { + public constructor(private readonly templateRef: TemplateRef) {} + + public getTemplateRef(): TemplateRef { + return this.templateRef; + } +} diff --git a/projects/components/src/select/select-option.component.ts b/projects/components/src/select/select-option.component.ts index a7df89585..01e9e9cab 100644 --- a/projects/components/src/select/select-option.component.ts +++ b/projects/components/src/select/select-option.component.ts @@ -1,13 +1,14 @@ -import { ChangeDetectionStrategy, Component, Input, OnChanges } from '@angular/core'; +import { ChangeDetectionStrategy, Component, ContentChild, Input, OnChanges } from '@angular/core'; import { IconType } from '@hypertrace/assets-library'; import { Observable, Subject } from 'rxjs'; import { IconBorder } from '../icon/icon-border'; +import { SelectOptionRendererDirective } from './directive/select-option-renderer.directive'; import { SelectOption } from './select-option'; @Component({ selector: 'ht-select-option', changeDetection: ChangeDetectionStrategy.OnPush, - template: '' // No template, just gathering data + template: `` }) export class SelectOptionComponent implements OnChanges, SelectOption { @Input() @@ -40,6 +41,9 @@ export class SelectOptionComponent implements OnChanges, SelectOption { @Input() public disabled?: boolean; + @ContentChild(SelectOptionRendererDirective) + public selectOptionRenderer?: SelectOptionRendererDirective; + private readonly optionChangeSubject$: Subject = new Subject(); public readonly optionChange$: Observable = this.optionChangeSubject$.asObservable(); diff --git a/projects/components/src/select/select-option.ts b/projects/components/src/select/select-option.ts index 054a3b17b..b12538796 100644 --- a/projects/components/src/select/select-option.ts +++ b/projects/components/src/select/select-option.ts @@ -1,6 +1,6 @@ export interface SelectOption { value: V; - label: string; + label?: string; selectedLabel?: string; icon?: string; iconColor?: string; diff --git a/projects/components/src/select/select.component.test.ts b/projects/components/src/select/select.component.test.ts index 5ee890849..42e24a49f 100644 --- a/projects/components/src/select/select.component.test.ts +++ b/projects/components/src/select/select.component.test.ts @@ -60,6 +60,26 @@ describe('Select Component', () => { expect(spectator.element).toHaveText(selectionOptions[2].label); })); + test('should display initial selection for new select renderer', fakeAsync(() => { + spectator = hostFactory( + ` + + +
new-label
+
+
`, + { + hostProps: { + options: selectionOptions, + selected: selectionOptions[1].value + } + } + ); + spectator.tick(); + + expect(spectator.element).toHaveText('new-label'); + })); + test('should display provided options when clicked', fakeAsync(() => { spectator = hostFactory( ` diff --git a/projects/components/src/select/select.component.ts b/projects/components/src/select/select.component.ts index a015067f1..494af48e4 100644 --- a/projects/components/src/select/select.component.ts +++ b/projects/components/src/select/select.component.ts @@ -55,20 +55,28 @@ import { SelectSize } from './select-size'; class="trigger-content menu-with-border" [ngClass]="[this.justifyClass]" > - - - - + + + + + + @@ -111,7 +127,6 @@ import { SelectSize } from './select-size'; *ngTemplateOutlet="itemsTemplate; context: { items: items, showSelectionStatus: true }" > -
-
- - - {{ item.label }} -
+
+ +
+ + + {{ item.label }} +
+
diff --git a/projects/components/src/select/select.module.ts b/projects/components/src/select/select.module.ts index 7a49b5802..90bea359c 100644 --- a/projects/components/src/select/select.module.ts +++ b/projects/components/src/select/select.module.ts @@ -8,6 +8,7 @@ import { LabelModule } from '../label/label.module'; import { LetAsyncModule } from '../let-async/let-async.module'; import { PopoverModule } from '../popover/popover.module'; import { TooltipModule } from '../tooltip/tooltip.module'; +import { SelectOptionRendererDirective } from './directive/select-option-renderer.directive'; import { SelectControlOptionComponent } from './select-control-option.component'; import { SelectGroupComponent } from './select-group.component'; import { SelectOptionComponent } from './select-option.component'; @@ -25,7 +26,19 @@ import { SelectComponent } from './select.component'; DividerModule, MemoizeModule ], - declarations: [SelectComponent, SelectOptionComponent, SelectGroupComponent, SelectControlOptionComponent], - exports: [SelectComponent, SelectOptionComponent, SelectGroupComponent, SelectControlOptionComponent] + declarations: [ + SelectComponent, + SelectOptionComponent, + SelectGroupComponent, + SelectControlOptionComponent, + SelectOptionRendererDirective + ], + exports: [ + SelectComponent, + SelectOptionComponent, + SelectGroupComponent, + SelectControlOptionComponent, + SelectOptionRendererDirective + ] }) export class SelectModule {}