@cute-widgets/base 20.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +1 -0
- package/LICENSE.md +191 -0
- package/README.md +190 -0
- package/abstract/index.d.ts +327 -0
- package/alert/index.d.ts +68 -0
- package/autocomplete/index.d.ts +442 -0
- package/badge/index.d.ts +26 -0
- package/bottom-sheet/index.d.ts +231 -0
- package/button/index.d.ts +182 -0
- package/button-toggle/index.d.ts +225 -0
- package/card/index.d.ts +163 -0
- package/checkbox/index.d.ts +174 -0
- package/chips/index.d.ts +963 -0
- package/collapse/index.d.ts +97 -0
- package/core/animation/index.d.ts +43 -0
- package/core/datetime/index.d.ts +404 -0
- package/core/directives/index.d.ts +168 -0
- package/core/error/index.d.ts +74 -0
- package/core/index.d.ts +1039 -0
- package/core/interfaces/index.d.ts +114 -0
- package/core/layout/index.d.ts +53 -0
- package/core/line/index.d.ts +37 -0
- package/core/nav/index.d.ts +321 -0
- package/core/observers/index.d.ts +124 -0
- package/core/option/index.d.ts +185 -0
- package/core/pipes/index.d.ts +53 -0
- package/core/ripple/index.d.ts +66 -0
- package/core/testing/index.d.ts +154 -0
- package/core/theming/index.d.ts +118 -0
- package/core/types/index.d.ts +53 -0
- package/core/utils/index.d.ts +129 -0
- package/cute-widgets-base-20.0.1.tgz +0 -0
- package/datepicker/index.d.ts +1817 -0
- package/dialog/index.d.ts +484 -0
- package/divider/index.d.ts +24 -0
- package/expansion/README.md +8 -0
- package/expansion/index.d.ts +308 -0
- package/fesm2022/cute-widgets-base-abstract.mjs +547 -0
- package/fesm2022/cute-widgets-base-abstract.mjs.map +1 -0
- package/fesm2022/cute-widgets-base-alert.mjs +198 -0
- package/fesm2022/cute-widgets-base-alert.mjs.map +1 -0
- package/fesm2022/cute-widgets-base-autocomplete.mjs +1217 -0
- package/fesm2022/cute-widgets-base-autocomplete.mjs.map +1 -0
- package/fesm2022/cute-widgets-base-badge.mjs +75 -0
- package/fesm2022/cute-widgets-base-badge.mjs.map +1 -0
- package/fesm2022/cute-widgets-base-bottom-sheet.mjs +416 -0
- package/fesm2022/cute-widgets-base-bottom-sheet.mjs.map +1 -0
- package/fesm2022/cute-widgets-base-button-toggle.mjs +640 -0
- package/fesm2022/cute-widgets-base-button-toggle.mjs.map +1 -0
- package/fesm2022/cute-widgets-base-button.mjs +546 -0
- package/fesm2022/cute-widgets-base-button.mjs.map +1 -0
- package/fesm2022/cute-widgets-base-card.mjs +471 -0
- package/fesm2022/cute-widgets-base-card.mjs.map +1 -0
- package/fesm2022/cute-widgets-base-checkbox.mjs +390 -0
- package/fesm2022/cute-widgets-base-checkbox.mjs.map +1 -0
- package/fesm2022/cute-widgets-base-chips.mjs +2360 -0
- package/fesm2022/cute-widgets-base-chips.mjs.map +1 -0
- package/fesm2022/cute-widgets-base-collapse.mjs +259 -0
- package/fesm2022/cute-widgets-base-collapse.mjs.map +1 -0
- package/fesm2022/cute-widgets-base-core-animation.mjs +53 -0
- package/fesm2022/cute-widgets-base-core-animation.mjs.map +1 -0
- package/fesm2022/cute-widgets-base-core-datetime.mjs +568 -0
- package/fesm2022/cute-widgets-base-core-datetime.mjs.map +1 -0
- package/fesm2022/cute-widgets-base-core-directives.mjs +404 -0
- package/fesm2022/cute-widgets-base-core-directives.mjs.map +1 -0
- package/fesm2022/cute-widgets-base-core-error.mjs +105 -0
- package/fesm2022/cute-widgets-base-core-error.mjs.map +1 -0
- package/fesm2022/cute-widgets-base-core-interfaces.mjs +22 -0
- package/fesm2022/cute-widgets-base-core-interfaces.mjs.map +1 -0
- package/fesm2022/cute-widgets-base-core-layout.mjs +74 -0
- package/fesm2022/cute-widgets-base-core-layout.mjs.map +1 -0
- package/fesm2022/cute-widgets-base-core-line.mjs +87 -0
- package/fesm2022/cute-widgets-base-core-line.mjs.map +1 -0
- package/fesm2022/cute-widgets-base-core-nav.mjs +863 -0
- package/fesm2022/cute-widgets-base-core-nav.mjs.map +1 -0
- package/fesm2022/cute-widgets-base-core-observers.mjs +304 -0
- package/fesm2022/cute-widgets-base-core-observers.mjs.map +1 -0
- package/fesm2022/cute-widgets-base-core-option.mjs +373 -0
- package/fesm2022/cute-widgets-base-core-option.mjs.map +1 -0
- package/fesm2022/cute-widgets-base-core-pipes.mjs +97 -0
- package/fesm2022/cute-widgets-base-core-pipes.mjs.map +1 -0
- package/fesm2022/cute-widgets-base-core-ripple.mjs +172 -0
- package/fesm2022/cute-widgets-base-core-ripple.mjs.map +1 -0
- package/fesm2022/cute-widgets-base-core-testing.mjs +210 -0
- package/fesm2022/cute-widgets-base-core-testing.mjs.map +1 -0
- package/fesm2022/cute-widgets-base-core-theming.mjs +314 -0
- package/fesm2022/cute-widgets-base-core-theming.mjs.map +1 -0
- package/fesm2022/cute-widgets-base-core-types.mjs +22 -0
- package/fesm2022/cute-widgets-base-core-types.mjs.map +1 -0
- package/fesm2022/cute-widgets-base-core-utils.mjs +257 -0
- package/fesm2022/cute-widgets-base-core-utils.mjs.map +1 -0
- package/fesm2022/cute-widgets-base-core.mjs +1600 -0
- package/fesm2022/cute-widgets-base-core.mjs.map +1 -0
- package/fesm2022/cute-widgets-base-datepicker.mjs +4827 -0
- package/fesm2022/cute-widgets-base-datepicker.mjs.map +1 -0
- package/fesm2022/cute-widgets-base-dialog.mjs +1046 -0
- package/fesm2022/cute-widgets-base-dialog.mjs.map +1 -0
- package/fesm2022/cute-widgets-base-divider.mjs +86 -0
- package/fesm2022/cute-widgets-base-divider.mjs.map +1 -0
- package/fesm2022/cute-widgets-base-expansion.mjs +623 -0
- package/fesm2022/cute-widgets-base-expansion.mjs.map +1 -0
- package/fesm2022/cute-widgets-base-form-field.mjs +969 -0
- package/fesm2022/cute-widgets-base-form-field.mjs.map +1 -0
- package/fesm2022/cute-widgets-base-grid-list.mjs +715 -0
- package/fesm2022/cute-widgets-base-grid-list.mjs.map +1 -0
- package/fesm2022/cute-widgets-base-icon.mjs +1105 -0
- package/fesm2022/cute-widgets-base-icon.mjs.map +1 -0
- package/fesm2022/cute-widgets-base-input.mjs +726 -0
- package/fesm2022/cute-widgets-base-input.mjs.map +1 -0
- package/fesm2022/cute-widgets-base-layout-container.mjs +95 -0
- package/fesm2022/cute-widgets-base-layout-container.mjs.map +1 -0
- package/fesm2022/cute-widgets-base-layout-stack.mjs +166 -0
- package/fesm2022/cute-widgets-base-layout-stack.mjs.map +1 -0
- package/fesm2022/cute-widgets-base-layout.mjs +250 -0
- package/fesm2022/cute-widgets-base-layout.mjs.map +1 -0
- package/fesm2022/cute-widgets-base-list.mjs +1557 -0
- package/fesm2022/cute-widgets-base-list.mjs.map +1 -0
- package/fesm2022/cute-widgets-base-menu.mjs +1283 -0
- package/fesm2022/cute-widgets-base-menu.mjs.map +1 -0
- package/fesm2022/cute-widgets-base-navbar.mjs +359 -0
- package/fesm2022/cute-widgets-base-navbar.mjs.map +1 -0
- package/fesm2022/cute-widgets-base-paginator.mjs +485 -0
- package/fesm2022/cute-widgets-base-paginator.mjs.map +1 -0
- package/fesm2022/cute-widgets-base-progress.mjs +321 -0
- package/fesm2022/cute-widgets-base-progress.mjs.map +1 -0
- package/fesm2022/cute-widgets-base-radio.mjs +637 -0
- package/fesm2022/cute-widgets-base-radio.mjs.map +1 -0
- package/fesm2022/cute-widgets-base-select.mjs +1208 -0
- package/fesm2022/cute-widgets-base-select.mjs.map +1 -0
- package/fesm2022/cute-widgets-base-sidenav.mjs +1095 -0
- package/fesm2022/cute-widgets-base-sidenav.mjs.map +1 -0
- package/fesm2022/cute-widgets-base-slider.mjs +99 -0
- package/fesm2022/cute-widgets-base-slider.mjs.map +1 -0
- package/fesm2022/cute-widgets-base-snack-bar.mjs +897 -0
- package/fesm2022/cute-widgets-base-snack-bar.mjs.map +1 -0
- package/fesm2022/cute-widgets-base-sort.mjs +639 -0
- package/fesm2022/cute-widgets-base-sort.mjs.map +1 -0
- package/fesm2022/cute-widgets-base-spinner.mjs +154 -0
- package/fesm2022/cute-widgets-base-spinner.mjs.map +1 -0
- package/fesm2022/cute-widgets-base-stepper.mjs +673 -0
- package/fesm2022/cute-widgets-base-stepper.mjs.map +1 -0
- package/fesm2022/cute-widgets-base-table.mjs +1023 -0
- package/fesm2022/cute-widgets-base-table.mjs.map +1 -0
- package/fesm2022/cute-widgets-base-tabs.mjs +729 -0
- package/fesm2022/cute-widgets-base-tabs.mjs.map +1 -0
- package/fesm2022/cute-widgets-base-timepicker.mjs +965 -0
- package/fesm2022/cute-widgets-base-timepicker.mjs.map +1 -0
- package/fesm2022/cute-widgets-base-toolbar.mjs +120 -0
- package/fesm2022/cute-widgets-base-toolbar.mjs.map +1 -0
- package/fesm2022/cute-widgets-base-tooltip.mjs +947 -0
- package/fesm2022/cute-widgets-base-tooltip.mjs.map +1 -0
- package/fesm2022/cute-widgets-base-tree.mjs +598 -0
- package/fesm2022/cute-widgets-base-tree.mjs.map +1 -0
- package/fesm2022/cute-widgets-base.mjs +68 -0
- package/fesm2022/cute-widgets-base.mjs.map +1 -0
- package/form-field/index.d.ts +401 -0
- package/grid-list/index.d.ts +361 -0
- package/icon/index.d.ts +477 -0
- package/index.d.ts +3 -0
- package/input/index.d.ts +256 -0
- package/layout/container/index.d.ts +31 -0
- package/layout/index.d.ts +78 -0
- package/layout/stack/index.d.ts +52 -0
- package/list/index.d.ts +659 -0
- package/menu/index.d.ts +497 -0
- package/navbar/index.d.ts +91 -0
- package/package.json +279 -0
- package/paginator/index.d.ts +216 -0
- package/progress/index.d.ts +130 -0
- package/radio/index.d.ts +259 -0
- package/select/index.d.ts +426 -0
- package/sidenav/index.d.ts +369 -0
- package/slider/index.d.ts +48 -0
- package/snack-bar/index.d.ts +374 -0
- package/sort/index.d.ts +334 -0
- package/spinner/index.d.ts +70 -0
- package/stepper/index.d.ts +295 -0
- package/table/index.d.ts +395 -0
- package/tabs/index.d.ts +307 -0
- package/timepicker/index.d.ts +350 -0
- package/toolbar/index.d.ts +36 -0
- package/tooltip/index.d.ts +299 -0
- package/tree/index.d.ts +314 -0
|
@@ -0,0 +1,1217 @@
|
|
|
1
|
+
import * as i0 from '@angular/core';
|
|
2
|
+
import { InjectionToken, inject, ChangeDetectorRef, ElementRef, EventEmitter, TemplateRef, booleanAttribute, Input, Output, ContentChildren, ViewChild, ChangeDetectionStrategy, ViewEncapsulation, Component, forwardRef, Injector, EnvironmentInjector, ViewContainerRef, NgZone, Renderer2, afterNextRender, isDevMode, Directive, NgModule } from '@angular/core';
|
|
3
|
+
import { CuteOption, CUTE_OPTGROUP, CUTE_OPTION_PARENT_COMPONENT, CuteOptionSelectionChange, _countGroupLabelsBeforeOption, _getOptionScrollPosition, CuteOptionModule } from '@cute-widgets/base/core/option';
|
|
4
|
+
import { ActiveDescendantKeyManager, removeAriaReferencedId, addAriaReferencedId } from '@angular/cdk/a11y';
|
|
5
|
+
import { Platform, _getEventTarget, _getFocusedElementPierceShadowDom } from '@angular/cdk/platform';
|
|
6
|
+
import { Subscription, Subject, defer, merge, EMPTY, of, Observable } from 'rxjs';
|
|
7
|
+
import { _animationsDisabled } from '@cute-widgets/base/core/animation';
|
|
8
|
+
import { Directionality } from '@angular/cdk/bidi';
|
|
9
|
+
import { ESCAPE, hasModifierKey, UP_ARROW, ENTER, DOWN_ARROW, TAB } from '@angular/cdk/keycodes';
|
|
10
|
+
import { TemplatePortal } from '@angular/cdk/portal';
|
|
11
|
+
import { ViewportRuler } from '@angular/cdk/scrolling';
|
|
12
|
+
import { createRepositionScrollStrategy, createOverlayRef, OverlayConfig, createFlexibleConnectedPositionStrategy } from '@angular/cdk/overlay';
|
|
13
|
+
import { BreakpointObserver, Breakpoints } from '@angular/cdk/layout';
|
|
14
|
+
import { coerceArray } from '@angular/cdk/coercion';
|
|
15
|
+
import { NG_VALUE_ACCESSOR } from '@angular/forms';
|
|
16
|
+
import { CUTE_FORM_FIELD } from '@cute-widgets/base/form-field';
|
|
17
|
+
import { startWith, switchMap, filter, map, tap, delay, take } from 'rxjs/operators';
|
|
18
|
+
import { _animationsDisabled as _animationsDisabled$1 } from '@cute-widgets/base/core';
|
|
19
|
+
import { CommonModule } from '@angular/common';
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* @license Apache-2.0
|
|
23
|
+
*
|
|
24
|
+
* Copyright (c) 2025 CuteWidgets Team. All Rights Reserved.
|
|
25
|
+
*
|
|
26
|
+
* You may not use this file except in compliance with the License
|
|
27
|
+
* that can be found at http://www.apache.org/licenses/LICENSE-2.0
|
|
28
|
+
*
|
|
29
|
+
* This code is a modification of the `@angular/material` original
|
|
30
|
+
* code licensed under MIT-style License (https://angular.dev/license).
|
|
31
|
+
*/
|
|
32
|
+
/**
|
|
33
|
+
* Autocomplete IDs need to be unique across components, so this counter exists outside
|
|
34
|
+
* the component definition.
|
|
35
|
+
*/
|
|
36
|
+
let _uniqueAutocompleteIdCounter = 0;
|
|
37
|
+
/** Event object that is emitted when an autocomplete option is selected. */
|
|
38
|
+
class CuteAutocompleteSelectedEvent {
|
|
39
|
+
constructor(
|
|
40
|
+
/** Reference to the autocomplete panel that emitted the event. */
|
|
41
|
+
source,
|
|
42
|
+
/** Option that was selected. */
|
|
43
|
+
option) {
|
|
44
|
+
this.source = source;
|
|
45
|
+
this.option = option;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
/** Injection token to be used to override the default options for `cute-autocomplete`. */
|
|
49
|
+
const CUTE_AUTOCOMPLETE_DEFAULT_OPTIONS = new InjectionToken('cute-autocomplete-default-options', {
|
|
50
|
+
providedIn: 'root',
|
|
51
|
+
factory: () => ({
|
|
52
|
+
autoActiveFirstOption: false,
|
|
53
|
+
autoSelectActiveOption: false,
|
|
54
|
+
hideSingleSelectionIndicator: false,
|
|
55
|
+
requireSelection: false,
|
|
56
|
+
hasBackdrop: false,
|
|
57
|
+
}),
|
|
58
|
+
});
|
|
59
|
+
/** Autocomplete component. */
|
|
60
|
+
class CuteAutocomplete {
|
|
61
|
+
/** Whether the autocomplete panel is open. */
|
|
62
|
+
get isOpen() {
|
|
63
|
+
return this._isOpen && this.showPanel;
|
|
64
|
+
}
|
|
65
|
+
/** @docs-private Sets the theme color of the panel. */
|
|
66
|
+
_setColor(value) {
|
|
67
|
+
this._color = value;
|
|
68
|
+
this._changeDetectorRef.markForCheck();
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Takes classes set on the host cute-autocomplete element and applies them to the panel
|
|
72
|
+
* inside the overlay container to allow for easy styling.
|
|
73
|
+
*/
|
|
74
|
+
set classList(value) {
|
|
75
|
+
this._classList = value;
|
|
76
|
+
this._elementRef.nativeElement.className = '';
|
|
77
|
+
}
|
|
78
|
+
/** Whether the checkmark indicator for single-selection options is hidden. */
|
|
79
|
+
get hideSingleSelectionIndicator() { return this._hideSingleSelectionIndicator; }
|
|
80
|
+
set hideSingleSelectionIndicator(value) {
|
|
81
|
+
this._hideSingleSelectionIndicator = value;
|
|
82
|
+
this._syncParentProperties();
|
|
83
|
+
}
|
|
84
|
+
/** Syncs the parent state with the individual options. */
|
|
85
|
+
_syncParentProperties() {
|
|
86
|
+
if (this.options) {
|
|
87
|
+
for (const option of this.options) {
|
|
88
|
+
option.markForCheck();
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
constructor() {
|
|
93
|
+
this._changeDetectorRef = inject(ChangeDetectorRef);
|
|
94
|
+
this._elementRef = inject(ElementRef);
|
|
95
|
+
this._defaults = inject(CUTE_AUTOCOMPLETE_DEFAULT_OPTIONS);
|
|
96
|
+
this._animationsDisabled = _animationsDisabled();
|
|
97
|
+
this._activeOptionChanges = Subscription.EMPTY;
|
|
98
|
+
/** Whether the autocomplete panel should be visible, depending on option length. */
|
|
99
|
+
this.showPanel = false;
|
|
100
|
+
this._isOpen = false;
|
|
101
|
+
/** Function that maps an option's control value to its display value in the trigger. */
|
|
102
|
+
this.displayWith = null;
|
|
103
|
+
/**
|
|
104
|
+
* Whether the first option should be highlighted when the autocomplete panel is opened.
|
|
105
|
+
* Can be configured globally through the `CUTE_AUTOCOMPLETE_DEFAULT_OPTIONS` token.
|
|
106
|
+
*/
|
|
107
|
+
this.autoActiveFirstOption = false;
|
|
108
|
+
/** Whether the active option should be selected as the user is navigating. */
|
|
109
|
+
this.autoSelectActiveOption = false;
|
|
110
|
+
/**
|
|
111
|
+
* Whether the user is required to make a choice when they're interacting with the
|
|
112
|
+
* autocomplete. If the user moves away from the autocomplete without selecting an option from
|
|
113
|
+
* the list, the value will be reset. If the user opens the panel and closes it without
|
|
114
|
+
* interacting or selecting a value, the initial value will be kept.
|
|
115
|
+
*/
|
|
116
|
+
this.requireSelection = false;
|
|
117
|
+
/** Whether ripples are disabled within the autocomplete panel. */
|
|
118
|
+
this.disableRipple = false;
|
|
119
|
+
/** Event that is emitted whenever an option from the list is selected. */
|
|
120
|
+
this.optionSelected = new EventEmitter();
|
|
121
|
+
/** Event that is emitted when the autocomplete panel is opened. */
|
|
122
|
+
this.opened = new EventEmitter();
|
|
123
|
+
/** Event that is emitted when the autocomplete panel is closed. */
|
|
124
|
+
this.closed = new EventEmitter();
|
|
125
|
+
/** Emits whenever an option is activated. */
|
|
126
|
+
this.optionActivated = new EventEmitter();
|
|
127
|
+
/** Unique ID to be used by autocomplete trigger's "aria-owns" property. */
|
|
128
|
+
this.id = `cute-autocomplete-${_uniqueAutocompleteIdCounter++}`;
|
|
129
|
+
const platform = inject(Platform);
|
|
130
|
+
// TODO(crisbeto): the problem that the `inertGroups` option resolves is only present on
|
|
131
|
+
// Safari using VoiceOver. We should occasionally check back to see whether the bug
|
|
132
|
+
// wasn't resolved in VoiceOver, and if it has, we can remove this and the `inertGroups`
|
|
133
|
+
// option altogether.
|
|
134
|
+
this.inertGroups = platform?.SAFARI || false;
|
|
135
|
+
this.autoActiveFirstOption = !!this._defaults.autoActiveFirstOption;
|
|
136
|
+
this.autoSelectActiveOption = !!this._defaults.autoSelectActiveOption;
|
|
137
|
+
this.requireSelection = !!this._defaults.requireSelection;
|
|
138
|
+
this._hideSingleSelectionIndicator = this._defaults.hideSingleSelectionIndicator ?? false;
|
|
139
|
+
}
|
|
140
|
+
ngAfterContentInit() {
|
|
141
|
+
this._keyManager = new ActiveDescendantKeyManager(this.options)
|
|
142
|
+
.withWrap()
|
|
143
|
+
.skipPredicate(this._skipPredicate);
|
|
144
|
+
this._activeOptionChanges = this._keyManager.change.subscribe(index => {
|
|
145
|
+
if (this.isOpen) {
|
|
146
|
+
this.optionActivated.emit({ source: this, option: this.options?.toArray()[index] || null });
|
|
147
|
+
}
|
|
148
|
+
});
|
|
149
|
+
// Set the initial visibility state.
|
|
150
|
+
this._setVisibility();
|
|
151
|
+
}
|
|
152
|
+
ngOnDestroy() {
|
|
153
|
+
this._keyManager?.destroy();
|
|
154
|
+
this._activeOptionChanges.unsubscribe();
|
|
155
|
+
}
|
|
156
|
+
/**
|
|
157
|
+
* Sets the panel scrollTop. This allows us to manually scroll to display options
|
|
158
|
+
* above or below the fold, as they are not being focused when active.
|
|
159
|
+
*/
|
|
160
|
+
_setScrollTop(scrollTop) {
|
|
161
|
+
if (this.panel) {
|
|
162
|
+
this.panel.nativeElement.scrollTop = scrollTop;
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
/** Returns the panel's scrollTop. */
|
|
166
|
+
_getScrollTop() {
|
|
167
|
+
return this.panel ? this.panel.nativeElement.scrollTop : 0;
|
|
168
|
+
}
|
|
169
|
+
/** The Panel should hide itself when the option list is empty. */
|
|
170
|
+
_setVisibility() {
|
|
171
|
+
this.showPanel = !!this.options?.length;
|
|
172
|
+
this._changeDetectorRef.markForCheck();
|
|
173
|
+
}
|
|
174
|
+
/** Emits the `select` event. */
|
|
175
|
+
_emitSelectEvent(option) {
|
|
176
|
+
const event = new CuteAutocompleteSelectedEvent(this, option);
|
|
177
|
+
this.optionSelected.emit(event);
|
|
178
|
+
}
|
|
179
|
+
/** Gets the aria-labelledby for the autocomplete panel. */
|
|
180
|
+
_getPanelAriaLabelledby(labelId) {
|
|
181
|
+
if (this.ariaLabel) {
|
|
182
|
+
return null;
|
|
183
|
+
}
|
|
184
|
+
const labelExpression = labelId ? labelId + ' ' : '';
|
|
185
|
+
return this.ariaLabelledby ? labelExpression + this.ariaLabelledby : labelId;
|
|
186
|
+
}
|
|
187
|
+
// `skipPredicate` determines if key manager should avoid putting a given option in the tab
|
|
188
|
+
// order. Allow disabled list items to receive focus via keyboard to align with WAI ARIA
|
|
189
|
+
// recommendation.
|
|
190
|
+
//
|
|
191
|
+
// Normally WAI ARIA's instructions are to exclude disabled items from the tab order, but it
|
|
192
|
+
// makes a few exceptions for compound widgets.
|
|
193
|
+
//
|
|
194
|
+
// From [Developing a Keyboard Interface](
|
|
195
|
+
// https://www.w3.org/WAI/ARIA/apg/practices/keyboard-interface/):
|
|
196
|
+
// "For the following composite widget elements, keep them focusable when disabled: Options in a
|
|
197
|
+
// Listbox..."
|
|
198
|
+
//
|
|
199
|
+
// The user can focus on disabled options using the keyboard, but the user cannot click disabled
|
|
200
|
+
// options.
|
|
201
|
+
_skipPredicate() {
|
|
202
|
+
return false;
|
|
203
|
+
}
|
|
204
|
+
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.3.15", ngImport: i0, type: CuteAutocomplete, deps: [], target: i0.ɵɵFactoryTarget.Component }); }
|
|
205
|
+
static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "16.1.0", version: "20.3.15", type: CuteAutocomplete, isStandalone: true, selector: "cute-autocomplete", inputs: { ariaLabel: ["aria-label", "ariaLabel"], ariaLabelledby: ["aria-labelledby", "ariaLabelledby"], displayWith: "displayWith", autoActiveFirstOption: ["autoActiveFirstOption", "autoActiveFirstOption", booleanAttribute], autoSelectActiveOption: ["autoSelectActiveOption", "autoSelectActiveOption", booleanAttribute], requireSelection: ["requireSelection", "requireSelection", booleanAttribute], panelWidth: "panelWidth", disableRipple: ["disableRipple", "disableRipple", booleanAttribute], classList: ["class", "classList"], hideSingleSelectionIndicator: ["hideSingleSelectionIndicator", "hideSingleSelectionIndicator", booleanAttribute] }, outputs: { optionSelected: "optionSelected", opened: "opened", closed: "closed", optionActivated: "optionActivated" }, host: { classAttribute: "cute-autocomplete" }, providers: [{ provide: CUTE_OPTION_PARENT_COMPONENT, useExisting: CuteAutocomplete }], queries: [{ propertyName: "options", predicate: CuteOption, descendants: true }, { propertyName: "optionGroups", predicate: CUTE_OPTGROUP, descendants: true }], viewQueries: [{ propertyName: "template", first: true, predicate: TemplateRef, descendants: true, static: true }, { propertyName: "panel", first: true, predicate: ["panel"], descendants: true }], exportAs: ["cuteAutocomplete"], ngImport: i0, template: "<ng-template let-formFieldId=\"id\">\r\n <div\r\n class=\"cute-autocomplete-panel cute-menu-surface bg-body-tertiary shadow\"\r\n role=\"listbox\"\r\n [id]=\"id\"\r\n [class]=\"_classList\"\r\n [class.cute-autocomplete-visible]=\"showPanel\"\r\n [class.cute-autocomplete-hidden]=\"!showPanel\"\r\n [class.cute-autocomplete-panel-animations-enabled]=\"!_animationsDisabled\"\r\n [class.cute-primary]=\"_color === 'primary'\"\r\n [class.cute-danger]=\"_color === 'danger'\"\r\n [class.cute-warning]=\"_color === 'warning'\"\r\n [attr.aria-label]=\"ariaLabel || null\"\r\n [attr.aria-labelledby]=\"_getPanelAriaLabelledby(formFieldId)\"\r\n #panel>\r\n <ng-content></ng-content>\r\n </div>\r\n</ng-template>\r\n", styles: [".cdk-overlay-pane .cute-autocomplete-panel{width:100%;max-height:256px;visibility:hidden;transform-origin:center top;overflow:auto;padding:.5rem 0;font-size:var(--bs-body-font-size);color:var(--bs-body-color);text-align:start;list-style:none;box-sizing:border-box;position:relative;border:var(--bs-border-width) solid var(--bs-border-color-translucent);border-radius:var(--bs-border-radius);background-color:var(--bs-body-bg)}@media (forced-colors: active){.cdk-overlay-pane .cute-autocomplete-panel{outline:solid 1px}}.cdk-overlay-pane .cute-autocomplete-panel.cute-autocomplete-visible{visibility:visible}.cdk-overlay-pane .cute-autocomplete-panel.cute-autocomplete-hidden{visibility:hidden}@keyframes _cute-autocomplete-enter{0%{opacity:0;transform:scaleY(.8)}to{opacity:1;transform:none}}.cute-autocomplete-panel-animations-enabled{animation:_cute-autocomplete-enter .12s cubic-bezier(0,0,.2,1)}cute-autocomplete{display:none}\n"], changeDetection: i0.ChangeDetectionStrategy.OnPush, encapsulation: i0.ViewEncapsulation.None }); }
|
|
206
|
+
}
|
|
207
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.15", ngImport: i0, type: CuteAutocomplete, decorators: [{
|
|
208
|
+
type: Component,
|
|
209
|
+
args: [{ selector: 'cute-autocomplete', encapsulation: ViewEncapsulation.None, changeDetection: ChangeDetectionStrategy.OnPush, exportAs: 'cuteAutocomplete', host: {
|
|
210
|
+
'class': 'cute-autocomplete',
|
|
211
|
+
}, providers: [{ provide: CUTE_OPTION_PARENT_COMPONENT, useExisting: CuteAutocomplete }], template: "<ng-template let-formFieldId=\"id\">\r\n <div\r\n class=\"cute-autocomplete-panel cute-menu-surface bg-body-tertiary shadow\"\r\n role=\"listbox\"\r\n [id]=\"id\"\r\n [class]=\"_classList\"\r\n [class.cute-autocomplete-visible]=\"showPanel\"\r\n [class.cute-autocomplete-hidden]=\"!showPanel\"\r\n [class.cute-autocomplete-panel-animations-enabled]=\"!_animationsDisabled\"\r\n [class.cute-primary]=\"_color === 'primary'\"\r\n [class.cute-danger]=\"_color === 'danger'\"\r\n [class.cute-warning]=\"_color === 'warning'\"\r\n [attr.aria-label]=\"ariaLabel || null\"\r\n [attr.aria-labelledby]=\"_getPanelAriaLabelledby(formFieldId)\"\r\n #panel>\r\n <ng-content></ng-content>\r\n </div>\r\n</ng-template>\r\n", styles: [".cdk-overlay-pane .cute-autocomplete-panel{width:100%;max-height:256px;visibility:hidden;transform-origin:center top;overflow:auto;padding:.5rem 0;font-size:var(--bs-body-font-size);color:var(--bs-body-color);text-align:start;list-style:none;box-sizing:border-box;position:relative;border:var(--bs-border-width) solid var(--bs-border-color-translucent);border-radius:var(--bs-border-radius);background-color:var(--bs-body-bg)}@media (forced-colors: active){.cdk-overlay-pane .cute-autocomplete-panel{outline:solid 1px}}.cdk-overlay-pane .cute-autocomplete-panel.cute-autocomplete-visible{visibility:visible}.cdk-overlay-pane .cute-autocomplete-panel.cute-autocomplete-hidden{visibility:hidden}@keyframes _cute-autocomplete-enter{0%{opacity:0;transform:scaleY(.8)}to{opacity:1;transform:none}}.cute-autocomplete-panel-animations-enabled{animation:_cute-autocomplete-enter .12s cubic-bezier(0,0,.2,1)}cute-autocomplete{display:none}\n"] }]
|
|
212
|
+
}], ctorParameters: () => [], propDecorators: { template: [{
|
|
213
|
+
type: ViewChild,
|
|
214
|
+
args: [TemplateRef, { static: true }]
|
|
215
|
+
}], panel: [{
|
|
216
|
+
type: ViewChild,
|
|
217
|
+
args: ['panel']
|
|
218
|
+
}], options: [{
|
|
219
|
+
type: ContentChildren,
|
|
220
|
+
args: [CuteOption, { descendants: true }]
|
|
221
|
+
}], optionGroups: [{
|
|
222
|
+
type: ContentChildren,
|
|
223
|
+
args: [CUTE_OPTGROUP, { descendants: true }]
|
|
224
|
+
}], ariaLabel: [{
|
|
225
|
+
type: Input,
|
|
226
|
+
args: ['aria-label']
|
|
227
|
+
}], ariaLabelledby: [{
|
|
228
|
+
type: Input,
|
|
229
|
+
args: ['aria-labelledby']
|
|
230
|
+
}], displayWith: [{
|
|
231
|
+
type: Input
|
|
232
|
+
}], autoActiveFirstOption: [{
|
|
233
|
+
type: Input,
|
|
234
|
+
args: [{ transform: booleanAttribute }]
|
|
235
|
+
}], autoSelectActiveOption: [{
|
|
236
|
+
type: Input,
|
|
237
|
+
args: [{ transform: booleanAttribute }]
|
|
238
|
+
}], requireSelection: [{
|
|
239
|
+
type: Input,
|
|
240
|
+
args: [{ transform: booleanAttribute }]
|
|
241
|
+
}], panelWidth: [{
|
|
242
|
+
type: Input
|
|
243
|
+
}], disableRipple: [{
|
|
244
|
+
type: Input,
|
|
245
|
+
args: [{ transform: booleanAttribute }]
|
|
246
|
+
}], optionSelected: [{
|
|
247
|
+
type: Output
|
|
248
|
+
}], opened: [{
|
|
249
|
+
type: Output
|
|
250
|
+
}], closed: [{
|
|
251
|
+
type: Output
|
|
252
|
+
}], optionActivated: [{
|
|
253
|
+
type: Output
|
|
254
|
+
}], classList: [{
|
|
255
|
+
type: Input,
|
|
256
|
+
args: ['class']
|
|
257
|
+
}], hideSingleSelectionIndicator: [{
|
|
258
|
+
type: Input,
|
|
259
|
+
args: [{ transform: booleanAttribute }]
|
|
260
|
+
}] } });
|
|
261
|
+
|
|
262
|
+
/**
|
|
263
|
+
* @license Apache-2.0
|
|
264
|
+
*
|
|
265
|
+
* Copyright (c) 2025 CuteWidgets Team. All Rights Reserved.
|
|
266
|
+
*
|
|
267
|
+
* You may not use this file except in compliance with the License
|
|
268
|
+
* that can be found at http://www.apache.org/licenses/LICENSE-2.0
|
|
269
|
+
*
|
|
270
|
+
* This code is a modification of the `@angular/material` original
|
|
271
|
+
* code licensed under MIT-style License (https://angular.dev/license).
|
|
272
|
+
*/
|
|
273
|
+
/**
|
|
274
|
+
* Provider that allows the autocomplete to register as a ControlValueAccessor.
|
|
275
|
+
* @docs-private
|
|
276
|
+
*/
|
|
277
|
+
const CUTE_AUTOCOMPLETE_VALUE_ACCESSOR = {
|
|
278
|
+
provide: NG_VALUE_ACCESSOR,
|
|
279
|
+
useExisting: forwardRef(() => CuteAutocompleteTrigger),
|
|
280
|
+
multi: true,
|
|
281
|
+
};
|
|
282
|
+
/**
|
|
283
|
+
* Creates an error to be thrown when attempting to use an autocomplete trigger without a panel.
|
|
284
|
+
* @docs-private
|
|
285
|
+
*/
|
|
286
|
+
function getCuteAutocompleteMissingPanelError() {
|
|
287
|
+
return Error('Attempting to open an undefined instance of `cute-autocomplete`. ' +
|
|
288
|
+
'Make sure that the id passed to the `cuteAutocomplete` is correct and that ' +
|
|
289
|
+
"you're attempting to open it after the ngAfterContentInit hook.");
|
|
290
|
+
}
|
|
291
|
+
/** Injection token that determines the scroll handling while the autocomplete panel is open. */
|
|
292
|
+
const CUTE_AUTOCOMPLETE_SCROLL_STRATEGY = new InjectionToken('cute-autocomplete-scroll-strategy', {
|
|
293
|
+
providedIn: 'root',
|
|
294
|
+
factory: () => {
|
|
295
|
+
const injector = inject(Injector);
|
|
296
|
+
return () => createRepositionScrollStrategy(injector);
|
|
297
|
+
},
|
|
298
|
+
});
|
|
299
|
+
/** Base class with all the `CuteAutocompleteTrigger` functionality. */
|
|
300
|
+
class CuteAutocompleteTrigger {
|
|
301
|
+
constructor() {
|
|
302
|
+
this._environmentInjector = inject(EnvironmentInjector);
|
|
303
|
+
this._element = inject(ElementRef);
|
|
304
|
+
this._injector = inject(Injector);
|
|
305
|
+
this._viewContainerRef = inject(ViewContainerRef);
|
|
306
|
+
this._zone = inject(NgZone);
|
|
307
|
+
this._changeDetectorRef = inject(ChangeDetectorRef);
|
|
308
|
+
this._dir = inject(Directionality, { optional: true });
|
|
309
|
+
this._formField = inject(CUTE_FORM_FIELD, { optional: true, host: true });
|
|
310
|
+
this._viewportRuler = inject(ViewportRuler);
|
|
311
|
+
this._scrollStrategy = inject(CUTE_AUTOCOMPLETE_SCROLL_STRATEGY);
|
|
312
|
+
this._renderer = inject(Renderer2);
|
|
313
|
+
this._animationsDisabled = _animationsDisabled$1();
|
|
314
|
+
this._defaults = inject(CUTE_AUTOCOMPLETE_DEFAULT_OPTIONS, { optional: true });
|
|
315
|
+
this._overlayRef = null;
|
|
316
|
+
this._componentDestroyed = false;
|
|
317
|
+
this._initialized = new Subject();
|
|
318
|
+
this._keydownSubscription = null;
|
|
319
|
+
this._outsideClickSubscription = null;
|
|
320
|
+
/** Old value of the native input. Used to work around issues with the `input` event on IE. */
|
|
321
|
+
this._previousValue = null;
|
|
322
|
+
/** Value of the input element when the panel was attached (even if there are no options). */
|
|
323
|
+
this._valueOnAttach = null;
|
|
324
|
+
/** Value on the previous keydown event. */
|
|
325
|
+
this._valueOnLastKeydown = null;
|
|
326
|
+
/** Whether the label state is being overridden. */
|
|
327
|
+
this._manuallyFloatingLabel = false;
|
|
328
|
+
/** Subscription to viewport size changes. */
|
|
329
|
+
this._viewportSubscription = Subscription.EMPTY;
|
|
330
|
+
/** Implements BreakpointObserver to be used to detect handset landscape */
|
|
331
|
+
this._breakpointObserver = inject(BreakpointObserver);
|
|
332
|
+
this._handsetLandscapeSubscription = Subscription.EMPTY;
|
|
333
|
+
/**
|
|
334
|
+
* Whether the autocomplete can open the next time, it is focused. Used to prevent a focused,
|
|
335
|
+
* closed autocomplete from being reopened if the user switches to another browser tab and then
|
|
336
|
+
* comes back.
|
|
337
|
+
*/
|
|
338
|
+
this._canOpenOnNextFocus = true;
|
|
339
|
+
/**
|
|
340
|
+
* The current option that we have auto-selected as the user is navigating,
|
|
341
|
+
* but which hasn't been propagated to the model value yet.
|
|
342
|
+
*/
|
|
343
|
+
this._pendingAutoselectedOption = null;
|
|
344
|
+
/** Stream of keyboard events that can close the panel. */
|
|
345
|
+
this._closeKeyEventStream = new Subject();
|
|
346
|
+
/** Classes to apply to the panel. Exposed as a public property for internal usage. */
|
|
347
|
+
this._overlayPanelClass = coerceArray(this._defaults?.overlayPanelClass || []);
|
|
348
|
+
/**
|
|
349
|
+
* Event handler for when the window is blurred. Needs to be an
|
|
350
|
+
* arrow function to preserve the context.
|
|
351
|
+
*/
|
|
352
|
+
this._windowBlurHandler = () => {
|
|
353
|
+
// If the user blurred the window while the autocomplete is focused, it means that it'll be
|
|
354
|
+
// refocused when they come back. In this case, we want to skip the first focus event if the
|
|
355
|
+
// pane was closed, to avoid reopening it unintentionally.
|
|
356
|
+
this._canOpenOnNextFocus = this.panelOpen || !this._hasFocus();
|
|
357
|
+
};
|
|
358
|
+
/** `View -> model callback called when value changes` */
|
|
359
|
+
this._onChange = () => { };
|
|
360
|
+
/** `View -> model callback called when autocomplete has been touched` */
|
|
361
|
+
this._onTouched = () => { };
|
|
362
|
+
/**
|
|
363
|
+
* Position of the autocomplete panel relative to the trigger element. A position of `auto`
|
|
364
|
+
* will render the panel underneath the trigger if there is enough space for it to fit in
|
|
365
|
+
* the viewport, otherwise the panel will be shown above it. If the position is set to
|
|
366
|
+
* `above` or `below`, the panel will always be shown above or below the trigger. no matter
|
|
367
|
+
* whether it fits completely in the viewport.
|
|
368
|
+
*/
|
|
369
|
+
this.position = 'auto';
|
|
370
|
+
/**
|
|
371
|
+
* `autocomplete` attribute to be set on the input element.
|
|
372
|
+
* @docs-private
|
|
373
|
+
*/
|
|
374
|
+
this.autocompleteAttribute = 'off';
|
|
375
|
+
/**
|
|
376
|
+
* Whether the autocomplete is disabled. When disabled, the element will
|
|
377
|
+
* act as a regular input and the user won't be able to open the panel.
|
|
378
|
+
*/
|
|
379
|
+
this.autocompleteDisabled = false;
|
|
380
|
+
/** Class to apply to the panel when it's above the input. */
|
|
381
|
+
this._aboveClass = 'cute-autocomplete-panel-above';
|
|
382
|
+
this._overlayAttached = false;
|
|
383
|
+
/** Stream of changes to the selection state of the autocomplete options. */
|
|
384
|
+
this.optionSelections = defer(() => {
|
|
385
|
+
const options = this.autocomplete ? this.autocomplete.options : null;
|
|
386
|
+
if (options) {
|
|
387
|
+
return options.changes.pipe(startWith(options), switchMap(() => merge(...options.map(option => option.onSelectionChange))));
|
|
388
|
+
}
|
|
389
|
+
// If there are any subscribers before `ngAfterViewInit`, the `autocomplete` will be undefined.
|
|
390
|
+
// Return a stream that we'll replace with the real one once everything is in place.
|
|
391
|
+
return this._initialized.pipe(switchMap(() => this.optionSelections));
|
|
392
|
+
});
|
|
393
|
+
/** Handles keyboard events coming from the overlay panel. */
|
|
394
|
+
this._handlePanelKeydown = (event) => {
|
|
395
|
+
// Close when pressing ESCAPE or ALT + UP_ARROW, based on the a11y guidelines.
|
|
396
|
+
// See: https://www.w3.org/TR/wai-aria-practices-1.1/#textbox-keyboard-interaction
|
|
397
|
+
if ((event.keyCode === ESCAPE && !hasModifierKey(event)) ||
|
|
398
|
+
(event.keyCode === UP_ARROW && hasModifierKey(event, 'altKey'))) {
|
|
399
|
+
// If the user had typed something in before we auto select an option, and they decided
|
|
400
|
+
// to cancel the selection, restore the input value to the one they had typed in.
|
|
401
|
+
if (this._pendingAutoselectedOption) {
|
|
402
|
+
this._updateNativeInputValue(this._valueBeforeAutoSelection ?? '');
|
|
403
|
+
this._pendingAutoselectedOption = null;
|
|
404
|
+
}
|
|
405
|
+
this._closeKeyEventStream.next();
|
|
406
|
+
this._resetActiveItem();
|
|
407
|
+
// We need to stop propagation, otherwise the event will eventually
|
|
408
|
+
// reach the input itself and cause the overlay to be reopened.
|
|
409
|
+
event.stopPropagation();
|
|
410
|
+
event.preventDefault();
|
|
411
|
+
}
|
|
412
|
+
};
|
|
413
|
+
/**
|
|
414
|
+
* Track which modal we have modified the `aria-owns` attribute of. When the combobox trigger is
|
|
415
|
+
* inside an aria-modal, we apply aria-owns to the parent modal with the `id` of the options
|
|
416
|
+
* panel. Track the modal we have changed, so we can undo the changes on destroy.
|
|
417
|
+
*/
|
|
418
|
+
this._trackedModal = null;
|
|
419
|
+
}
|
|
420
|
+
ngAfterViewInit() {
|
|
421
|
+
this._initialized.next();
|
|
422
|
+
this._initialized.complete();
|
|
423
|
+
this._cleanupWindowBlur = this._renderer.listen('window', 'blur', this._windowBlurHandler);
|
|
424
|
+
}
|
|
425
|
+
ngOnChanges(changes) {
|
|
426
|
+
if (changes['position'] && this._positionStrategy) {
|
|
427
|
+
this._setStrategyPositions(this._positionStrategy);
|
|
428
|
+
if (this.panelOpen) {
|
|
429
|
+
this._overlayRef.updatePosition();
|
|
430
|
+
}
|
|
431
|
+
}
|
|
432
|
+
}
|
|
433
|
+
ngOnDestroy() {
|
|
434
|
+
this._cleanupWindowBlur?.();
|
|
435
|
+
this._handsetLandscapeSubscription.unsubscribe();
|
|
436
|
+
this._viewportSubscription.unsubscribe();
|
|
437
|
+
this._componentDestroyed = true;
|
|
438
|
+
this._destroyPanel();
|
|
439
|
+
this._closeKeyEventStream.complete();
|
|
440
|
+
this._clearFromModal();
|
|
441
|
+
}
|
|
442
|
+
/** Whether the autocomplete panel is open. */
|
|
443
|
+
get panelOpen() {
|
|
444
|
+
return this._overlayAttached && this.autocomplete.showPanel;
|
|
445
|
+
}
|
|
446
|
+
/** Opens the autocomplete suggestion panel. */
|
|
447
|
+
openPanel() {
|
|
448
|
+
this._openPanelInternal();
|
|
449
|
+
}
|
|
450
|
+
/** Closes the autocomplete suggestion panel. */
|
|
451
|
+
closePanel() {
|
|
452
|
+
this._resetLabel();
|
|
453
|
+
if (!this._overlayAttached) {
|
|
454
|
+
return;
|
|
455
|
+
}
|
|
456
|
+
if (this.panelOpen) {
|
|
457
|
+
// Only emit if the panel was visible.
|
|
458
|
+
// The `NgZone.onStable` always emits outside the Angular zone,
|
|
459
|
+
// so all the subscriptions from `_subscribeToClosingActions()` are also outside of the Angular zone.
|
|
460
|
+
// We should manually run in Angular zone to update UI after panel closing.
|
|
461
|
+
this._zone.run(() => {
|
|
462
|
+
this.autocomplete.closed.emit();
|
|
463
|
+
});
|
|
464
|
+
}
|
|
465
|
+
// Only reset if this trigger is the latest one that opened the
|
|
466
|
+
// autocomplete since another may have taken it over.
|
|
467
|
+
if (this.autocomplete._latestOpeningTrigger === this) {
|
|
468
|
+
this.autocomplete._isOpen = false;
|
|
469
|
+
this.autocomplete._latestOpeningTrigger = null;
|
|
470
|
+
}
|
|
471
|
+
this._overlayAttached = false;
|
|
472
|
+
this._pendingAutoselectedOption = null;
|
|
473
|
+
if (this._overlayRef && this._overlayRef.hasAttached()) {
|
|
474
|
+
this._overlayRef.detach();
|
|
475
|
+
this._closingActionsSubscription?.unsubscribe();
|
|
476
|
+
}
|
|
477
|
+
this._updatePanelState();
|
|
478
|
+
// Note that in some cases this can end up being called after the component is destroyed.
|
|
479
|
+
// Add a check to ensure that we don't try to run change detection on a destroyed view.
|
|
480
|
+
if (!this._componentDestroyed) {
|
|
481
|
+
// We need to trigger change detection manually, because
|
|
482
|
+
// `fromEvent` doesn't seem to do it at the proper time.
|
|
483
|
+
// This ensures that the label is reset when the
|
|
484
|
+
// user clicks outside.
|
|
485
|
+
this._changeDetectorRef.detectChanges();
|
|
486
|
+
}
|
|
487
|
+
// Remove aria-owns attribute when the autocomplete is no longer visible.
|
|
488
|
+
if (this._trackedModal) {
|
|
489
|
+
removeAriaReferencedId(this._trackedModal, 'aria-owns', this.autocomplete.id);
|
|
490
|
+
}
|
|
491
|
+
}
|
|
492
|
+
// Interface `Expandable`
|
|
493
|
+
get expanded() { return this.panelOpen; }
|
|
494
|
+
open() { this.openPanel(); }
|
|
495
|
+
close() { this.closePanel(); }
|
|
496
|
+
toggle() { this.panelOpen ? this.closePanel() : this.openPanel(); }
|
|
497
|
+
/**
|
|
498
|
+
* Updates the position of the autocomplete suggestion panel to ensure that it fits all options
|
|
499
|
+
* within the viewport.
|
|
500
|
+
*/
|
|
501
|
+
updatePosition() {
|
|
502
|
+
if (this._overlayAttached) {
|
|
503
|
+
this._overlayRef.updatePosition();
|
|
504
|
+
}
|
|
505
|
+
}
|
|
506
|
+
/**
|
|
507
|
+
* A stream of actions that should close the autocomplete panel, including
|
|
508
|
+
* when an option is selected, on blur, and when TAB is pressed.
|
|
509
|
+
*/
|
|
510
|
+
get panelClosingActions() {
|
|
511
|
+
return merge(this.optionSelections, this.autocomplete._keyManager?.tabOut.pipe(filter(() => this._overlayAttached)) || EMPTY, this._closeKeyEventStream, this._getOutsideClickStream(), this._overlayRef
|
|
512
|
+
? this._overlayRef.detachments().pipe(filter(() => this._overlayAttached))
|
|
513
|
+
: of()).pipe(
|
|
514
|
+
// Normalize the output so we return a consistent type.
|
|
515
|
+
map(event => (event instanceof CuteOptionSelectionChange ? event : null)));
|
|
516
|
+
}
|
|
517
|
+
/** The currently active option, coerced to CuteOption type. */
|
|
518
|
+
get activeOption() {
|
|
519
|
+
if (this.autocomplete && this.autocomplete._keyManager) {
|
|
520
|
+
return this.autocomplete._keyManager.activeItem;
|
|
521
|
+
}
|
|
522
|
+
return null;
|
|
523
|
+
}
|
|
524
|
+
/** Stream of clicks outside the autocomplete panel. */
|
|
525
|
+
_getOutsideClickStream() {
|
|
526
|
+
return new Observable(observer => {
|
|
527
|
+
const listener = (event) => {
|
|
528
|
+
// If we're in the Shadow DOM, the event target will be the shadow root, so we have to
|
|
529
|
+
// fall back to check the first element in the path of the click event.
|
|
530
|
+
const clickTarget = _getEventTarget(event);
|
|
531
|
+
const formField = this._formField
|
|
532
|
+
? this._formField.getConnectedOverlayOrigin().nativeElement
|
|
533
|
+
: null;
|
|
534
|
+
const customOrigin = this.connectedTo ? this.connectedTo.elementRef.nativeElement : null;
|
|
535
|
+
if (this._overlayAttached &&
|
|
536
|
+
clickTarget !== this._element.nativeElement &&
|
|
537
|
+
// Normally focus moves inside `mousedown` so this condition will almost always be
|
|
538
|
+
// true. Its main purpose is to handle the case where the input is focused from an
|
|
539
|
+
// outside click which propagates up to the `body` listener within the same sequence
|
|
540
|
+
// and causes the panel to close immediately (see #3106).
|
|
541
|
+
!this._hasFocus() &&
|
|
542
|
+
(!formField || !formField.contains(clickTarget)) &&
|
|
543
|
+
(!customOrigin || !customOrigin.contains(clickTarget)) &&
|
|
544
|
+
!!this._overlayRef &&
|
|
545
|
+
!this._overlayRef.overlayElement.contains(clickTarget)) {
|
|
546
|
+
observer.next(event);
|
|
547
|
+
}
|
|
548
|
+
};
|
|
549
|
+
const cleanups = [
|
|
550
|
+
this._renderer.listen('document', 'click', listener),
|
|
551
|
+
this._renderer.listen('document', 'auxclick', listener),
|
|
552
|
+
this._renderer.listen('document', 'touchend', listener),
|
|
553
|
+
];
|
|
554
|
+
return () => {
|
|
555
|
+
cleanups.forEach(current => current());
|
|
556
|
+
};
|
|
557
|
+
});
|
|
558
|
+
}
|
|
559
|
+
// Implemented as part of ControlValueAccessor.
|
|
560
|
+
writeValue(value) {
|
|
561
|
+
Promise.resolve(null).then(() => this._assignOptionValue(value));
|
|
562
|
+
}
|
|
563
|
+
// Implemented as part of ControlValueAccessor.
|
|
564
|
+
registerOnChange(fn) {
|
|
565
|
+
this._onChange = fn;
|
|
566
|
+
}
|
|
567
|
+
// Implemented as part of ControlValueAccessor.
|
|
568
|
+
registerOnTouched(fn) {
|
|
569
|
+
this._onTouched = fn;
|
|
570
|
+
}
|
|
571
|
+
// Implemented as part of ControlValueAccessor.
|
|
572
|
+
setDisabledState(isDisabled) {
|
|
573
|
+
this._element.nativeElement.disabled = isDisabled;
|
|
574
|
+
}
|
|
575
|
+
_handleKeydown(e) {
|
|
576
|
+
const event = e;
|
|
577
|
+
const keyCode = event.keyCode;
|
|
578
|
+
const hasModifier = hasModifierKey(event);
|
|
579
|
+
// Prevent the default action on all escape key presses. This is here primarily to bring IE
|
|
580
|
+
// in line with other browsers. By default, pressing escape on IE will cause it to revert
|
|
581
|
+
// the input value to the one that it had on focus, however it won't dispatch any events
|
|
582
|
+
// which means that the model value will be out of sync with the view.
|
|
583
|
+
if (keyCode === ESCAPE && !hasModifier) {
|
|
584
|
+
event.preventDefault();
|
|
585
|
+
}
|
|
586
|
+
this._valueOnLastKeydown = this._element.nativeElement.value;
|
|
587
|
+
if (this.activeOption && keyCode === ENTER && this.panelOpen && !hasModifier) {
|
|
588
|
+
this.activeOption._selectViaInteraction();
|
|
589
|
+
this._resetActiveItem();
|
|
590
|
+
event.preventDefault();
|
|
591
|
+
}
|
|
592
|
+
else if (this.autocomplete && this.autocomplete._keyManager) {
|
|
593
|
+
const prevActiveItem = this.autocomplete._keyManager.activeItem;
|
|
594
|
+
const isArrowKey = keyCode === UP_ARROW || keyCode === DOWN_ARROW;
|
|
595
|
+
if (keyCode === TAB || (isArrowKey && !hasModifier && this.panelOpen)) {
|
|
596
|
+
this.autocomplete._keyManager.onKeydown(event);
|
|
597
|
+
}
|
|
598
|
+
else if (isArrowKey && this._canOpen()) {
|
|
599
|
+
this._openPanelInternal(this._valueOnLastKeydown);
|
|
600
|
+
}
|
|
601
|
+
if (isArrowKey || this.autocomplete._keyManager?.activeItem !== prevActiveItem) {
|
|
602
|
+
this._scrollToOption(this.autocomplete._keyManager?.activeItemIndex || 0);
|
|
603
|
+
if (this.autocomplete.autoSelectActiveOption && this.activeOption) {
|
|
604
|
+
if (!this._pendingAutoselectedOption) {
|
|
605
|
+
this._valueBeforeAutoSelection = this._valueOnLastKeydown;
|
|
606
|
+
}
|
|
607
|
+
this._pendingAutoselectedOption = this.activeOption;
|
|
608
|
+
this._assignOptionValue(this.activeOption.value);
|
|
609
|
+
}
|
|
610
|
+
}
|
|
611
|
+
}
|
|
612
|
+
}
|
|
613
|
+
_handleInput(event) {
|
|
614
|
+
let target = event.target;
|
|
615
|
+
let value = target.value;
|
|
616
|
+
// Based on `NumberValueAccessor` from forms.
|
|
617
|
+
if (target.type === 'number') {
|
|
618
|
+
value = value == '' ? null : parseFloat(value);
|
|
619
|
+
}
|
|
620
|
+
// If the input has a placeholder, IE will fire the `input` event on a page load,
|
|
621
|
+
// focus and blur, in addition to when the user actually changed the value. To
|
|
622
|
+
// filter out all the extra events, we save the value on focus and between
|
|
623
|
+
// `input` events, and we check whether it changed.
|
|
624
|
+
// See: https://connect.microsoft.com/IE/feedback/details/885747/
|
|
625
|
+
if (this._previousValue !== value) {
|
|
626
|
+
this._previousValue = value;
|
|
627
|
+
this._pendingAutoselectedOption = null;
|
|
628
|
+
// If selection is required, we don't write to the CVA while the user is typing.
|
|
629
|
+
// At the end of the selection either the user will have picked something
|
|
630
|
+
// or we'll reset the value back to null.
|
|
631
|
+
if (!this.autocomplete || !this.autocomplete.requireSelection) {
|
|
632
|
+
this._onChange(value);
|
|
633
|
+
}
|
|
634
|
+
if (!value) {
|
|
635
|
+
this._clearPreviousSelectedOption(null, false);
|
|
636
|
+
}
|
|
637
|
+
else if (this.panelOpen && !this.autocomplete.requireSelection) {
|
|
638
|
+
// Note that we don't reset this when `requireSelection` is enabled,
|
|
639
|
+
// because the option will be reset when the panel is closed.
|
|
640
|
+
const selectedOption = this.autocomplete.options?.find(option => option.selected);
|
|
641
|
+
if (selectedOption) {
|
|
642
|
+
const display = this._getDisplayValue(selectedOption.value);
|
|
643
|
+
if (value !== display) {
|
|
644
|
+
selectedOption.deselect(false);
|
|
645
|
+
}
|
|
646
|
+
}
|
|
647
|
+
}
|
|
648
|
+
if (this._canOpen() && this._hasFocus()) {
|
|
649
|
+
// When the `input` event fires, the input's value will have already changed. This means
|
|
650
|
+
// that if we take the `this._element.nativeElement.value` directly, it'll be one keystroke
|
|
651
|
+
// behind. This can be a problem when the user selects a value, changes a character while
|
|
652
|
+
// the input still has focus and then clicks away (see #28432). To work around it, we
|
|
653
|
+
// capture the value in `keydown` so we can use it here.
|
|
654
|
+
const valueOnAttach = this._valueOnLastKeydown ?? this._element.nativeElement.value;
|
|
655
|
+
this._valueOnLastKeydown = null;
|
|
656
|
+
this._openPanelInternal(valueOnAttach);
|
|
657
|
+
}
|
|
658
|
+
}
|
|
659
|
+
}
|
|
660
|
+
_handleFocus() {
|
|
661
|
+
if (!this._canOpenOnNextFocus) {
|
|
662
|
+
this._canOpenOnNextFocus = true;
|
|
663
|
+
}
|
|
664
|
+
else if (this._canOpen()) {
|
|
665
|
+
this._previousValue = this._element.nativeElement.value;
|
|
666
|
+
this._attachOverlay(this._previousValue);
|
|
667
|
+
this._floatLabel(true);
|
|
668
|
+
}
|
|
669
|
+
}
|
|
670
|
+
_handleClick() {
|
|
671
|
+
if (this._canOpen() && !this.panelOpen) {
|
|
672
|
+
this._openPanelInternal();
|
|
673
|
+
}
|
|
674
|
+
}
|
|
675
|
+
/** Whether the input currently has focus. */
|
|
676
|
+
_hasFocus() {
|
|
677
|
+
return _getFocusedElementPierceShadowDom() === this._element.nativeElement;
|
|
678
|
+
}
|
|
679
|
+
/**
|
|
680
|
+
* In "auto" mode, the label will animate down as soon as focus is lost.
|
|
681
|
+
* This causes the value to jump when selecting an option with the mouse.
|
|
682
|
+
* This method manually floats the label until the panel can be closed.
|
|
683
|
+
* @param shouldAnimate Whether the label should be animated when it is floated.
|
|
684
|
+
*/
|
|
685
|
+
_floatLabel(shouldAnimate = false) {
|
|
686
|
+
if (this._formField && this._formField.floatLabel === 'auto') {
|
|
687
|
+
if (shouldAnimate) {
|
|
688
|
+
this._formField._animateAndLockLabel();
|
|
689
|
+
}
|
|
690
|
+
else {
|
|
691
|
+
this._formField.floatLabel = 'always';
|
|
692
|
+
}
|
|
693
|
+
this._manuallyFloatingLabel = true;
|
|
694
|
+
}
|
|
695
|
+
}
|
|
696
|
+
/** If the label has been manually elevated, return it to its normal state. */
|
|
697
|
+
_resetLabel() {
|
|
698
|
+
if (this._manuallyFloatingLabel) {
|
|
699
|
+
if (this._formField) {
|
|
700
|
+
this._formField.floatLabel = 'auto';
|
|
701
|
+
}
|
|
702
|
+
this._manuallyFloatingLabel = false;
|
|
703
|
+
}
|
|
704
|
+
}
|
|
705
|
+
/**
|
|
706
|
+
* This method listens to a stream of panel closing actions and resets the
|
|
707
|
+
* stream every time the option list changes.
|
|
708
|
+
*/
|
|
709
|
+
_subscribeToClosingActions() {
|
|
710
|
+
const initialRender = new Observable(subscriber => {
|
|
711
|
+
afterNextRender(() => {
|
|
712
|
+
subscriber.next();
|
|
713
|
+
}, { injector: this._environmentInjector });
|
|
714
|
+
});
|
|
715
|
+
const optionChanges = this.autocomplete.options?.changes.pipe(tap(() => this._positionStrategy?.reapplyLastPosition()),
|
|
716
|
+
// Defer emitting to the stream until the next tick, because changing
|
|
717
|
+
// bindings in here will cause "changed after checked" errors.
|
|
718
|
+
delay(0)) ?? of();
|
|
719
|
+
// When the options are initially rendered, and when the option list changes...
|
|
720
|
+
return (merge(initialRender, optionChanges)
|
|
721
|
+
.pipe(
|
|
722
|
+
// create a new stream of panelClosingActions, replacing any previous streams
|
|
723
|
+
// that were created, and flatten it so our stream only emits closing events...
|
|
724
|
+
switchMap(() => this._zone.run(() => {
|
|
725
|
+
// `afterNextRender` always runs outside the Angular zone, thus we have to re-enter
|
|
726
|
+
// the Angular zone. This will lead to change detection being called outside the Angular
|
|
727
|
+
// zone and the `autocomplete.opened` will also emit outside the Angular.
|
|
728
|
+
const wasOpen = this.panelOpen;
|
|
729
|
+
this._resetActiveItem();
|
|
730
|
+
this._updatePanelState();
|
|
731
|
+
this._changeDetectorRef.detectChanges();
|
|
732
|
+
if (this.panelOpen) {
|
|
733
|
+
this._overlayRef.updatePosition();
|
|
734
|
+
}
|
|
735
|
+
if (wasOpen !== this.panelOpen) {
|
|
736
|
+
// If the `panelOpen` state changed, we need to make sure to emit the `opened` or
|
|
737
|
+
// `closed` event, because we may not have emitted it. This can happen
|
|
738
|
+
// - if the users opens the panel and there are no options, but the
|
|
739
|
+
// options come in slightly later or as a result of the value changing,
|
|
740
|
+
// - if the panel is closed after the user entered a string that did not match any
|
|
741
|
+
// of the available options,
|
|
742
|
+
// - if a valid string is entered after an invalid one.
|
|
743
|
+
if (this.panelOpen) {
|
|
744
|
+
this._emitOpened();
|
|
745
|
+
}
|
|
746
|
+
else {
|
|
747
|
+
this.autocomplete.closed.emit();
|
|
748
|
+
}
|
|
749
|
+
}
|
|
750
|
+
return this.panelClosingActions;
|
|
751
|
+
})),
|
|
752
|
+
// when the first closing event occurs...
|
|
753
|
+
take(1))
|
|
754
|
+
// set the value, close the panel, and complete.
|
|
755
|
+
.subscribe(event => this._setValueAndClose(event)));
|
|
756
|
+
}
|
|
757
|
+
/**
|
|
758
|
+
* Emits the opened event once it's known that the panel will be shown and stores
|
|
759
|
+
* the state of the trigger right before the opening sequence was finished.
|
|
760
|
+
*/
|
|
761
|
+
_emitOpened() {
|
|
762
|
+
this.autocomplete.opened.emit();
|
|
763
|
+
}
|
|
764
|
+
/** Destroys the autocomplete suggestion panel. */
|
|
765
|
+
_destroyPanel() {
|
|
766
|
+
if (this._overlayRef) {
|
|
767
|
+
this.closePanel();
|
|
768
|
+
this._overlayRef.dispose();
|
|
769
|
+
this._overlayRef = null;
|
|
770
|
+
}
|
|
771
|
+
}
|
|
772
|
+
/** Given a value, returns the string that should be shown within the input. */
|
|
773
|
+
_getDisplayValue(value) {
|
|
774
|
+
const autocomplete = this.autocomplete;
|
|
775
|
+
return autocomplete && autocomplete.displayWith ? autocomplete.displayWith(value) : value;
|
|
776
|
+
}
|
|
777
|
+
_assignOptionValue(value) {
|
|
778
|
+
const toDisplay = this._getDisplayValue(value);
|
|
779
|
+
if (value == null) {
|
|
780
|
+
this._clearPreviousSelectedOption(null, false);
|
|
781
|
+
}
|
|
782
|
+
// Simply falling back to an empty string if the display value is falsy does not work properly.
|
|
783
|
+
// The display value can also be the number zero and shouldn't fall back to an empty string.
|
|
784
|
+
this._updateNativeInputValue(toDisplay != null ? toDisplay : '');
|
|
785
|
+
}
|
|
786
|
+
_updateNativeInputValue(value) {
|
|
787
|
+
// If it's used within a `CuteFormField`, we should set it through the property, so it can go
|
|
788
|
+
// through change detection.
|
|
789
|
+
if (this._formField?._control) {
|
|
790
|
+
this._formField._control.value = value;
|
|
791
|
+
}
|
|
792
|
+
else {
|
|
793
|
+
this._element.nativeElement.value = value;
|
|
794
|
+
}
|
|
795
|
+
this._previousValue = value;
|
|
796
|
+
}
|
|
797
|
+
/**
|
|
798
|
+
* This method closes the panel, and if a value is specified, also sets the associated
|
|
799
|
+
* control to that value. It will also mark the control as dirty if this interaction
|
|
800
|
+
* stemmed from the user.
|
|
801
|
+
*/
|
|
802
|
+
_setValueAndClose(event) {
|
|
803
|
+
const panel = this.autocomplete;
|
|
804
|
+
const toSelect = event ? event.source : this._pendingAutoselectedOption;
|
|
805
|
+
if (toSelect) {
|
|
806
|
+
this._clearPreviousSelectedOption(toSelect);
|
|
807
|
+
this._assignOptionValue(toSelect.value);
|
|
808
|
+
// TODO(crisbeto): this should wait until the animation is done, otherwise the value
|
|
809
|
+
// gets reset while the panel is still animating which looks glitchy. It'll likely break
|
|
810
|
+
// some tests to change it at this point.
|
|
811
|
+
this._onChange(toSelect.value);
|
|
812
|
+
panel._emitSelectEvent(toSelect);
|
|
813
|
+
this._element.nativeElement.focus();
|
|
814
|
+
}
|
|
815
|
+
else if (panel.requireSelection &&
|
|
816
|
+
this._element.nativeElement.value !== this._valueOnAttach) {
|
|
817
|
+
this._clearPreviousSelectedOption(null);
|
|
818
|
+
this._assignOptionValue(null);
|
|
819
|
+
this._onChange(null);
|
|
820
|
+
}
|
|
821
|
+
this.closePanel();
|
|
822
|
+
}
|
|
823
|
+
/**
|
|
824
|
+
* Clear any previous selected option and emit a selection change event for this option
|
|
825
|
+
*/
|
|
826
|
+
_clearPreviousSelectedOption(skip, emitEvent) {
|
|
827
|
+
// Null checks are necessary here, because the autocomplete
|
|
828
|
+
// or its options may not have been assigned yet.
|
|
829
|
+
this.autocomplete?.options?.forEach(option => {
|
|
830
|
+
if (option !== skip && option.selected) {
|
|
831
|
+
option.deselect(emitEvent);
|
|
832
|
+
}
|
|
833
|
+
});
|
|
834
|
+
}
|
|
835
|
+
_openPanelInternal(valueOnAttach = this._element.nativeElement.value) {
|
|
836
|
+
this._attachOverlay(valueOnAttach);
|
|
837
|
+
this._floatLabel();
|
|
838
|
+
// Add aria-owns attribute when the autocomplete becomes visible.
|
|
839
|
+
if (this._trackedModal) {
|
|
840
|
+
const panelId = this.autocomplete.id;
|
|
841
|
+
addAriaReferencedId(this._trackedModal, 'aria-owns', panelId);
|
|
842
|
+
}
|
|
843
|
+
}
|
|
844
|
+
_attachOverlay(valueOnAttach) {
|
|
845
|
+
if (!this.autocomplete && isDevMode()) {
|
|
846
|
+
throw getCuteAutocompleteMissingPanelError();
|
|
847
|
+
}
|
|
848
|
+
let overlayRef = this._overlayRef;
|
|
849
|
+
if (!overlayRef) {
|
|
850
|
+
this._portal = new TemplatePortal(this.autocomplete.template, this._viewContainerRef, {
|
|
851
|
+
id: this._formField?.getLabelId(),
|
|
852
|
+
});
|
|
853
|
+
overlayRef = createOverlayRef(this._injector, this._getOverlayConfig());
|
|
854
|
+
this._overlayRef = overlayRef;
|
|
855
|
+
this._viewportSubscription = this._viewportRuler.change().subscribe(() => {
|
|
856
|
+
if (this.panelOpen && overlayRef) {
|
|
857
|
+
overlayRef.updateSize({ width: this._getPanelWidth() });
|
|
858
|
+
}
|
|
859
|
+
});
|
|
860
|
+
// Subscribe to the breakpoint events stream to detect when screen is in
|
|
861
|
+
// handsetLandscape.
|
|
862
|
+
this._handsetLandscapeSubscription = this._breakpointObserver
|
|
863
|
+
.observe(Breakpoints.HandsetLandscape)
|
|
864
|
+
.subscribe(result => {
|
|
865
|
+
const isHandsetLandscape = result.matches;
|
|
866
|
+
// Check if result.matches Breakpoints.HandsetLandscape. Apply HandsetLandscape
|
|
867
|
+
// settings to prevent overlay cutoff in that breakpoint. Fixes b/284148377
|
|
868
|
+
if (this._positionStrategy) {
|
|
869
|
+
if (isHandsetLandscape) {
|
|
870
|
+
this._positionStrategy
|
|
871
|
+
.withFlexibleDimensions(true)
|
|
872
|
+
.withGrowAfterOpen(true)
|
|
873
|
+
.withViewportMargin(8);
|
|
874
|
+
}
|
|
875
|
+
else {
|
|
876
|
+
this._positionStrategy
|
|
877
|
+
.withFlexibleDimensions(false)
|
|
878
|
+
.withGrowAfterOpen(false)
|
|
879
|
+
.withViewportMargin(0);
|
|
880
|
+
}
|
|
881
|
+
}
|
|
882
|
+
});
|
|
883
|
+
}
|
|
884
|
+
else {
|
|
885
|
+
// Update the trigger, panel width and direction, in case anything has changed.
|
|
886
|
+
this._positionStrategy?.setOrigin(this._getConnectedElement());
|
|
887
|
+
overlayRef.updateSize({ width: this._getPanelWidth() });
|
|
888
|
+
}
|
|
889
|
+
if (overlayRef && !overlayRef.hasAttached()) {
|
|
890
|
+
overlayRef.attach(this._portal);
|
|
891
|
+
this._valueOnAttach = valueOnAttach;
|
|
892
|
+
this._valueOnLastKeydown = null;
|
|
893
|
+
this._closingActionsSubscription = this._subscribeToClosingActions();
|
|
894
|
+
}
|
|
895
|
+
const wasOpen = this.panelOpen;
|
|
896
|
+
this.autocomplete._isOpen = this._overlayAttached = true;
|
|
897
|
+
this.autocomplete._latestOpeningTrigger = this;
|
|
898
|
+
this.autocomplete._setColor(this._formField?.color);
|
|
899
|
+
this._updatePanelState();
|
|
900
|
+
this._applyModalPanelOwnership();
|
|
901
|
+
// We need to do an extra `panelOpen` check in here, because the
|
|
902
|
+
// autocomplete won't be shown if there are no options.
|
|
903
|
+
if (this.panelOpen && wasOpen !== this.panelOpen) {
|
|
904
|
+
this._emitOpened();
|
|
905
|
+
}
|
|
906
|
+
}
|
|
907
|
+
/** Updates the panel's visibility state and any trigger state tied to id. */
|
|
908
|
+
_updatePanelState() {
|
|
909
|
+
this.autocomplete._setVisibility();
|
|
910
|
+
// Note that here we subscribe and unsubscribe based on the panel's visibility state,
|
|
911
|
+
// because the act of subscribing will prevent events from reaching other overlays, and
|
|
912
|
+
// we don't want to block the events if there are no options.
|
|
913
|
+
if (this.panelOpen) {
|
|
914
|
+
const overlayRef = this._overlayRef;
|
|
915
|
+
if (!this._keydownSubscription) {
|
|
916
|
+
// Use the `keydownEvents` in order to take advantage of
|
|
917
|
+
// the overlay event targeting provided by the CDK overlay.
|
|
918
|
+
this._keydownSubscription = overlayRef.keydownEvents().subscribe(this._handlePanelKeydown);
|
|
919
|
+
}
|
|
920
|
+
if (!this._outsideClickSubscription) {
|
|
921
|
+
// Subscribe to the pointer events stream so that it doesn't get picked up by other overlays.
|
|
922
|
+
// TODO(crisbeto): we should switch `_getOutsideClickStream` eventually to use this stream,
|
|
923
|
+
// but the behavior isn't exactly the same and it ends up breaking some internal tests.
|
|
924
|
+
this._outsideClickSubscription = overlayRef.outsidePointerEvents().subscribe();
|
|
925
|
+
}
|
|
926
|
+
}
|
|
927
|
+
else {
|
|
928
|
+
this._keydownSubscription?.unsubscribe();
|
|
929
|
+
this._outsideClickSubscription?.unsubscribe();
|
|
930
|
+
this._keydownSubscription = this._outsideClickSubscription = null;
|
|
931
|
+
}
|
|
932
|
+
}
|
|
933
|
+
_getOverlayConfig() {
|
|
934
|
+
return new OverlayConfig({
|
|
935
|
+
positionStrategy: this._getOverlayPosition(),
|
|
936
|
+
scrollStrategy: this._scrollStrategy(),
|
|
937
|
+
width: this._getPanelWidth(),
|
|
938
|
+
direction: this._dir ?? undefined,
|
|
939
|
+
hasBackdrop: this._defaults?.hasBackdrop,
|
|
940
|
+
backdropClass: this._defaults?.backdropClass || 'cdk-overlay-transparent-backdrop',
|
|
941
|
+
panelClass: this._overlayPanelClass,
|
|
942
|
+
disableAnimations: this._animationsDisabled,
|
|
943
|
+
});
|
|
944
|
+
}
|
|
945
|
+
_getOverlayPosition() {
|
|
946
|
+
// Set default Overlay Position
|
|
947
|
+
const strategy = createFlexibleConnectedPositionStrategy(this._injector, this._getConnectedElement())
|
|
948
|
+
.withFlexibleDimensions(false)
|
|
949
|
+
.withPush(false);
|
|
950
|
+
// TODO: not exists in CDK ver. 20.x
|
|
951
|
+
//.withPopoverLocation('inline');
|
|
952
|
+
this._setStrategyPositions(strategy);
|
|
953
|
+
this._positionStrategy = strategy;
|
|
954
|
+
return strategy;
|
|
955
|
+
}
|
|
956
|
+
/** Sets the positions on a position strategy based on the directive's input state. */
|
|
957
|
+
_setStrategyPositions(positionStrategy) {
|
|
958
|
+
// Note that we provide horizontal fallback positions, even though by default the dropdown
|
|
959
|
+
// width matches the input, because consumers can override the width. See #18854.
|
|
960
|
+
const OFFSET = 4;
|
|
961
|
+
const belowPositions = [
|
|
962
|
+
{ originX: 'start', originY: 'bottom', overlayX: 'start', overlayY: 'top', offsetY: OFFSET },
|
|
963
|
+
{ originX: 'end', originY: 'bottom', overlayX: 'end', overlayY: 'top', offsetY: OFFSET },
|
|
964
|
+
];
|
|
965
|
+
// The overlay edge connected to the trigger should have squared corners, while
|
|
966
|
+
// the opposite end has rounded corners. We apply a CSS class to swap the
|
|
967
|
+
// border-radius based on the overlay position.
|
|
968
|
+
const panelClass = this._aboveClass;
|
|
969
|
+
const abovePositions = [
|
|
970
|
+
{ originX: 'start', originY: 'top', overlayX: 'start', overlayY: 'bottom', offsetY: -OFFSET, panelClass },
|
|
971
|
+
{ originX: 'end', originY: 'top', overlayX: 'end', overlayY: 'bottom', offsetY: -OFFSET, panelClass },
|
|
972
|
+
];
|
|
973
|
+
let positions;
|
|
974
|
+
if (this.position === 'above') {
|
|
975
|
+
positions = abovePositions;
|
|
976
|
+
}
|
|
977
|
+
else if (this.position === 'below') {
|
|
978
|
+
positions = belowPositions;
|
|
979
|
+
}
|
|
980
|
+
else {
|
|
981
|
+
positions = [...belowPositions, ...abovePositions];
|
|
982
|
+
}
|
|
983
|
+
positionStrategy.withPositions(positions);
|
|
984
|
+
}
|
|
985
|
+
_getConnectedElement() {
|
|
986
|
+
if (this.connectedTo) {
|
|
987
|
+
return this.connectedTo.elementRef;
|
|
988
|
+
}
|
|
989
|
+
return this._formField ? this._formField.getConnectedOverlayOrigin() : this._element;
|
|
990
|
+
}
|
|
991
|
+
_getPanelWidth() {
|
|
992
|
+
return this.autocomplete.panelWidth || this._getHostWidth();
|
|
993
|
+
}
|
|
994
|
+
/** Returns the width of the input element, so the panel width can match it. */
|
|
995
|
+
_getHostWidth() {
|
|
996
|
+
return this._getConnectedElement().nativeElement.getBoundingClientRect().width;
|
|
997
|
+
}
|
|
998
|
+
/**
|
|
999
|
+
* Reset the active item to -1. This is so that pressing arrow keys will activate the correct
|
|
1000
|
+
* option.
|
|
1001
|
+
*
|
|
1002
|
+
* If the consumer opted-in to automatically activating the first option, activate the first
|
|
1003
|
+
* *enabled* option.
|
|
1004
|
+
*/
|
|
1005
|
+
_resetActiveItem() {
|
|
1006
|
+
const autocomplete = this.autocomplete;
|
|
1007
|
+
if (autocomplete.autoActiveFirstOption) {
|
|
1008
|
+
// Find the index of the first *enabled* option. Avoid calling `_keyManager.setActiveItem`
|
|
1009
|
+
// because it activates the first option that passes the skip predicate, rather than the
|
|
1010
|
+
// first *enabled* option.
|
|
1011
|
+
let firstEnabledOptionIndex = -1;
|
|
1012
|
+
for (let index = 0; index < (autocomplete.options?.length || 0); index++) {
|
|
1013
|
+
const option = autocomplete.options?.get(index);
|
|
1014
|
+
if (!option.disabled) {
|
|
1015
|
+
firstEnabledOptionIndex = index;
|
|
1016
|
+
break;
|
|
1017
|
+
}
|
|
1018
|
+
}
|
|
1019
|
+
autocomplete._keyManager?.setActiveItem(firstEnabledOptionIndex);
|
|
1020
|
+
}
|
|
1021
|
+
else {
|
|
1022
|
+
autocomplete._keyManager?.setActiveItem(-1);
|
|
1023
|
+
}
|
|
1024
|
+
}
|
|
1025
|
+
/** Determines whether the panel can be opened. */
|
|
1026
|
+
_canOpen() {
|
|
1027
|
+
const element = this._element.nativeElement;
|
|
1028
|
+
return !element.readOnly && !element.disabled && !this.autocompleteDisabled;
|
|
1029
|
+
}
|
|
1030
|
+
/** Scrolls to a particular option in the list. */
|
|
1031
|
+
_scrollToOption(index) {
|
|
1032
|
+
// Given that we are not actually focusing active options, we must manually adjust the scroll
|
|
1033
|
+
// to reveal options below the fold. First, we find the offset of the option from the top
|
|
1034
|
+
// of the panel. If that offset is below the fold, the new scrollTop will be the offset -
|
|
1035
|
+
// the panel height + the option height, so the active option will be just visible at the
|
|
1036
|
+
// bottom of the panel. If that offset is above the top of the visible panel, the new scrollTop
|
|
1037
|
+
// will become the offset. If that offset is visible within the panel already, the scrollTop is
|
|
1038
|
+
// not adjusted.
|
|
1039
|
+
const autocomplete = this.autocomplete;
|
|
1040
|
+
const labelCount = _countGroupLabelsBeforeOption(index, autocomplete.options, autocomplete.optionGroups);
|
|
1041
|
+
if (index === 0 && labelCount === 1) {
|
|
1042
|
+
// If we've got one group label before the option, and we're at the top option,
|
|
1043
|
+
// scroll the list to the top. This is better UX than scrolling the list to the
|
|
1044
|
+
// top of the option, because it allows the user to read the top group's label.
|
|
1045
|
+
autocomplete._setScrollTop(0);
|
|
1046
|
+
}
|
|
1047
|
+
else if (autocomplete.panel) {
|
|
1048
|
+
const option = autocomplete.options?.toArray()[index];
|
|
1049
|
+
if (option) {
|
|
1050
|
+
const element = option._getHostElement();
|
|
1051
|
+
const newScrollPosition = _getOptionScrollPosition(element.offsetTop, element.offsetHeight, autocomplete._getScrollTop(), autocomplete.panel.nativeElement.offsetHeight);
|
|
1052
|
+
autocomplete._setScrollTop(newScrollPosition);
|
|
1053
|
+
}
|
|
1054
|
+
}
|
|
1055
|
+
}
|
|
1056
|
+
/**
|
|
1057
|
+
* If the autocomplete trigger is inside an `aria-modal` element, connect
|
|
1058
|
+
* that modal to the options panel with `aria-owns`.
|
|
1059
|
+
*
|
|
1060
|
+
* For some browser + screen reader combinations, when navigation is inside
|
|
1061
|
+
* an `aria-modal` element, the screen reader treats everything outside
|
|
1062
|
+
* of that modal as hidden or invisible.
|
|
1063
|
+
*
|
|
1064
|
+
* This causes a problem when the combobox trigger is _inside_ of a modal, because the
|
|
1065
|
+
* options panel is rendered _outside_ of that modal, preventing screen reader navigation
|
|
1066
|
+
* from reaching the panel.
|
|
1067
|
+
*
|
|
1068
|
+
* We can work around this issue by applying `aria-owns` to the modal with the `id` of
|
|
1069
|
+
* the options panel. This effectively communicates to assistive technology that the
|
|
1070
|
+
* options panel is part of the same interaction as the modal.
|
|
1071
|
+
*
|
|
1072
|
+
* At the time of this writing, this issue is present in VoiceOver.
|
|
1073
|
+
* See https://github.com/angular/components/issues/20694
|
|
1074
|
+
*/
|
|
1075
|
+
_applyModalPanelOwnership() {
|
|
1076
|
+
// TODO(http://github.com/angular/components/issues/26853): consider de-duplicating this with
|
|
1077
|
+
// the `LiveAnnouncer` and any other usages.
|
|
1078
|
+
//
|
|
1079
|
+
// Note that the selector here is limited to CDK overlays at the moment in order to reduce the
|
|
1080
|
+
// section of the DOM we need to look through. This should cover all the cases we support, but
|
|
1081
|
+
// the selector can be expanded if it turns out to be too narrow.
|
|
1082
|
+
const modal = this._element.nativeElement.closest('body > .cdk-overlay-container [aria-modal="true"]');
|
|
1083
|
+
if (!modal) {
|
|
1084
|
+
// Most commonly, the autocomplete trigger is not inside a modal.
|
|
1085
|
+
return;
|
|
1086
|
+
}
|
|
1087
|
+
const panelId = this.autocomplete.id;
|
|
1088
|
+
if (this._trackedModal) {
|
|
1089
|
+
removeAriaReferencedId(this._trackedModal, 'aria-owns', panelId);
|
|
1090
|
+
}
|
|
1091
|
+
addAriaReferencedId(modal, 'aria-owns', panelId);
|
|
1092
|
+
this._trackedModal = modal;
|
|
1093
|
+
}
|
|
1094
|
+
/** Clears the references to the listbox overlay element from the modal it was added to. */
|
|
1095
|
+
_clearFromModal() {
|
|
1096
|
+
if (this._trackedModal && this.autocomplete) {
|
|
1097
|
+
const panelId = this.autocomplete.id;
|
|
1098
|
+
removeAriaReferencedId(this._trackedModal, 'aria-owns', panelId);
|
|
1099
|
+
this._trackedModal = null;
|
|
1100
|
+
}
|
|
1101
|
+
}
|
|
1102
|
+
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.3.15", ngImport: i0, type: CuteAutocompleteTrigger, deps: [], target: i0.ɵɵFactoryTarget.Directive }); }
|
|
1103
|
+
static { this.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "16.1.0", version: "20.3.15", type: CuteAutocompleteTrigger, isStandalone: true, selector: "input[cuteAutocomplete], textarea[cuteAutocomplete]", inputs: { autocomplete: ["cuteAutocomplete", "autocomplete"], position: ["cuteAutocompletePosition", "position"], connectedTo: ["cuteAutocompleteConnectedTo", "connectedTo"], autocompleteAttribute: ["autocomplete", "autocompleteAttribute"], autocompleteDisabled: ["cuteAutocompleteDisabled", "autocompleteDisabled", booleanAttribute] }, host: { listeners: { "focusin": "_handleFocus()", "blur": "_onTouched()", "input": "_handleInput($event)", "keydown": "_handleKeydown($event)", "click": "_handleClick()" }, properties: { "attr.autocomplete": "autocompleteAttribute", "attr.role": "autocompleteDisabled ? null : \"combobox\"", "attr.aria-autocomplete": "autocompleteDisabled ? null : \"list\"", "attr.aria-activedescendant": "(panelOpen && activeOption) ? activeOption.id : null", "attr.aria-expanded": "autocompleteDisabled ? null : panelOpen", "attr.aria-controls": "(autocompleteDisabled || !panelOpen) ? null : autocomplete?.id", "attr.aria-haspopup": "autocompleteDisabled ? null : \"listbox\"" }, classAttribute: "cute-autocomplete-trigger dropdown-toggle" }, providers: [CUTE_AUTOCOMPLETE_VALUE_ACCESSOR], exportAs: ["cuteAutocompleteTrigger"], usesOnChanges: true, ngImport: i0 }); }
|
|
1104
|
+
}
|
|
1105
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.15", ngImport: i0, type: CuteAutocompleteTrigger, decorators: [{
|
|
1106
|
+
type: Directive,
|
|
1107
|
+
args: [{
|
|
1108
|
+
selector: `input[cuteAutocomplete], textarea[cuteAutocomplete]`,
|
|
1109
|
+
host: {
|
|
1110
|
+
'class': 'cute-autocomplete-trigger dropdown-toggle', /* Exclude from .input-group */
|
|
1111
|
+
'[attr.autocomplete]': 'autocompleteAttribute',
|
|
1112
|
+
'[attr.role]': 'autocompleteDisabled ? null : "combobox"',
|
|
1113
|
+
'[attr.aria-autocomplete]': 'autocompleteDisabled ? null : "list"',
|
|
1114
|
+
'[attr.aria-activedescendant]': '(panelOpen && activeOption) ? activeOption.id : null',
|
|
1115
|
+
'[attr.aria-expanded]': 'autocompleteDisabled ? null : panelOpen',
|
|
1116
|
+
'[attr.aria-controls]': '(autocompleteDisabled || !panelOpen) ? null : autocomplete?.id',
|
|
1117
|
+
'[attr.aria-haspopup]': 'autocompleteDisabled ? null : "listbox"',
|
|
1118
|
+
// Note: we use `focusin`, as opposed to `focus`, to open the panel
|
|
1119
|
+
// a little earlier. This avoids issues where IE delays the focusing of the input.
|
|
1120
|
+
'(focusin)': '_handleFocus()',
|
|
1121
|
+
'(blur)': '_onTouched()',
|
|
1122
|
+
'(input)': '_handleInput($event)',
|
|
1123
|
+
'(keydown)': '_handleKeydown($event)',
|
|
1124
|
+
'(click)': '_handleClick()',
|
|
1125
|
+
},
|
|
1126
|
+
exportAs: 'cuteAutocompleteTrigger',
|
|
1127
|
+
providers: [CUTE_AUTOCOMPLETE_VALUE_ACCESSOR],
|
|
1128
|
+
standalone: true,
|
|
1129
|
+
}]
|
|
1130
|
+
}], ctorParameters: () => [], propDecorators: { autocomplete: [{
|
|
1131
|
+
type: Input,
|
|
1132
|
+
args: ['cuteAutocomplete']
|
|
1133
|
+
}], position: [{
|
|
1134
|
+
type: Input,
|
|
1135
|
+
args: ['cuteAutocompletePosition']
|
|
1136
|
+
}], connectedTo: [{
|
|
1137
|
+
type: Input,
|
|
1138
|
+
args: ['cuteAutocompleteConnectedTo']
|
|
1139
|
+
}], autocompleteAttribute: [{
|
|
1140
|
+
type: Input,
|
|
1141
|
+
args: ['autocomplete']
|
|
1142
|
+
}], autocompleteDisabled: [{
|
|
1143
|
+
type: Input,
|
|
1144
|
+
args: [{ alias: 'cuteAutocompleteDisabled', transform: booleanAttribute }]
|
|
1145
|
+
}] } });
|
|
1146
|
+
|
|
1147
|
+
/**
|
|
1148
|
+
* @license Apache-2.0
|
|
1149
|
+
*
|
|
1150
|
+
* Copyright (c) 2025 CuteWidgets Team. All Rights Reserved.
|
|
1151
|
+
*
|
|
1152
|
+
* You may not use this file except in compliance with the License
|
|
1153
|
+
* that can be found at http://www.apache.org/licenses/LICENSE-2.0
|
|
1154
|
+
*
|
|
1155
|
+
* This code is a modification of the `@angular/material` original
|
|
1156
|
+
* code licensed under MIT-style License (https://angular.dev/license).
|
|
1157
|
+
*/
|
|
1158
|
+
/**
|
|
1159
|
+
* Directive applied to an element to make it usable
|
|
1160
|
+
* as a connection point for an autocomplete panel.
|
|
1161
|
+
*/
|
|
1162
|
+
class CuteAutocompleteOrigin {
|
|
1163
|
+
constructor() {
|
|
1164
|
+
this.elementRef = inject(ElementRef);
|
|
1165
|
+
}
|
|
1166
|
+
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.3.15", ngImport: i0, type: CuteAutocompleteOrigin, deps: [], target: i0.ɵɵFactoryTarget.Directive }); }
|
|
1167
|
+
static { this.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "20.3.15", type: CuteAutocompleteOrigin, isStandalone: true, selector: "[cuteAutocompleteOrigin]", exportAs: ["cuteAutocompleteOrigin"], ngImport: i0 }); }
|
|
1168
|
+
}
|
|
1169
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.15", ngImport: i0, type: CuteAutocompleteOrigin, decorators: [{
|
|
1170
|
+
type: Directive,
|
|
1171
|
+
args: [{
|
|
1172
|
+
selector: '[cuteAutocompleteOrigin]',
|
|
1173
|
+
exportAs: 'cuteAutocompleteOrigin',
|
|
1174
|
+
standalone: true,
|
|
1175
|
+
}]
|
|
1176
|
+
}], ctorParameters: () => [] });
|
|
1177
|
+
|
|
1178
|
+
/**
|
|
1179
|
+
* @license Apache-2.0
|
|
1180
|
+
*
|
|
1181
|
+
* Copyright (c) 2025 CuteWidgets Team. All Rights Reserved.
|
|
1182
|
+
*
|
|
1183
|
+
* You may not use this file except in compliance with the License
|
|
1184
|
+
* that can be found at http://www.apache.org/licenses/LICENSE-2.0
|
|
1185
|
+
*/
|
|
1186
|
+
const TYPES = [
|
|
1187
|
+
CuteOptionModule,
|
|
1188
|
+
CuteAutocomplete,
|
|
1189
|
+
CuteAutocompleteTrigger,
|
|
1190
|
+
CuteAutocompleteOrigin
|
|
1191
|
+
];
|
|
1192
|
+
class CuteAutocompleteModule {
|
|
1193
|
+
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.3.15", ngImport: i0, type: CuteAutocompleteModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule }); }
|
|
1194
|
+
static { this.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "20.3.15", ngImport: i0, type: CuteAutocompleteModule, imports: [CommonModule, CuteOptionModule,
|
|
1195
|
+
CuteAutocomplete,
|
|
1196
|
+
CuteAutocompleteTrigger,
|
|
1197
|
+
CuteAutocompleteOrigin], exports: [CuteOptionModule,
|
|
1198
|
+
CuteAutocomplete,
|
|
1199
|
+
CuteAutocompleteTrigger,
|
|
1200
|
+
CuteAutocompleteOrigin] }); }
|
|
1201
|
+
static { this.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "20.3.15", ngImport: i0, type: CuteAutocompleteModule, imports: [CommonModule, CuteOptionModule, CuteOptionModule] }); }
|
|
1202
|
+
}
|
|
1203
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.15", ngImport: i0, type: CuteAutocompleteModule, decorators: [{
|
|
1204
|
+
type: NgModule,
|
|
1205
|
+
args: [{
|
|
1206
|
+
imports: [CommonModule, ...TYPES],
|
|
1207
|
+
exports: TYPES,
|
|
1208
|
+
declarations: [],
|
|
1209
|
+
}]
|
|
1210
|
+
}] });
|
|
1211
|
+
|
|
1212
|
+
/**
|
|
1213
|
+
* Generated bundle index. Do not edit.
|
|
1214
|
+
*/
|
|
1215
|
+
|
|
1216
|
+
export { CUTE_AUTOCOMPLETE_DEFAULT_OPTIONS, CUTE_AUTOCOMPLETE_SCROLL_STRATEGY, CUTE_AUTOCOMPLETE_VALUE_ACCESSOR, CuteAutocomplete, CuteAutocompleteModule, CuteAutocompleteOrigin, CuteAutocompleteSelectedEvent, CuteAutocompleteTrigger, getCuteAutocompleteMissingPanelError };
|
|
1217
|
+
//# sourceMappingURL=cute-widgets-base-autocomplete.mjs.map
|