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 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
8 changes: 3 additions & 5 deletions projects/core/components/textfield/textfield.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ import {tuiAsDataListHost} from '@taiga-ui/core/components/data-list';
import {TuiLabel} from '@taiga-ui/core/components/label';
import {
TuiDropdownDirective,
TuiDropdownFixed,
tuiDropdownOpen,
tuiDropdownOptionsProvider,
TuiWithDropdownOpen,
} from '@taiga-ui/core/directives/dropdown';
import {TuiWithIcons} from '@taiga-ui/core/directives/icons';
Expand All @@ -48,11 +48,9 @@ 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)],
hostDirectives: [
TuiDropdownFixed,
TuiDropdownDirective,
TuiWithDropdownOpen,
TuiWithTextfieldDropdown,
Expand Down
23 changes: 23 additions & 0 deletions projects/core/directives/dropdown/dropdown-fixed.directive.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import {Directive, inject} from '@angular/core';
import {tuiOverrideOptions} from '@taiga-ui/core/utils/miscellaneous';

import {
TUI_DROPDOWN_DEFAULT_OPTIONS,
TUI_DROPDOWN_OPTIONS,
tuiDropdownOptionsProvider,
} from './dropdown-options.directive';

@Directive({
standalone: true,
providers: [tuiDropdownOptionsProvider({})],
})
export class TuiDropdownFixed {
constructor() {
const override = tuiOverrideOptions(
{limitWidth: 'fixed'},
TUI_DROPDOWN_DEFAULT_OPTIONS,
);

override(inject(TUI_DROPDOWN_OPTIONS, {self: true, optional: true}), null);
}
}
1 change: 1 addition & 0 deletions projects/core/directives/dropdown/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ export * from './dropdown.driver';
export * from './dropdown.providers';
export * from './dropdown.service';
export * from './dropdown-context.directive';
export * from './dropdown-fixed.directive';
export * from './dropdown-hover.directive';
export * from './dropdown-hover.options';
export * from './dropdown-manual.directive';
Expand Down
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
5 changes: 2 additions & 3 deletions projects/legacy/components/combo-box/combo-box.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import {
tuiAsOptionContent,
TuiDataListDirective,
} from '@taiga-ui/core/components/data-list';
import {TuiDropdownOpen} from '@taiga-ui/core/directives/dropdown';
import {TuiDropdownFixed, TuiDropdownOpen} from '@taiga-ui/core/directives/dropdown';
import type {
TuiSizeL,
TuiSizeM,
Expand All @@ -40,7 +40,6 @@ import {TUI_SELECT_OPTION} from '@taiga-ui/legacy/components/select-option';
import {TUI_TEXTFIELD_SIZE} from '@taiga-ui/legacy/directives';
import type {TuiFocusableElementAccessor} from '@taiga-ui/legacy/tokens';
import {tuiAsFocusableItemAccessor} from '@taiga-ui/legacy/tokens';
import {FIXED_DROPDOWN_CONTROLLER_PROVIDER} from '@taiga-ui/legacy/utils';
import type {PolymorpheusContent} from '@taiga-ui/polymorpheus';

@Component({
Expand All @@ -55,7 +54,7 @@ import type {PolymorpheusContent} from '@taiga-ui/polymorpheus';
tuiAsControl(TuiComboBoxComponent),
tuiAsOptionContent(TUI_SELECT_OPTION),
],
viewProviders: [FIXED_DROPDOWN_CONTROLLER_PROVIDER],
hostDirectives: [TuiDropdownFixed],
host: {
'[attr.data-size]': 'size',
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {tuiPure} from '@taiga-ui/cdk/utils/miscellaneous';
import {TuiButton} from '@taiga-ui/core/components/button';
import {TuiDataList} from '@taiga-ui/core/components/data-list';
import {TuiAppearance} from '@taiga-ui/core/directives/appearance';
import {TuiDropdown} from '@taiga-ui/core/directives/dropdown';
import {TuiDropdown, TuiDropdownFixed} from '@taiga-ui/core/directives/dropdown';
import {TuiGroup} from '@taiga-ui/core/directives/group';
import {TuiHint} from '@taiga-ui/core/directives/hint';
import {TuiFlagPipe} from '@taiga-ui/core/pipes/flag';
Expand All @@ -40,11 +40,7 @@ import {
import {TuiIsoToCountryCodePipe, TuiToCountryCodePipe} from '@taiga-ui/legacy/pipes';
import type {TuiFocusableElementAccessor} from '@taiga-ui/legacy/tokens';
import {TUI_COUNTRIES_MASKS, tuiAsFocusableItemAccessor} from '@taiga-ui/legacy/tokens';
import {
FIXED_DROPDOWN_CONTROLLER_PROVIDER,
tuiGetMaxAllowedPhoneLength,
tuiIsoToCountryCode,
} from '@taiga-ui/legacy/utils';
import {tuiGetMaxAllowedPhoneLength, tuiIsoToCountryCode} from '@taiga-ui/legacy/utils';
import type {PolymorpheusContent} from '@taiga-ui/polymorpheus';
import {PolymorpheusOutlet, PolymorpheusTemplate} from '@taiga-ui/polymorpheus';

Expand Down Expand Up @@ -87,7 +83,7 @@ const MASK_SYMBOLS = /[ \-_()]/g;
tuiAsControl(TuiInputPhoneInternationalComponent),
TuiToCountryCodePipe,
],
viewProviders: [FIXED_DROPDOWN_CONTROLLER_PROVIDER],
hostDirectives: [TuiDropdownFixed],
host: {
'[attr.data-size]': 'size',
'(paste.capture.prevent.stop)': 'onPaste($event)',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,13 @@ import {
tuiAsDataListHost,
TuiDataListDirective,
} from '@taiga-ui/core/components/data-list';
import {TuiDropdownOpen} from '@taiga-ui/core/directives/dropdown';
import {TuiDropdownFixed, TuiDropdownOpen} from '@taiga-ui/core/directives/dropdown';
import type {TuiSizeL, TuiSizeS} from '@taiga-ui/core/types';
import {AbstractTuiControl, tuiAsControl} from '@taiga-ui/legacy/classes';
import {TuiPrimitiveTextfieldComponent} from '@taiga-ui/legacy/components/primitive-textfield';
import {TUI_TEXTFIELD_CLEANER, TUI_TEXTFIELD_SIZE} from '@taiga-ui/legacy/directives';
import type {TuiFocusableElementAccessor} from '@taiga-ui/legacy/tokens';
import {tuiAsFocusableItemAccessor} from '@taiga-ui/legacy/tokens';
import {FIXED_DROPDOWN_CONTROLLER_PROVIDER} from '@taiga-ui/legacy/utils';

import {TUI_INPUT_PHONE_OPTIONS} from './input-phone.options';
import {
Expand All @@ -53,7 +52,7 @@ function isText(value: string): boolean {
tuiAsControl(TuiInputPhoneComponent),
tuiAsDataListHost(TuiInputPhoneComponent),
],
viewProviders: [FIXED_DROPDOWN_CONTROLLER_PROVIDER],
hostDirectives: [TuiDropdownFixed],
host: {
'[attr.data-size]': 'size',
},
Expand Down
5 changes: 2 additions & 3 deletions projects/legacy/components/input-tag/input-tag.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import {
TuiDataListDirective,
} from '@taiga-ui/core/components/data-list';
import {TuiScrollbar} from '@taiga-ui/core/components/scrollbar';
import {TuiDropdownOpen} from '@taiga-ui/core/directives/dropdown';
import {TuiDropdownFixed, TuiDropdownOpen} from '@taiga-ui/core/directives/dropdown';
import {TuiHintOptionsDirective} from '@taiga-ui/core/directives/hint';
import {TUI_COMMON_ICONS} from '@taiga-ui/core/tokens';
import type {TuiSizeL, TuiSizeS} from '@taiga-ui/core/types';
Expand All @@ -44,7 +44,6 @@ import {
import type {TuiFocusableElementAccessor} from '@taiga-ui/legacy/tokens';
import {tuiAsFocusableItemAccessor} from '@taiga-ui/legacy/tokens';
import type {TuiStatus} from '@taiga-ui/legacy/utils';
import {FIXED_DROPDOWN_CONTROLLER_PROVIDER} from '@taiga-ui/legacy/utils';
import type {PolymorpheusContent} from '@taiga-ui/polymorpheus';
import {PolymorpheusOutlet} from '@taiga-ui/polymorpheus';
import {timer} from 'rxjs';
Expand Down Expand Up @@ -75,7 +74,7 @@ const TAG_VERTICAL_SPACE_REM = 0.125;
tuiAsDataListHost(TuiInputTagComponent),
TEXTFIELD_CONTROLLER_PROVIDER,
],
viewProviders: [FIXED_DROPDOWN_CONTROLLER_PROVIDER],
hostDirectives: [TuiDropdownFixed],
host: {
'[attr.data-size]': 'size',
'[class._icon-start]': 'iconStart',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import {tuiIsNativeFocused} from '@taiga-ui/cdk/utils/focus';
import {tuiPure} from '@taiga-ui/cdk/utils/miscellaneous';
import type {TuiDataListHost} from '@taiga-ui/core/components/data-list';
import {tuiAsDataListHost, tuiAsOptionContent} from '@taiga-ui/core/components/data-list';
import {TuiDropdownFixed} from '@taiga-ui/core/directives/dropdown';
import type {TuiSizeL, TuiSizeS} from '@taiga-ui/core/types';
import {TUI_TIME_TEXTS, TUI_TIME_VALUE_TRANSFORMER} from '@taiga-ui/kit/tokens';
import {AbstractTuiNullableControl, tuiAsControl} from '@taiga-ui/legacy/classes';
Expand All @@ -27,7 +28,6 @@ import {TUI_SELECT_OPTION} from '@taiga-ui/legacy/components/select-option';
import {TUI_TEXTFIELD_SIZE} from '@taiga-ui/legacy/directives';
import type {TuiFocusableElementAccessor} from '@taiga-ui/legacy/tokens';
import {tuiAsFocusableItemAccessor} from '@taiga-ui/legacy/tokens';
import {FIXED_DROPDOWN_CONTROLLER_PROVIDER} from '@taiga-ui/legacy/utils';
import type {Observable} from 'rxjs';
import {map, timer} from 'rxjs';

Expand All @@ -46,7 +46,7 @@ import {TUI_INPUT_TIME_OPTIONS} from './input-time.options';
tuiAsDataListHost(TuiInputTimeComponent),
tuiAsOptionContent(TUI_SELECT_OPTION),
],
viewProviders: [FIXED_DROPDOWN_CONTROLLER_PROVIDER],
hostDirectives: [TuiDropdownFixed],
host: {
'(click)': 'onClick()',
'[attr.data-size]': 'size',
Expand Down
5 changes: 2 additions & 3 deletions projects/legacy/components/input/input.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {
tuiAsDataListHost,
TuiDataListDirective,
} from '@taiga-ui/core/components/data-list';
import {TuiDropdownOpen} from '@taiga-ui/core/directives/dropdown';
import {TuiDropdownFixed, TuiDropdownOpen} from '@taiga-ui/core/directives/dropdown';
import type {TuiSizeL, TuiSizeS} from '@taiga-ui/core/types';
import {AbstractTuiControl, tuiAsControl} from '@taiga-ui/legacy/classes';
import {TuiPrimitiveTextfieldComponent} from '@taiga-ui/legacy/components/primitive-textfield';
Expand All @@ -24,7 +24,6 @@ import {
} from '@taiga-ui/legacy/directives';
import type {TuiFocusableElementAccessor} from '@taiga-ui/legacy/tokens';
import {tuiAsFocusableItemAccessor} from '@taiga-ui/legacy/tokens';
import {FIXED_DROPDOWN_CONTROLLER_PROVIDER} from '@taiga-ui/legacy/utils';
import type {PolymorpheusContent} from '@taiga-ui/polymorpheus';

@Component({
Expand All @@ -39,7 +38,7 @@ import type {PolymorpheusContent} from '@taiga-ui/polymorpheus';
tuiAsDataListHost(TuiInputComponent),
tuiAsControl(TuiInputComponent),
],
viewProviders: [FIXED_DROPDOWN_CONTROLLER_PROVIDER],
viewProviders: [TuiDropdownFixed],
host: {
'[attr.data-size]': 'size',
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import {
tuiAsDataListHost,
TuiDataListDirective,
} from '@taiga-ui/core/components/data-list';
import {TuiDropdownOpen} from '@taiga-ui/core/directives/dropdown';
import {TuiDropdownFixed, TuiDropdownOpen} from '@taiga-ui/core/directives/dropdown';
import type {TuiSizeL, TuiSizeM, TuiSizeS} from '@taiga-ui/core/types';
import type {TuiItemsHandlers} from '@taiga-ui/kit/tokens';
import {TUI_ITEMS_HANDLERS} from '@taiga-ui/kit/tokens';
Expand All @@ -46,7 +46,6 @@ import {
} from '@taiga-ui/legacy/directives';
import type {TuiFocusableElementAccessor} from '@taiga-ui/legacy/tokens';
import {tuiAsFocusableItemAccessor} from '@taiga-ui/legacy/tokens';
import {FIXED_DROPDOWN_CONTROLLER_PROVIDER} from '@taiga-ui/legacy/utils';
import type {PolymorpheusContent} from '@taiga-ui/polymorpheus';

import type {TuiMultiSelectOptions} from './multi-select.options';
Expand All @@ -65,7 +64,7 @@ import {AbstractTuiNativeMultiSelect} from './native-multi-select/native-multi-s
tuiAsDataListHost(TuiMultiSelectComponent),
TEXTFIELD_CONTROLLER_PROVIDER,
],
viewProviders: [FIXED_DROPDOWN_CONTROLLER_PROVIDER],
hostDirectives: [TuiDropdownFixed],
host: {
'[attr.data-size]': 'size',
'[class._editable]': 'editable',
Expand Down
5 changes: 2 additions & 3 deletions projects/legacy/components/select/select.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import {
tuiAsOptionContent,
TuiDataListDirective,
} from '@taiga-ui/core/components/data-list';
import {TuiDropdownOpen} from '@taiga-ui/core/directives/dropdown';
import {TuiDropdownFixed, TuiDropdownOpen} from '@taiga-ui/core/directives/dropdown';
import type {
TuiSizeL,
TuiSizeM,
Expand All @@ -37,7 +37,6 @@ import {TUI_SELECT_OPTION} from '@taiga-ui/legacy/components/select-option';
import {TUI_TEXTFIELD_CLEANER, TUI_TEXTFIELD_SIZE} from '@taiga-ui/legacy/directives';
import type {TuiFocusableElementAccessor} from '@taiga-ui/legacy/tokens';
import {tuiAsFocusableItemAccessor} from '@taiga-ui/legacy/tokens';
import {FIXED_DROPDOWN_CONTROLLER_PROVIDER} from '@taiga-ui/legacy/utils';
import type {PolymorpheusContent} from '@taiga-ui/polymorpheus';

import type {TuiSelectOptions} from './select.options';
Expand All @@ -55,7 +54,7 @@ import {TUI_SELECT_OPTIONS} from './select.options';
tuiAsDataListHost(TuiSelectComponent),
tuiAsOptionContent(TUI_SELECT_OPTION),
],
viewProviders: [FIXED_DROPDOWN_CONTROLLER_PROVIDER],
hostDirectives: [TuiDropdownFixed],
host: {
'[attr.data-size]': 'size',
},
Expand Down
Loading