Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(core): fix overriding default dropdown options #9348

Merged
merged 5 commits into from
Oct 7, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
10 changes: 6 additions & 4 deletions projects/core/components/textfield/textfield.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import type {TuiDataListHost} from '@taiga-ui/core/components/data-list';
import {tuiAsDataListHost} from '@taiga-ui/core/components/data-list';
import {TuiLabel} from '@taiga-ui/core/components/label';
import {
TUI_DROPDOWN_OPTIONS,
TuiDropdownDirective,
tuiDropdownOpen,
tuiDropdownOptionsProvider,
Expand All @@ -33,6 +34,7 @@ import {
import {TuiWithIcons} from '@taiga-ui/core/directives/icons';
import {TUI_COMMON_ICONS} from '@taiga-ui/core/tokens';
import type {TuiSizeL, TuiSizeS} from '@taiga-ui/core/types';
import {tuiOverrideDefaultOptions} from '@taiga-ui/core/utils';
import type {PolymorpheusContent} from '@taiga-ui/polymorpheus';
import {PolymorpheusOutlet} from '@taiga-ui/polymorpheus';

Expand All @@ -48,10 +50,7 @@ import {TuiWithTextfieldDropdown} from './textfield-dropdown.directive';
styles: ['@import "@taiga-ui/core/styles/components/textfield.less";'],
encapsulation: ViewEncapsulation.None,
changeDetection: ChangeDetectionStrategy.OnPush,
providers: [
tuiAsDataListHost(TuiTextfieldComponent),
tuiDropdownOptionsProvider({limitWidth: 'fixed'}),
],
providers: [tuiAsDataListHost(TuiTextfieldComponent), tuiDropdownOptionsProvider({})],
hostDirectives: [
TuiDropdownDirective,
TuiWithDropdownOpen,
Expand Down Expand Up @@ -83,6 +82,9 @@ export class TuiTextfieldComponent<T> implements TuiDataListHost<T> {
protected readonly control?: NgControl;

protected readonly icons = inject(TUI_COMMON_ICONS);
protected readonly override = tuiOverrideDefaultOptions(TUI_DROPDOWN_OPTIONS, {
splincode marked this conversation as resolved.
Show resolved Hide resolved
limitWidth: 'fixed',
});

protected computedFiller = computed(() => {
const value = this.directive?.nativeValue() || '';
Expand Down
14 changes: 14 additions & 0 deletions projects/core/utils/miscellaneous/override-options.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import type {ProviderToken} from '@angular/core';
import {inject} from '@angular/core';

export function tuiOverrideOptions<T>(
override: Partial<T>,
fallback: T,
Expand All @@ -13,3 +16,14 @@ export function tuiOverrideOptions<T>(
return result;
};
}

export function tuiOverrideDefaultOptions<T>(
key: ProviderToken<T>,
options: Partial<T>,
): void {
const defaultOptions = inject(key, {self: true});

Object.keys(options).forEach((key) => {
(defaultOptions as Record<string, unknown>)[key] = options[key as keyof T];
});
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,20 @@
[items]="items"
/>
</tui-textfield>

<tui-textfield
tuiChevron
tuiDropdownLimitWidth="auto"
>
<label tuiLabel>Dropdown setting</label>
<select
placeholder="I am placeholder"
tuiTextfield
[(ngModel)]="value"
></select>
<tui-icon tuiTooltip="Fixed choice select" />
<tui-data-list-wrapper
*tuiTextfieldDropdown
[items]="items"
/>
</tui-textfield>
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import {Component, inject} from '@angular/core';
import {FormsModule} from '@angular/forms';
import {changeDetection} from '@demo/emulate/change-detection';
import {encapsulation} from '@demo/emulate/encapsulation';
import {TuiIcon, TuiTextfield} from '@taiga-ui/core';
import {TuiDropdownOptionsDirective, TuiIcon, TuiTextfield} from '@taiga-ui/core';
import {
TuiChevron,
TuiDataListWrapper,
Expand All @@ -16,6 +16,7 @@ import {
FormsModule,
TuiChevron,
TuiDataListWrapper,
TuiDropdownOptionsDirective,
TuiFilterByInputPipe,
TuiIcon,
TuiTextfield,
Expand Down
Loading