Skip to content

Commit 78ad2e0

Browse files
fix(core): fix overriding default dropdown options
1 parent 5c2bcdf commit 78ad2e0

File tree

4 files changed

+39
-5
lines changed

4 files changed

+39
-5
lines changed

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

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ 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,
2829
TuiDropdownDirective,
2930
tuiDropdownOpen,
3031
tuiDropdownOptionsProvider,
@@ -33,6 +34,7 @@ import {
3334
import {TuiWithIcons} from '@taiga-ui/core/directives/icons';
3435
import {TUI_COMMON_ICONS} from '@taiga-ui/core/tokens';
3536
import type {TuiSizeL, TuiSizeS} from '@taiga-ui/core/types';
37+
import {tuiOverrideDefaultOptions} from '@taiga-ui/core/utils';
3638
import type {PolymorpheusContent} from '@taiga-ui/polymorpheus';
3739
import {PolymorpheusOutlet} from '@taiga-ui/polymorpheus';
3840

@@ -48,10 +50,7 @@ import {TuiWithTextfieldDropdown} from './textfield-dropdown.directive';
4850
styles: ['@import "@taiga-ui/core/styles/components/textfield.less";'],
4951
encapsulation: ViewEncapsulation.None,
5052
changeDetection: ChangeDetectionStrategy.OnPush,
51-
providers: [
52-
tuiAsDataListHost(TuiTextfieldComponent),
53-
tuiDropdownOptionsProvider({limitWidth: 'fixed'}),
54-
],
53+
providers: [tuiAsDataListHost(TuiTextfieldComponent), tuiDropdownOptionsProvider({})],
5554
hostDirectives: [
5655
TuiDropdownDirective,
5756
TuiWithDropdownOpen,
@@ -83,6 +82,9 @@ export class TuiTextfieldComponent<T> implements TuiDataListHost<T> {
8382
protected readonly control?: NgControl;
8483

8584
protected readonly icons = inject(TUI_COMMON_ICONS);
85+
protected readonly override = tuiOverrideDefaultOptions(TUI_DROPDOWN_OPTIONS, {
86+
limitWidth: 'fixed',
87+
});
8688

8789
protected computedFiller = computed(() => {
8890
const value = this.directive?.nativeValue() || '';

projects/core/utils/miscellaneous/override-options.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
import type {ProviderToken} from '@angular/core';
2+
import {inject} from '@angular/core';
3+
14
export function tuiOverrideOptions<T>(
25
override: Partial<T>,
36
fallback: T,
@@ -13,3 +16,14 @@ export function tuiOverrideOptions<T>(
1316
return result;
1417
};
1518
}
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+
}

projects/demo/src/modules/components/textfield/examples/3/index.html

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,20 @@
2525
[items]="items"
2626
/>
2727
</tui-textfield>
28+
29+
<tui-textfield
30+
tuiChevron
31+
tuiDropdownLimitWidth="auto"
32+
>
33+
<label tuiLabel>Dropdown setting</label>
34+
<select
35+
placeholder="I am placeholder"
36+
tuiTextfield
37+
[(ngModel)]="value"
38+
></select>
39+
<tui-icon tuiTooltip="Fixed choice select" />
40+
<tui-data-list-wrapper
41+
*tuiTextfieldDropdown
42+
[items]="items"
43+
/>
44+
</tui-textfield>

projects/demo/src/modules/components/textfield/examples/3/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import {Component, inject} from '@angular/core';
22
import {FormsModule} from '@angular/forms';
33
import {changeDetection} from '@demo/emulate/change-detection';
44
import {encapsulation} from '@demo/emulate/encapsulation';
5-
import {TuiIcon, TuiTextfield} from '@taiga-ui/core';
5+
import {TuiDropdownOptionsDirective, TuiIcon, TuiTextfield} from '@taiga-ui/core';
66
import {
77
TuiChevron,
88
TuiDataListWrapper,
@@ -16,6 +16,7 @@ import {
1616
FormsModule,
1717
TuiChevron,
1818
TuiDataListWrapper,
19+
TuiDropdownOptionsDirective,
1920
TuiFilterByInputPipe,
2021
TuiIcon,
2122
TuiTextfield,

0 commit comments

Comments
 (0)