Skip to content

Commit 54c6bbd

Browse files
chore: micro host directive
1 parent 78ad2e0 commit 54c6bbd

File tree

4 files changed

+25
-21
lines changed

4 files changed

+25
-21
lines changed

projects/core/components/textfield/textfield.component.ts

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,16 +25,14 @@ import type {TuiDataListHost} from '@taiga-ui/core/components/data-list';
2525
import {tuiAsDataListHost} from '@taiga-ui/core/components/data-list';
2626
import {TuiLabel} from '@taiga-ui/core/components/label';
2727
import {
28-
TUI_DROPDOWN_OPTIONS,
2928
TuiDropdownDirective,
29+
TuiDropdownFixed,
3030
tuiDropdownOpen,
31-
tuiDropdownOptionsProvider,
3231
TuiWithDropdownOpen,
3332
} from '@taiga-ui/core/directives/dropdown';
3433
import {TuiWithIcons} from '@taiga-ui/core/directives/icons';
3534
import {TUI_COMMON_ICONS} from '@taiga-ui/core/tokens';
3635
import type {TuiSizeL, TuiSizeS} from '@taiga-ui/core/types';
37-
import {tuiOverrideDefaultOptions} from '@taiga-ui/core/utils';
3836
import type {PolymorpheusContent} from '@taiga-ui/polymorpheus';
3937
import {PolymorpheusOutlet} from '@taiga-ui/polymorpheus';
4038

@@ -50,8 +48,9 @@ import {TuiWithTextfieldDropdown} from './textfield-dropdown.directive';
5048
styles: ['@import "@taiga-ui/core/styles/components/textfield.less";'],
5149
encapsulation: ViewEncapsulation.None,
5250
changeDetection: ChangeDetectionStrategy.OnPush,
53-
providers: [tuiAsDataListHost(TuiTextfieldComponent), tuiDropdownOptionsProvider({})],
51+
providers: [tuiAsDataListHost(TuiTextfieldComponent)],
5452
hostDirectives: [
53+
TuiDropdownFixed,
5554
TuiDropdownDirective,
5655
TuiWithDropdownOpen,
5756
TuiWithTextfieldDropdown,
@@ -82,9 +81,6 @@ export class TuiTextfieldComponent<T> implements TuiDataListHost<T> {
8281
protected readonly control?: NgControl;
8382

8483
protected readonly icons = inject(TUI_COMMON_ICONS);
85-
protected readonly override = tuiOverrideDefaultOptions(TUI_DROPDOWN_OPTIONS, {
86-
limitWidth: 'fixed',
87-
});
8884

8985
protected computedFiller = computed(() => {
9086
const value = this.directive?.nativeValue() || '';
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import {Directive, inject} from '@angular/core';
2+
import {tuiOverrideOptions} from '@taiga-ui/core/utils/miscellaneous';
3+
4+
import {
5+
TUI_DROPDOWN_DEFAULT_OPTIONS,
6+
TUI_DROPDOWN_OPTIONS,
7+
} from './dropdown-options.directive';
8+
9+
@Directive({
10+
standalone: true,
11+
})
12+
export class TuiDropdownFixed {
13+
constructor() {
14+
const override = tuiOverrideOptions(
15+
{limitWidth: 'fixed'},
16+
TUI_DROPDOWN_DEFAULT_OPTIONS,
17+
);
18+
19+
override(inject(TUI_DROPDOWN_OPTIONS), TUI_DROPDOWN_DEFAULT_OPTIONS);
20+
}
21+
}

projects/core/directives/dropdown/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,4 @@ export * from './dropdown-position-sided.directive';
1818
export * from './dropdown-selection.directive';
1919
export * from './dropdowns.component';
2020
export * from './with-dropdown-open.directive';
21+
export * from './dropdown-fixed.directive';
Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
import type {ProviderToken} from '@angular/core';
2-
import {inject} from '@angular/core';
3-
41
export function tuiOverrideOptions<T>(
52
override: Partial<T>,
63
fallback: T,
@@ -16,14 +13,3 @@ export function tuiOverrideOptions<T>(
1613
return result;
1714
};
1815
}
19-
20-
export function tuiOverrideDefaultOptions<T>(
21-
key: ProviderToken<T>,
22-
options: Partial<T>,
23-
): void {
24-
const defaultOptions = inject(key, {self: true});
25-
26-
Object.keys(options).forEach((key) => {
27-
(defaultOptions as Record<string, unknown>)[key] = options[key as keyof T];
28-
});
29-
}

0 commit comments

Comments
 (0)