source: trip-planner-front/node_modules/@angular/material/bundles/material-autocomplete.umd.js@ ceaed42

Last change on this file since ceaed42 was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

  • Property mode set to 100644
File size: 64.7 KB
Line 
1(function (global, factory) {
2 typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@angular/cdk/a11y'), require('@angular/cdk/coercion'), require('@angular/cdk/platform'), require('@angular/core'), require('@angular/material/core'), require('rxjs'), require('@angular/common'), require('@angular/cdk/overlay'), require('@angular/cdk/scrolling'), require('@angular/cdk/bidi'), require('@angular/cdk/keycodes'), require('@angular/cdk/portal'), require('@angular/forms'), require('@angular/material/form-field'), require('rxjs/operators')) :
3 typeof define === 'function' && define.amd ? define('@angular/material/autocomplete', ['exports', '@angular/cdk/a11y', '@angular/cdk/coercion', '@angular/cdk/platform', '@angular/core', '@angular/material/core', 'rxjs', '@angular/common', '@angular/cdk/overlay', '@angular/cdk/scrolling', '@angular/cdk/bidi', '@angular/cdk/keycodes', '@angular/cdk/portal', '@angular/forms', '@angular/material/form-field', 'rxjs/operators'], factory) :
4 (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory((global.ng = global.ng || {}, global.ng.material = global.ng.material || {}, global.ng.material.autocomplete = {}), global.ng.cdk.a11y, global.ng.cdk.coercion, global.ng.cdk.platform, global.ng.core, global.ng.material.core, global.rxjs, global.ng.common, global.ng.cdk.overlay, global.ng.cdk.scrolling, global.ng.cdk.bidi, global.ng.cdk.keycodes, global.ng.cdk.portal, global.ng.forms, global.ng.material.formField, global.rxjs.operators));
5}(this, (function (exports, a11y, coercion, platform, core$1, core, rxjs, common, overlay, scrolling, bidi, keycodes, portal, forms, formField, operators) { 'use strict';
6
7 /*! *****************************************************************************
8 Copyright (c) Microsoft Corporation.
9
10 Permission to use, copy, modify, and/or distribute this software for any
11 purpose with or without fee is hereby granted.
12
13 THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
14 REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
15 AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
16 INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
17 LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
18 OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
19 PERFORMANCE OF THIS SOFTWARE.
20 ***************************************************************************** */
21 /* global Reflect, Promise */
22 var extendStatics = function (d, b) {
23 extendStatics = Object.setPrototypeOf ||
24 ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
25 function (d, b) { for (var p in b)
26 if (Object.prototype.hasOwnProperty.call(b, p))
27 d[p] = b[p]; };
28 return extendStatics(d, b);
29 };
30 function __extends(d, b) {
31 if (typeof b !== "function" && b !== null)
32 throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
33 extendStatics(d, b);
34 function __() { this.constructor = d; }
35 d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
36 }
37 var __assign = function () {
38 __assign = Object.assign || function __assign(t) {
39 for (var s, i = 1, n = arguments.length; i < n; i++) {
40 s = arguments[i];
41 for (var p in s)
42 if (Object.prototype.hasOwnProperty.call(s, p))
43 t[p] = s[p];
44 }
45 return t;
46 };
47 return __assign.apply(this, arguments);
48 };
49 function __rest(s, e) {
50 var t = {};
51 for (var p in s)
52 if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
53 t[p] = s[p];
54 if (s != null && typeof Object.getOwnPropertySymbols === "function")
55 for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
56 if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
57 t[p[i]] = s[p[i]];
58 }
59 return t;
60 }
61 function __decorate(decorators, target, key, desc) {
62 var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
63 if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
64 r = Reflect.decorate(decorators, target, key, desc);
65 else
66 for (var i = decorators.length - 1; i >= 0; i--)
67 if (d = decorators[i])
68 r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
69 return c > 3 && r && Object.defineProperty(target, key, r), r;
70 }
71 function __param(paramIndex, decorator) {
72 return function (target, key) { decorator(target, key, paramIndex); };
73 }
74 function __metadata(metadataKey, metadataValue) {
75 if (typeof Reflect === "object" && typeof Reflect.metadata === "function")
76 return Reflect.metadata(metadataKey, metadataValue);
77 }
78 function __awaiter(thisArg, _arguments, P, generator) {
79 function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
80 return new (P || (P = Promise))(function (resolve, reject) {
81 function fulfilled(value) { try {
82 step(generator.next(value));
83 }
84 catch (e) {
85 reject(e);
86 } }
87 function rejected(value) { try {
88 step(generator["throw"](value));
89 }
90 catch (e) {
91 reject(e);
92 } }
93 function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
94 step((generator = generator.apply(thisArg, _arguments || [])).next());
95 });
96 }
97 function __generator(thisArg, body) {
98 var _ = { label: 0, sent: function () { if (t[0] & 1)
99 throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
100 return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function () { return this; }), g;
101 function verb(n) { return function (v) { return step([n, v]); }; }
102 function step(op) {
103 if (f)
104 throw new TypeError("Generator is already executing.");
105 while (_)
106 try {
107 if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done)
108 return t;
109 if (y = 0, t)
110 op = [op[0] & 2, t.value];
111 switch (op[0]) {
112 case 0:
113 case 1:
114 t = op;
115 break;
116 case 4:
117 _.label++;
118 return { value: op[1], done: false };
119 case 5:
120 _.label++;
121 y = op[1];
122 op = [0];
123 continue;
124 case 7:
125 op = _.ops.pop();
126 _.trys.pop();
127 continue;
128 default:
129 if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
130 _ = 0;
131 continue;
132 }
133 if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) {
134 _.label = op[1];
135 break;
136 }
137 if (op[0] === 6 && _.label < t[1]) {
138 _.label = t[1];
139 t = op;
140 break;
141 }
142 if (t && _.label < t[2]) {
143 _.label = t[2];
144 _.ops.push(op);
145 break;
146 }
147 if (t[2])
148 _.ops.pop();
149 _.trys.pop();
150 continue;
151 }
152 op = body.call(thisArg, _);
153 }
154 catch (e) {
155 op = [6, e];
156 y = 0;
157 }
158 finally {
159 f = t = 0;
160 }
161 if (op[0] & 5)
162 throw op[1];
163 return { value: op[0] ? op[1] : void 0, done: true };
164 }
165 }
166 var __createBinding = Object.create ? (function (o, m, k, k2) {
167 if (k2 === undefined)
168 k2 = k;
169 Object.defineProperty(o, k2, { enumerable: true, get: function () { return m[k]; } });
170 }) : (function (o, m, k, k2) {
171 if (k2 === undefined)
172 k2 = k;
173 o[k2] = m[k];
174 });
175 function __exportStar(m, o) {
176 for (var p in m)
177 if (p !== "default" && !Object.prototype.hasOwnProperty.call(o, p))
178 __createBinding(o, m, p);
179 }
180 function __values(o) {
181 var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
182 if (m)
183 return m.call(o);
184 if (o && typeof o.length === "number")
185 return {
186 next: function () {
187 if (o && i >= o.length)
188 o = void 0;
189 return { value: o && o[i++], done: !o };
190 }
191 };
192 throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
193 }
194 function __read(o, n) {
195 var m = typeof Symbol === "function" && o[Symbol.iterator];
196 if (!m)
197 return o;
198 var i = m.call(o), r, ar = [], e;
199 try {
200 while ((n === void 0 || n-- > 0) && !(r = i.next()).done)
201 ar.push(r.value);
202 }
203 catch (error) {
204 e = { error: error };
205 }
206 finally {
207 try {
208 if (r && !r.done && (m = i["return"]))
209 m.call(i);
210 }
211 finally {
212 if (e)
213 throw e.error;
214 }
215 }
216 return ar;
217 }
218 /** @deprecated */
219 function __spread() {
220 for (var ar = [], i = 0; i < arguments.length; i++)
221 ar = ar.concat(__read(arguments[i]));
222 return ar;
223 }
224 /** @deprecated */
225 function __spreadArrays() {
226 for (var s = 0, i = 0, il = arguments.length; i < il; i++)
227 s += arguments[i].length;
228 for (var r = Array(s), k = 0, i = 0; i < il; i++)
229 for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++)
230 r[k] = a[j];
231 return r;
232 }
233 function __spreadArray(to, from, pack) {
234 if (pack || arguments.length === 2)
235 for (var i = 0, l = from.length, ar; i < l; i++) {
236 if (ar || !(i in from)) {
237 if (!ar)
238 ar = Array.prototype.slice.call(from, 0, i);
239 ar[i] = from[i];
240 }
241 }
242 return to.concat(ar || from);
243 }
244 function __await(v) {
245 return this instanceof __await ? (this.v = v, this) : new __await(v);
246 }
247 function __asyncGenerator(thisArg, _arguments, generator) {
248 if (!Symbol.asyncIterator)
249 throw new TypeError("Symbol.asyncIterator is not defined.");
250 var g = generator.apply(thisArg, _arguments || []), i, q = [];
251 return i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i;
252 function verb(n) { if (g[n])
253 i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; }
254 function resume(n, v) { try {
255 step(g[n](v));
256 }
257 catch (e) {
258 settle(q[0][3], e);
259 } }
260 function step(r) { r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r); }
261 function fulfill(value) { resume("next", value); }
262 function reject(value) { resume("throw", value); }
263 function settle(f, v) { if (f(v), q.shift(), q.length)
264 resume(q[0][0], q[0][1]); }
265 }
266 function __asyncDelegator(o) {
267 var i, p;
268 return i = {}, verb("next"), verb("throw", function (e) { throw e; }), verb("return"), i[Symbol.iterator] = function () { return this; }, i;
269 function verb(n, f) { i[n] = o[n] ? function (v) { return (p = !p) ? { value: __await(o[n](v)), done: n === "return" } : f ? f(v) : v; } : f; }
270 }
271 function __asyncValues(o) {
272 if (!Symbol.asyncIterator)
273 throw new TypeError("Symbol.asyncIterator is not defined.");
274 var m = o[Symbol.asyncIterator], i;
275 return m ? m.call(o) : (o = typeof __values === "function" ? __values(o) : o[Symbol.iterator](), i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i);
276 function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }
277 function settle(resolve, reject, d, v) { Promise.resolve(v).then(function (v) { resolve({ value: v, done: d }); }, reject); }
278 }
279 function __makeTemplateObject(cooked, raw) {
280 if (Object.defineProperty) {
281 Object.defineProperty(cooked, "raw", { value: raw });
282 }
283 else {
284 cooked.raw = raw;
285 }
286 return cooked;
287 }
288 ;
289 var __setModuleDefault = Object.create ? (function (o, v) {
290 Object.defineProperty(o, "default", { enumerable: true, value: v });
291 }) : function (o, v) {
292 o["default"] = v;
293 };
294 function __importStar(mod) {
295 if (mod && mod.__esModule)
296 return mod;
297 var result = {};
298 if (mod != null)
299 for (var k in mod)
300 if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k))
301 __createBinding(result, mod, k);
302 __setModuleDefault(result, mod);
303 return result;
304 }
305 function __importDefault(mod) {
306 return (mod && mod.__esModule) ? mod : { default: mod };
307 }
308 function __classPrivateFieldGet(receiver, state, kind, f) {
309 if (kind === "a" && !f)
310 throw new TypeError("Private accessor was defined without a getter");
311 if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver))
312 throw new TypeError("Cannot read private member from an object whose class did not declare it");
313 return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
314 }
315 function __classPrivateFieldSet(receiver, state, value, kind, f) {
316 if (kind === "m")
317 throw new TypeError("Private method is not writable");
318 if (kind === "a" && !f)
319 throw new TypeError("Private accessor was defined without a setter");
320 if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver))
321 throw new TypeError("Cannot write private member to an object whose class did not declare it");
322 return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
323 }
324
325 /**
326 * Autocomplete IDs need to be unique across components, so this counter exists outside of
327 * the component definition.
328 */
329 var _uniqueAutocompleteIdCounter = 0;
330 /** Event object that is emitted when an autocomplete option is selected. */
331 var MatAutocompleteSelectedEvent = /** @class */ (function () {
332 function MatAutocompleteSelectedEvent(
333 /** Reference to the autocomplete panel that emitted the event. */
334 source,
335 /** Option that was selected. */
336 option) {
337 this.source = source;
338 this.option = option;
339 }
340 return MatAutocompleteSelectedEvent;
341 }());
342 // Boilerplate for applying mixins to MatAutocomplete.
343 /** @docs-private */
344 var _MatAutocompleteMixinBase = core.mixinDisableRipple(/** @class */ (function () {
345 function class_1() {
346 }
347 return class_1;
348 }()));
349 /** Injection token to be used to override the default options for `mat-autocomplete`. */
350 var MAT_AUTOCOMPLETE_DEFAULT_OPTIONS = new core$1.InjectionToken('mat-autocomplete-default-options', {
351 providedIn: 'root',
352 factory: MAT_AUTOCOMPLETE_DEFAULT_OPTIONS_FACTORY,
353 });
354 /** @docs-private */
355 function MAT_AUTOCOMPLETE_DEFAULT_OPTIONS_FACTORY() {
356 return { autoActiveFirstOption: false };
357 }
358 /** Base class with all of the `MatAutocomplete` functionality. */
359 var _MatAutocompleteBase = /** @class */ (function (_super) {
360 __extends(_MatAutocompleteBase, _super);
361 function _MatAutocompleteBase(_changeDetectorRef, _elementRef, defaults, platform) {
362 var _this = _super.call(this) || this;
363 _this._changeDetectorRef = _changeDetectorRef;
364 _this._elementRef = _elementRef;
365 _this._activeOptionChanges = rxjs.Subscription.EMPTY;
366 /** Whether the autocomplete panel should be visible, depending on option length. */
367 _this.showPanel = false;
368 _this._isOpen = false;
369 /** Function that maps an option's control value to its display value in the trigger. */
370 _this.displayWith = null;
371 /** Event that is emitted whenever an option from the list is selected. */
372 _this.optionSelected = new core$1.EventEmitter();
373 /** Event that is emitted when the autocomplete panel is opened. */
374 _this.opened = new core$1.EventEmitter();
375 /** Event that is emitted when the autocomplete panel is closed. */
376 _this.closed = new core$1.EventEmitter();
377 /** Emits whenever an option is activated using the keyboard. */
378 _this.optionActivated = new core$1.EventEmitter();
379 _this._classList = {};
380 /** Unique ID to be used by autocomplete trigger's "aria-owns" property. */
381 _this.id = "mat-autocomplete-" + _uniqueAutocompleteIdCounter++;
382 // TODO(crisbeto): the problem that the `inertGroups` option resolves is only present on
383 // Safari using VoiceOver. We should occasionally check back to see whether the bug
384 // wasn't resolved in VoiceOver, and if it has, we can remove this and the `inertGroups`
385 // option altogether.
386 _this.inertGroups = (platform === null || platform === void 0 ? void 0 : platform.SAFARI) || false;
387 _this._autoActiveFirstOption = !!defaults.autoActiveFirstOption;
388 return _this;
389 }
390 Object.defineProperty(_MatAutocompleteBase.prototype, "isOpen", {
391 /** Whether the autocomplete panel is open. */
392 get: function () { return this._isOpen && this.showPanel; },
393 enumerable: false,
394 configurable: true
395 });
396 Object.defineProperty(_MatAutocompleteBase.prototype, "autoActiveFirstOption", {
397 /**
398 * Whether the first option should be highlighted when the autocomplete panel is opened.
399 * Can be configured globally through the `MAT_AUTOCOMPLETE_DEFAULT_OPTIONS` token.
400 */
401 get: function () { return this._autoActiveFirstOption; },
402 set: function (value) {
403 this._autoActiveFirstOption = coercion.coerceBooleanProperty(value);
404 },
405 enumerable: false,
406 configurable: true
407 });
408 Object.defineProperty(_MatAutocompleteBase.prototype, "classList", {
409 /**
410 * Takes classes set on the host mat-autocomplete element and applies them to the panel
411 * inside the overlay container to allow for easy styling.
412 */
413 set: function (value) {
414 if (value && value.length) {
415 this._classList = coercion.coerceStringArray(value).reduce(function (classList, className) {
416 classList[className] = true;
417 return classList;
418 }, {});
419 }
420 else {
421 this._classList = {};
422 }
423 this._setVisibilityClasses(this._classList);
424 this._elementRef.nativeElement.className = '';
425 },
426 enumerable: false,
427 configurable: true
428 });
429 _MatAutocompleteBase.prototype.ngAfterContentInit = function () {
430 var _this = this;
431 this._keyManager = new a11y.ActiveDescendantKeyManager(this.options).withWrap();
432 this._activeOptionChanges = this._keyManager.change.subscribe(function (index) {
433 if (_this.isOpen) {
434 _this.optionActivated.emit({ source: _this, option: _this.options.toArray()[index] || null });
435 }
436 });
437 // Set the initial visibility state.
438 this._setVisibility();
439 };
440 _MatAutocompleteBase.prototype.ngOnDestroy = function () {
441 this._activeOptionChanges.unsubscribe();
442 };
443 /**
444 * Sets the panel scrollTop. This allows us to manually scroll to display options
445 * above or below the fold, as they are not actually being focused when active.
446 */
447 _MatAutocompleteBase.prototype._setScrollTop = function (scrollTop) {
448 if (this.panel) {
449 this.panel.nativeElement.scrollTop = scrollTop;
450 }
451 };
452 /** Returns the panel's scrollTop. */
453 _MatAutocompleteBase.prototype._getScrollTop = function () {
454 return this.panel ? this.panel.nativeElement.scrollTop : 0;
455 };
456 /** Panel should hide itself when the option list is empty. */
457 _MatAutocompleteBase.prototype._setVisibility = function () {
458 this.showPanel = !!this.options.length;
459 this._setVisibilityClasses(this._classList);
460 this._changeDetectorRef.markForCheck();
461 };
462 /** Emits the `select` event. */
463 _MatAutocompleteBase.prototype._emitSelectEvent = function (option) {
464 var event = new MatAutocompleteSelectedEvent(this, option);
465 this.optionSelected.emit(event);
466 };
467 /** Gets the aria-labelledby for the autocomplete panel. */
468 _MatAutocompleteBase.prototype._getPanelAriaLabelledby = function (labelId) {
469 if (this.ariaLabel) {
470 return null;
471 }
472 var labelExpression = labelId ? labelId + ' ' : '';
473 return this.ariaLabelledby ? labelExpression + this.ariaLabelledby : labelId;
474 };
475 /** Sets the autocomplete visibility classes on a classlist based on the panel is visible. */
476 _MatAutocompleteBase.prototype._setVisibilityClasses = function (classList) {
477 classList[this._visibleClass] = this.showPanel;
478 classList[this._hiddenClass] = !this.showPanel;
479 };
480 return _MatAutocompleteBase;
481 }(_MatAutocompleteMixinBase));
482 _MatAutocompleteBase.decorators = [
483 { type: core$1.Directive }
484 ];
485 _MatAutocompleteBase.ctorParameters = function () { return [
486 { type: core$1.ChangeDetectorRef },
487 { type: core$1.ElementRef },
488 { type: undefined, decorators: [{ type: core$1.Inject, args: [MAT_AUTOCOMPLETE_DEFAULT_OPTIONS,] }] },
489 { type: platform.Platform }
490 ]; };
491 _MatAutocompleteBase.propDecorators = {
492 template: [{ type: core$1.ViewChild, args: [core$1.TemplateRef, { static: true },] }],
493 panel: [{ type: core$1.ViewChild, args: ['panel',] }],
494 ariaLabel: [{ type: core$1.Input, args: ['aria-label',] }],
495 ariaLabelledby: [{ type: core$1.Input, args: ['aria-labelledby',] }],
496 displayWith: [{ type: core$1.Input }],
497 autoActiveFirstOption: [{ type: core$1.Input }],
498 panelWidth: [{ type: core$1.Input }],
499 optionSelected: [{ type: core$1.Output }],
500 opened: [{ type: core$1.Output }],
501 closed: [{ type: core$1.Output }],
502 optionActivated: [{ type: core$1.Output }],
503 classList: [{ type: core$1.Input, args: ['class',] }]
504 };
505 var MatAutocomplete = /** @class */ (function (_super) {
506 __extends(MatAutocomplete, _super);
507 function MatAutocomplete() {
508 var _this = _super.apply(this, __spreadArray([], __read(arguments))) || this;
509 _this._visibleClass = 'mat-autocomplete-visible';
510 _this._hiddenClass = 'mat-autocomplete-hidden';
511 return _this;
512 }
513 return MatAutocomplete;
514 }(_MatAutocompleteBase));
515 MatAutocomplete.decorators = [
516 { type: core$1.Component, args: [{
517 selector: 'mat-autocomplete',
518 template: "<ng-template let-formFieldId=\"id\">\n <div class=\"mat-autocomplete-panel\"\n role=\"listbox\"\n [id]=\"id\"\n [attr.aria-label]=\"ariaLabel || null\"\n [attr.aria-labelledby]=\"_getPanelAriaLabelledby(formFieldId)\"\n [ngClass]=\"_classList\"\n #panel>\n <ng-content></ng-content>\n </div>\n</ng-template>\n",
519 encapsulation: core$1.ViewEncapsulation.None,
520 changeDetection: core$1.ChangeDetectionStrategy.OnPush,
521 exportAs: 'matAutocomplete',
522 inputs: ['disableRipple'],
523 host: {
524 'class': 'mat-autocomplete'
525 },
526 providers: [
527 { provide: core.MAT_OPTION_PARENT_COMPONENT, useExisting: MatAutocomplete }
528 ],
529 styles: [".mat-autocomplete-panel{min-width:112px;max-width:280px;overflow:auto;-webkit-overflow-scrolling:touch;visibility:hidden;max-width:none;max-height:256px;position:relative;width:100%;border-bottom-left-radius:4px;border-bottom-right-radius:4px}.mat-autocomplete-panel.mat-autocomplete-visible{visibility:visible}.mat-autocomplete-panel.mat-autocomplete-hidden{visibility:hidden}.mat-autocomplete-panel-above .mat-autocomplete-panel{border-radius:0;border-top-left-radius:4px;border-top-right-radius:4px}.mat-autocomplete-panel .mat-divider-horizontal{margin-top:-1px}.cdk-high-contrast-active .mat-autocomplete-panel{outline:solid 1px}mat-autocomplete{display:none}\n"]
530 },] }
531 ];
532 MatAutocomplete.propDecorators = {
533 optionGroups: [{ type: core$1.ContentChildren, args: [core.MAT_OPTGROUP, { descendants: true },] }],
534 options: [{ type: core$1.ContentChildren, args: [core.MatOption, { descendants: true },] }]
535 };
536
537 /** Injection token that determines the scroll handling while the autocomplete panel is open. */
538 var MAT_AUTOCOMPLETE_SCROLL_STRATEGY = new core$1.InjectionToken('mat-autocomplete-scroll-strategy');
539 /** @docs-private */
540 function MAT_AUTOCOMPLETE_SCROLL_STRATEGY_FACTORY(overlay) {
541 return function () { return overlay.scrollStrategies.reposition(); };
542 }
543 /** @docs-private */
544 var MAT_AUTOCOMPLETE_SCROLL_STRATEGY_FACTORY_PROVIDER = {
545 provide: MAT_AUTOCOMPLETE_SCROLL_STRATEGY,
546 deps: [overlay.Overlay],
547 useFactory: MAT_AUTOCOMPLETE_SCROLL_STRATEGY_FACTORY,
548 };
549 /**
550 * Provider that allows the autocomplete to register as a ControlValueAccessor.
551 * @docs-private
552 */
553 var MAT_AUTOCOMPLETE_VALUE_ACCESSOR = {
554 provide: forms.NG_VALUE_ACCESSOR,
555 useExisting: core$1.forwardRef(function () { return MatAutocompleteTrigger; }),
556 multi: true
557 };
558 /**
559 * Creates an error to be thrown when attempting to use an autocomplete trigger without a panel.
560 * @docs-private
561 */
562 function getMatAutocompleteMissingPanelError() {
563 return Error('Attempting to open an undefined instance of `mat-autocomplete`. ' +
564 'Make sure that the id passed to the `matAutocomplete` is correct and that ' +
565 'you\'re attempting to open it after the ngAfterContentInit hook.');
566 }
567 /** Base class with all of the `MatAutocompleteTrigger` functionality. */
568 var _MatAutocompleteTriggerBase = /** @class */ (function () {
569 function _MatAutocompleteTriggerBase(_element, _overlay, _viewContainerRef, _zone, _changeDetectorRef, scrollStrategy, _dir, _formField, _document, _viewportRuler, _defaults) {
570 var _this = this;
571 this._element = _element;
572 this._overlay = _overlay;
573 this._viewContainerRef = _viewContainerRef;
574 this._zone = _zone;
575 this._changeDetectorRef = _changeDetectorRef;
576 this._dir = _dir;
577 this._formField = _formField;
578 this._document = _document;
579 this._viewportRuler = _viewportRuler;
580 this._defaults = _defaults;
581 this._componentDestroyed = false;
582 this._autocompleteDisabled = false;
583 /** Whether or not the label state is being overridden. */
584 this._manuallyFloatingLabel = false;
585 /** Subscription to viewport size changes. */
586 this._viewportSubscription = rxjs.Subscription.EMPTY;
587 /**
588 * Whether the autocomplete can open the next time it is focused. Used to prevent a focused,
589 * closed autocomplete from being reopened if the user switches to another browser tab and then
590 * comes back.
591 */
592 this._canOpenOnNextFocus = true;
593 /** Stream of keyboard events that can close the panel. */
594 this._closeKeyEventStream = new rxjs.Subject();
595 /**
596 * Event handler for when the window is blurred. Needs to be an
597 * arrow function in order to preserve the context.
598 */
599 this._windowBlurHandler = function () {
600 // If the user blurred the window while the autocomplete is focused, it means that it'll be
601 // refocused when they come back. In this case we want to skip the first focus event, if the
602 // pane was closed, in order to avoid reopening it unintentionally.
603 _this._canOpenOnNextFocus =
604 _this._document.activeElement !== _this._element.nativeElement || _this.panelOpen;
605 };
606 /** `View -> model callback called when value changes` */
607 this._onChange = function () { };
608 /** `View -> model callback called when autocomplete has been touched` */
609 this._onTouched = function () { };
610 /**
611 * Position of the autocomplete panel relative to the trigger element. A position of `auto`
612 * will render the panel underneath the trigger if there is enough space for it to fit in
613 * the viewport, otherwise the panel will be shown above it. If the position is set to
614 * `above` or `below`, the panel will always be shown above or below the trigger. no matter
615 * whether it fits completely in the viewport.
616 */
617 this.position = 'auto';
618 /**
619 * `autocomplete` attribute to be set on the input element.
620 * @docs-private
621 */
622 this.autocompleteAttribute = 'off';
623 this._overlayAttached = false;
624 /** Stream of autocomplete option selections. */
625 this.optionSelections = rxjs.defer(function () {
626 if (_this.autocomplete && _this.autocomplete.options) {
627 return rxjs.merge.apply(void 0, __spreadArray([], __read(_this.autocomplete.options.map(function (option) { return option.onSelectionChange; }))));
628 }
629 // If there are any subscribers before `ngAfterViewInit`, the `autocomplete` will be undefined.
630 // Return a stream that we'll replace with the real one once everything is in place.
631 return _this._zone.onStable
632 .pipe(operators.take(1), operators.switchMap(function () { return _this.optionSelections; }));
633 });
634 this._scrollStrategy = scrollStrategy;
635 }
636 Object.defineProperty(_MatAutocompleteTriggerBase.prototype, "autocompleteDisabled", {
637 /**
638 * Whether the autocomplete is disabled. When disabled, the element will
639 * act as a regular input and the user won't be able to open the panel.
640 */
641 get: function () { return this._autocompleteDisabled; },
642 set: function (value) {
643 this._autocompleteDisabled = coercion.coerceBooleanProperty(value);
644 },
645 enumerable: false,
646 configurable: true
647 });
648 _MatAutocompleteTriggerBase.prototype.ngAfterViewInit = function () {
649 var _this = this;
650 var window = this._getWindow();
651 if (typeof window !== 'undefined') {
652 this._zone.runOutsideAngular(function () { return window.addEventListener('blur', _this._windowBlurHandler); });
653 }
654 };
655 _MatAutocompleteTriggerBase.prototype.ngOnChanges = function (changes) {
656 if (changes['position'] && this._positionStrategy) {
657 this._setStrategyPositions(this._positionStrategy);
658 if (this.panelOpen) {
659 this._overlayRef.updatePosition();
660 }
661 }
662 };
663 _MatAutocompleteTriggerBase.prototype.ngOnDestroy = function () {
664 var window = this._getWindow();
665 if (typeof window !== 'undefined') {
666 window.removeEventListener('blur', this._windowBlurHandler);
667 }
668 this._viewportSubscription.unsubscribe();
669 this._componentDestroyed = true;
670 this._destroyPanel();
671 this._closeKeyEventStream.complete();
672 };
673 Object.defineProperty(_MatAutocompleteTriggerBase.prototype, "panelOpen", {
674 /** Whether or not the autocomplete panel is open. */
675 get: function () {
676 return this._overlayAttached && this.autocomplete.showPanel;
677 },
678 enumerable: false,
679 configurable: true
680 });
681 /** Opens the autocomplete suggestion panel. */
682 _MatAutocompleteTriggerBase.prototype.openPanel = function () {
683 this._attachOverlay();
684 this._floatLabel();
685 };
686 /** Closes the autocomplete suggestion panel. */
687 _MatAutocompleteTriggerBase.prototype.closePanel = function () {
688 this._resetLabel();
689 if (!this._overlayAttached) {
690 return;
691 }
692 if (this.panelOpen) {
693 // Only emit if the panel was visible.
694 this.autocomplete.closed.emit();
695 }
696 this.autocomplete._isOpen = this._overlayAttached = false;
697 if (this._overlayRef && this._overlayRef.hasAttached()) {
698 this._overlayRef.detach();
699 this._closingActionsSubscription.unsubscribe();
700 }
701 // Note that in some cases this can end up being called after the component is destroyed.
702 // Add a check to ensure that we don't try to run change detection on a destroyed view.
703 if (!this._componentDestroyed) {
704 // We need to trigger change detection manually, because
705 // `fromEvent` doesn't seem to do it at the proper time.
706 // This ensures that the label is reset when the
707 // user clicks outside.
708 this._changeDetectorRef.detectChanges();
709 }
710 };
711 /**
712 * Updates the position of the autocomplete suggestion panel to ensure that it fits all options
713 * within the viewport.
714 */
715 _MatAutocompleteTriggerBase.prototype.updatePosition = function () {
716 if (this._overlayAttached) {
717 this._overlayRef.updatePosition();
718 }
719 };
720 Object.defineProperty(_MatAutocompleteTriggerBase.prototype, "panelClosingActions", {
721 /**
722 * A stream of actions that should close the autocomplete panel, including
723 * when an option is selected, on blur, and when TAB is pressed.
724 */
725 get: function () {
726 var _this = this;
727 return rxjs.merge(this.optionSelections, this.autocomplete._keyManager.tabOut.pipe(operators.filter(function () { return _this._overlayAttached; })), this._closeKeyEventStream, this._getOutsideClickStream(), this._overlayRef ?
728 this._overlayRef.detachments().pipe(operators.filter(function () { return _this._overlayAttached; })) :
729 rxjs.of()).pipe(
730 // Normalize the output so we return a consistent type.
731 operators.map(function (event) { return event instanceof core.MatOptionSelectionChange ? event : null; }));
732 },
733 enumerable: false,
734 configurable: true
735 });
736 Object.defineProperty(_MatAutocompleteTriggerBase.prototype, "activeOption", {
737 /** The currently active option, coerced to MatOption type. */
738 get: function () {
739 if (this.autocomplete && this.autocomplete._keyManager) {
740 return this.autocomplete._keyManager.activeItem;
741 }
742 return null;
743 },
744 enumerable: false,
745 configurable: true
746 });
747 /** Stream of clicks outside of the autocomplete panel. */
748 _MatAutocompleteTriggerBase.prototype._getOutsideClickStream = function () {
749 var _this = this;
750 return rxjs.merge(rxjs.fromEvent(this._document, 'click'), rxjs.fromEvent(this._document, 'auxclick'), rxjs.fromEvent(this._document, 'touchend'))
751 .pipe(operators.filter(function (event) {
752 // If we're in the Shadow DOM, the event target will be the shadow root, so we have to
753 // fall back to check the first element in the path of the click event.
754 var clickTarget = platform._getEventTarget(event);
755 var formField = _this._formField ? _this._formField._elementRef.nativeElement : null;
756 var customOrigin = _this.connectedTo ? _this.connectedTo.elementRef.nativeElement : null;
757 return _this._overlayAttached && clickTarget !== _this._element.nativeElement &&
758 (!formField || !formField.contains(clickTarget)) &&
759 (!customOrigin || !customOrigin.contains(clickTarget)) &&
760 (!!_this._overlayRef && !_this._overlayRef.overlayElement.contains(clickTarget));
761 }));
762 };
763 // Implemented as part of ControlValueAccessor.
764 _MatAutocompleteTriggerBase.prototype.writeValue = function (value) {
765 var _this = this;
766 Promise.resolve(null).then(function () { return _this._setTriggerValue(value); });
767 };
768 // Implemented as part of ControlValueAccessor.
769 _MatAutocompleteTriggerBase.prototype.registerOnChange = function (fn) {
770 this._onChange = fn;
771 };
772 // Implemented as part of ControlValueAccessor.
773 _MatAutocompleteTriggerBase.prototype.registerOnTouched = function (fn) {
774 this._onTouched = fn;
775 };
776 // Implemented as part of ControlValueAccessor.
777 _MatAutocompleteTriggerBase.prototype.setDisabledState = function (isDisabled) {
778 this._element.nativeElement.disabled = isDisabled;
779 };
780 _MatAutocompleteTriggerBase.prototype._handleKeydown = function (event) {
781 var keyCode = event.keyCode;
782 // Prevent the default action on all escape key presses. This is here primarily to bring IE
783 // in line with other browsers. By default, pressing escape on IE will cause it to revert
784 // the input value to the one that it had on focus, however it won't dispatch any events
785 // which means that the model value will be out of sync with the view.
786 if (keyCode === keycodes.ESCAPE && !keycodes.hasModifierKey(event)) {
787 event.preventDefault();
788 }
789 if (this.activeOption && keyCode === keycodes.ENTER && this.panelOpen) {
790 this.activeOption._selectViaInteraction();
791 this._resetActiveItem();
792 event.preventDefault();
793 }
794 else if (this.autocomplete) {
795 var prevActiveItem = this.autocomplete._keyManager.activeItem;
796 var isArrowKey = keyCode === keycodes.UP_ARROW || keyCode === keycodes.DOWN_ARROW;
797 if (this.panelOpen || keyCode === keycodes.TAB) {
798 this.autocomplete._keyManager.onKeydown(event);
799 }
800 else if (isArrowKey && this._canOpen()) {
801 this.openPanel();
802 }
803 if (isArrowKey || this.autocomplete._keyManager.activeItem !== prevActiveItem) {
804 this._scrollToOption(this.autocomplete._keyManager.activeItemIndex || 0);
805 }
806 }
807 };
808 _MatAutocompleteTriggerBase.prototype._handleInput = function (event) {
809 var target = event.target;
810 var value = target.value;
811 // Based on `NumberValueAccessor` from forms.
812 if (target.type === 'number') {
813 value = value == '' ? null : parseFloat(value);
814 }
815 // If the input has a placeholder, IE will fire the `input` event on page load,
816 // focus and blur, in addition to when the user actually changed the value. To
817 // filter out all of the extra events, we save the value on focus and between
818 // `input` events, and we check whether it changed.
819 // See: https://connect.microsoft.com/IE/feedback/details/885747/
820 if (this._previousValue !== value) {
821 this._previousValue = value;
822 this._onChange(value);
823 if (this._canOpen() && this._document.activeElement === event.target) {
824 this.openPanel();
825 }
826 }
827 };
828 _MatAutocompleteTriggerBase.prototype._handleFocus = function () {
829 if (!this._canOpenOnNextFocus) {
830 this._canOpenOnNextFocus = true;
831 }
832 else if (this._canOpen()) {
833 this._previousValue = this._element.nativeElement.value;
834 this._attachOverlay();
835 this._floatLabel(true);
836 }
837 };
838 /**
839 * In "auto" mode, the label will animate down as soon as focus is lost.
840 * This causes the value to jump when selecting an option with the mouse.
841 * This method manually floats the label until the panel can be closed.
842 * @param shouldAnimate Whether the label should be animated when it is floated.
843 */
844 _MatAutocompleteTriggerBase.prototype._floatLabel = function (shouldAnimate) {
845 if (shouldAnimate === void 0) { shouldAnimate = false; }
846 if (this._formField && this._formField.floatLabel === 'auto') {
847 if (shouldAnimate) {
848 this._formField._animateAndLockLabel();
849 }
850 else {
851 this._formField.floatLabel = 'always';
852 }
853 this._manuallyFloatingLabel = true;
854 }
855 };
856 /** If the label has been manually elevated, return it to its normal state. */
857 _MatAutocompleteTriggerBase.prototype._resetLabel = function () {
858 if (this._manuallyFloatingLabel) {
859 this._formField.floatLabel = 'auto';
860 this._manuallyFloatingLabel = false;
861 }
862 };
863 /**
864 * This method listens to a stream of panel closing actions and resets the
865 * stream every time the option list changes.
866 */
867 _MatAutocompleteTriggerBase.prototype._subscribeToClosingActions = function () {
868 var _this = this;
869 var firstStable = this._zone.onStable.pipe(operators.take(1));
870 var optionChanges = this.autocomplete.options.changes.pipe(operators.tap(function () { return _this._positionStrategy.reapplyLastPosition(); }),
871 // Defer emitting to the stream until the next tick, because changing
872 // bindings in here will cause "changed after checked" errors.
873 operators.delay(0));
874 // When the zone is stable initially, and when the option list changes...
875 return rxjs.merge(firstStable, optionChanges)
876 .pipe(
877 // create a new stream of panelClosingActions, replacing any previous streams
878 // that were created, and flatten it so our stream only emits closing events...
879 operators.switchMap(function () {
880 var wasOpen = _this.panelOpen;
881 _this._resetActiveItem();
882 _this.autocomplete._setVisibility();
883 if (_this.panelOpen) {
884 _this._overlayRef.updatePosition();
885 // If the `panelOpen` state changed, we need to make sure to emit the `opened`
886 // event, because we may not have emitted it when the panel was attached. This
887 // can happen if the users opens the panel and there are no options, but the
888 // options come in slightly later or as a result of the value changing.
889 if (wasOpen !== _this.panelOpen) {
890 _this.autocomplete.opened.emit();
891 }
892 }
893 return _this.panelClosingActions;
894 }),
895 // when the first closing event occurs...
896 operators.take(1))
897 // set the value, close the panel, and complete.
898 .subscribe(function (event) { return _this._setValueAndClose(event); });
899 };
900 /** Destroys the autocomplete suggestion panel. */
901 _MatAutocompleteTriggerBase.prototype._destroyPanel = function () {
902 if (this._overlayRef) {
903 this.closePanel();
904 this._overlayRef.dispose();
905 this._overlayRef = null;
906 }
907 };
908 _MatAutocompleteTriggerBase.prototype._setTriggerValue = function (value) {
909 var toDisplay = this.autocomplete && this.autocomplete.displayWith ?
910 this.autocomplete.displayWith(value) :
911 value;
912 // Simply falling back to an empty string if the display value is falsy does not work properly.
913 // The display value can also be the number zero and shouldn't fall back to an empty string.
914 var inputValue = toDisplay != null ? toDisplay : '';
915 // If it's used within a `MatFormField`, we should set it through the property so it can go
916 // through change detection.
917 if (this._formField) {
918 this._formField._control.value = inputValue;
919 }
920 else {
921 this._element.nativeElement.value = inputValue;
922 }
923 this._previousValue = inputValue;
924 };
925 /**
926 * This method closes the panel, and if a value is specified, also sets the associated
927 * control to that value. It will also mark the control as dirty if this interaction
928 * stemmed from the user.
929 */
930 _MatAutocompleteTriggerBase.prototype._setValueAndClose = function (event) {
931 if (event && event.source) {
932 this._clearPreviousSelectedOption(event.source);
933 this._setTriggerValue(event.source.value);
934 this._onChange(event.source.value);
935 this._element.nativeElement.focus();
936 this.autocomplete._emitSelectEvent(event.source);
937 }
938 this.closePanel();
939 };
940 /**
941 * Clear any previous selected option and emit a selection change event for this option
942 */
943 _MatAutocompleteTriggerBase.prototype._clearPreviousSelectedOption = function (skip) {
944 this.autocomplete.options.forEach(function (option) {
945 if (option !== skip && option.selected) {
946 option.deselect();
947 }
948 });
949 };
950 _MatAutocompleteTriggerBase.prototype._attachOverlay = function () {
951 var _this = this;
952 var _a;
953 if (!this.autocomplete && (typeof ngDevMode === 'undefined' || ngDevMode)) {
954 throw getMatAutocompleteMissingPanelError();
955 }
956 var overlayRef = this._overlayRef;
957 if (!overlayRef) {
958 this._portal = new portal.TemplatePortal(this.autocomplete.template, this._viewContainerRef, { id: (_a = this._formField) === null || _a === void 0 ? void 0 : _a.getLabelId() });
959 overlayRef = this._overlay.create(this._getOverlayConfig());
960 this._overlayRef = overlayRef;
961 // Use the `keydownEvents` in order to take advantage of
962 // the overlay event targeting provided by the CDK overlay.
963 overlayRef.keydownEvents().subscribe(function (event) {
964 // Close when pressing ESCAPE or ALT + UP_ARROW, based on the a11y guidelines.
965 // See: https://www.w3.org/TR/wai-aria-practices-1.1/#textbox-keyboard-interaction
966 if ((event.keyCode === keycodes.ESCAPE && !keycodes.hasModifierKey(event)) ||
967 (event.keyCode === keycodes.UP_ARROW && keycodes.hasModifierKey(event, 'altKey'))) {
968 _this._closeKeyEventStream.next();
969 _this._resetActiveItem();
970 // We need to stop propagation, otherwise the event will eventually
971 // reach the input itself and cause the overlay to be reopened.
972 event.stopPropagation();
973 event.preventDefault();
974 }
975 });
976 this._viewportSubscription = this._viewportRuler.change().subscribe(function () {
977 if (_this.panelOpen && overlayRef) {
978 overlayRef.updateSize({ width: _this._getPanelWidth() });
979 }
980 });
981 }
982 else {
983 // Update the trigger, panel width and direction, in case anything has changed.
984 this._positionStrategy.setOrigin(this._getConnectedElement());
985 overlayRef.updateSize({ width: this._getPanelWidth() });
986 }
987 if (overlayRef && !overlayRef.hasAttached()) {
988 overlayRef.attach(this._portal);
989 this._closingActionsSubscription = this._subscribeToClosingActions();
990 }
991 var wasOpen = this.panelOpen;
992 this.autocomplete._setVisibility();
993 this.autocomplete._isOpen = this._overlayAttached = true;
994 // We need to do an extra `panelOpen` check in here, because the
995 // autocomplete won't be shown if there are no options.
996 if (this.panelOpen && wasOpen !== this.panelOpen) {
997 this.autocomplete.opened.emit();
998 }
999 };
1000 _MatAutocompleteTriggerBase.prototype._getOverlayConfig = function () {
1001 var _a;
1002 return new overlay.OverlayConfig({
1003 positionStrategy: this._getOverlayPosition(),
1004 scrollStrategy: this._scrollStrategy(),
1005 width: this._getPanelWidth(),
1006 direction: this._dir,
1007 panelClass: (_a = this._defaults) === null || _a === void 0 ? void 0 : _a.overlayPanelClass,
1008 });
1009 };
1010 _MatAutocompleteTriggerBase.prototype._getOverlayPosition = function () {
1011 var strategy = this._overlay.position()
1012 .flexibleConnectedTo(this._getConnectedElement())
1013 .withFlexibleDimensions(false)
1014 .withPush(false);
1015 this._setStrategyPositions(strategy);
1016 this._positionStrategy = strategy;
1017 return strategy;
1018 };
1019 /** Sets the positions on a position strategy based on the directive's input state. */
1020 _MatAutocompleteTriggerBase.prototype._setStrategyPositions = function (positionStrategy) {
1021 // Note that we provide horizontal fallback positions, even though by default the dropdown
1022 // width matches the input, because consumers can override the width. See #18854.
1023 var belowPositions = [
1024 { originX: 'start', originY: 'bottom', overlayX: 'start', overlayY: 'top' },
1025 { originX: 'end', originY: 'bottom', overlayX: 'end', overlayY: 'top' }
1026 ];
1027 // The overlay edge connected to the trigger should have squared corners, while
1028 // the opposite end has rounded corners. We apply a CSS class to swap the
1029 // border-radius based on the overlay position.
1030 var panelClass = this._aboveClass;
1031 var abovePositions = [
1032 { originX: 'start', originY: 'top', overlayX: 'start', overlayY: 'bottom', panelClass: panelClass },
1033 { originX: 'end', originY: 'top', overlayX: 'end', overlayY: 'bottom', panelClass: panelClass }
1034 ];
1035 var positions;
1036 if (this.position === 'above') {
1037 positions = abovePositions;
1038 }
1039 else if (this.position === 'below') {
1040 positions = belowPositions;
1041 }
1042 else {
1043 positions = __spreadArray(__spreadArray([], __read(belowPositions)), __read(abovePositions));
1044 }
1045 positionStrategy.withPositions(positions);
1046 };
1047 _MatAutocompleteTriggerBase.prototype._getConnectedElement = function () {
1048 if (this.connectedTo) {
1049 return this.connectedTo.elementRef;
1050 }
1051 return this._formField ? this._formField.getConnectedOverlayOrigin() : this._element;
1052 };
1053 _MatAutocompleteTriggerBase.prototype._getPanelWidth = function () {
1054 return this.autocomplete.panelWidth || this._getHostWidth();
1055 };
1056 /** Returns the width of the input element, so the panel width can match it. */
1057 _MatAutocompleteTriggerBase.prototype._getHostWidth = function () {
1058 return this._getConnectedElement().nativeElement.getBoundingClientRect().width;
1059 };
1060 /**
1061 * Resets the active item to -1 so arrow events will activate the
1062 * correct options, or to 0 if the consumer opted into it.
1063 */
1064 _MatAutocompleteTriggerBase.prototype._resetActiveItem = function () {
1065 var autocomplete = this.autocomplete;
1066 if (autocomplete.autoActiveFirstOption) {
1067 // Note that we go through `setFirstItemActive`, rather than `setActiveItem(0)`, because
1068 // the former will find the next enabled option, if the first one is disabled.
1069 autocomplete._keyManager.setFirstItemActive();
1070 }
1071 else {
1072 autocomplete._keyManager.setActiveItem(-1);
1073 }
1074 };
1075 /** Determines whether the panel can be opened. */
1076 _MatAutocompleteTriggerBase.prototype._canOpen = function () {
1077 var element = this._element.nativeElement;
1078 return !element.readOnly && !element.disabled && !this._autocompleteDisabled;
1079 };
1080 /** Use defaultView of injected document if available or fallback to global window reference */
1081 _MatAutocompleteTriggerBase.prototype._getWindow = function () {
1082 var _a;
1083 return ((_a = this._document) === null || _a === void 0 ? void 0 : _a.defaultView) || window;
1084 };
1085 /** Scrolls to a particular option in the list. */
1086 _MatAutocompleteTriggerBase.prototype._scrollToOption = function (index) {
1087 // Given that we are not actually focusing active options, we must manually adjust scroll
1088 // to reveal options below the fold. First, we find the offset of the option from the top
1089 // of the panel. If that offset is below the fold, the new scrollTop will be the offset -
1090 // the panel height + the option height, so the active option will be just visible at the
1091 // bottom of the panel. If that offset is above the top of the visible panel, the new scrollTop
1092 // will become the offset. If that offset is visible within the panel already, the scrollTop is
1093 // not adjusted.
1094 var autocomplete = this.autocomplete;
1095 var labelCount = core._countGroupLabelsBeforeOption(index, autocomplete.options, autocomplete.optionGroups);
1096 if (index === 0 && labelCount === 1) {
1097 // If we've got one group label before the option and we're at the top option,
1098 // scroll the list to the top. This is better UX than scrolling the list to the
1099 // top of the option, because it allows the user to read the top group's label.
1100 autocomplete._setScrollTop(0);
1101 }
1102 else if (autocomplete.panel) {
1103 var option = autocomplete.options.toArray()[index];
1104 if (option) {
1105 var element = option._getHostElement();
1106 var newScrollPosition = core._getOptionScrollPosition(element.offsetTop, element.offsetHeight, autocomplete._getScrollTop(), autocomplete.panel.nativeElement.offsetHeight);
1107 autocomplete._setScrollTop(newScrollPosition);
1108 }
1109 }
1110 };
1111 return _MatAutocompleteTriggerBase;
1112 }());
1113 _MatAutocompleteTriggerBase.decorators = [
1114 { type: core$1.Directive }
1115 ];
1116 _MatAutocompleteTriggerBase.ctorParameters = function () { return [
1117 { type: core$1.ElementRef },
1118 { type: overlay.Overlay },
1119 { type: core$1.ViewContainerRef },
1120 { type: core$1.NgZone },
1121 { type: core$1.ChangeDetectorRef },
1122 { type: undefined, decorators: [{ type: core$1.Inject, args: [MAT_AUTOCOMPLETE_SCROLL_STRATEGY,] }] },
1123 { type: bidi.Directionality, decorators: [{ type: core$1.Optional }] },
1124 { type: formField.MatFormField, decorators: [{ type: core$1.Optional }, { type: core$1.Inject, args: [formField.MAT_FORM_FIELD,] }, { type: core$1.Host }] },
1125 { type: undefined, decorators: [{ type: core$1.Optional }, { type: core$1.Inject, args: [common.DOCUMENT,] }] },
1126 { type: scrolling.ViewportRuler },
1127 { type: undefined, decorators: [{ type: core$1.Optional }, { type: core$1.Inject, args: [MAT_AUTOCOMPLETE_DEFAULT_OPTIONS,] }] }
1128 ]; };
1129 _MatAutocompleteTriggerBase.propDecorators = {
1130 autocomplete: [{ type: core$1.Input, args: ['matAutocomplete',] }],
1131 position: [{ type: core$1.Input, args: ['matAutocompletePosition',] }],
1132 connectedTo: [{ type: core$1.Input, args: ['matAutocompleteConnectedTo',] }],
1133 autocompleteAttribute: [{ type: core$1.Input, args: ['autocomplete',] }],
1134 autocompleteDisabled: [{ type: core$1.Input, args: ['matAutocompleteDisabled',] }]
1135 };
1136 var MatAutocompleteTrigger = /** @class */ (function (_super) {
1137 __extends(MatAutocompleteTrigger, _super);
1138 function MatAutocompleteTrigger() {
1139 var _this = _super.apply(this, __spreadArray([], __read(arguments))) || this;
1140 _this._aboveClass = 'mat-autocomplete-panel-above';
1141 return _this;
1142 }
1143 return MatAutocompleteTrigger;
1144 }(_MatAutocompleteTriggerBase));
1145 MatAutocompleteTrigger.decorators = [
1146 { type: core$1.Directive, args: [{
1147 selector: "input[matAutocomplete], textarea[matAutocomplete]",
1148 host: {
1149 'class': 'mat-autocomplete-trigger',
1150 '[attr.autocomplete]': 'autocompleteAttribute',
1151 '[attr.role]': 'autocompleteDisabled ? null : "combobox"',
1152 '[attr.aria-autocomplete]': 'autocompleteDisabled ? null : "list"',
1153 '[attr.aria-activedescendant]': '(panelOpen && activeOption) ? activeOption.id : null',
1154 '[attr.aria-expanded]': 'autocompleteDisabled ? null : panelOpen.toString()',
1155 '[attr.aria-owns]': '(autocompleteDisabled || !panelOpen) ? null : autocomplete?.id',
1156 '[attr.aria-haspopup]': '!autocompleteDisabled',
1157 // Note: we use `focusin`, as opposed to `focus`, in order to open the panel
1158 // a little earlier. This avoids issues where IE delays the focusing of the input.
1159 '(focusin)': '_handleFocus()',
1160 '(blur)': '_onTouched()',
1161 '(input)': '_handleInput($event)',
1162 '(keydown)': '_handleKeydown($event)',
1163 },
1164 exportAs: 'matAutocompleteTrigger',
1165 providers: [MAT_AUTOCOMPLETE_VALUE_ACCESSOR]
1166 },] }
1167 ];
1168
1169 /** Base class containing all of the functionality for `MatAutocompleteOrigin`. */
1170 var _MatAutocompleteOriginBase = /** @class */ (function () {
1171 function _MatAutocompleteOriginBase(
1172 /** Reference to the element on which the directive is applied. */
1173 elementRef) {
1174 this.elementRef = elementRef;
1175 }
1176 return _MatAutocompleteOriginBase;
1177 }());
1178 _MatAutocompleteOriginBase.decorators = [
1179 { type: core$1.Directive }
1180 ];
1181 _MatAutocompleteOriginBase.ctorParameters = function () { return [
1182 { type: core$1.ElementRef }
1183 ]; };
1184 /**
1185 * Directive applied to an element to make it usable
1186 * as a connection point for an autocomplete panel.
1187 */
1188 var MatAutocompleteOrigin = /** @class */ (function (_super) {
1189 __extends(MatAutocompleteOrigin, _super);
1190 function MatAutocompleteOrigin() {
1191 return _super !== null && _super.apply(this, arguments) || this;
1192 }
1193 return MatAutocompleteOrigin;
1194 }(_MatAutocompleteOriginBase));
1195 MatAutocompleteOrigin.decorators = [
1196 { type: core$1.Directive, args: [{
1197 selector: '[matAutocompleteOrigin]',
1198 exportAs: 'matAutocompleteOrigin',
1199 },] }
1200 ];
1201
1202 /**
1203 * @license
1204 * Copyright Google LLC All Rights Reserved.
1205 *
1206 * Use of this source code is governed by an MIT-style license that can be
1207 * found in the LICENSE file at https://angular.io/license
1208 */
1209 var MatAutocompleteModule = /** @class */ (function () {
1210 function MatAutocompleteModule() {
1211 }
1212 return MatAutocompleteModule;
1213 }());
1214 MatAutocompleteModule.decorators = [
1215 { type: core$1.NgModule, args: [{
1216 imports: [
1217 overlay.OverlayModule,
1218 core.MatOptionModule,
1219 core.MatCommonModule,
1220 common.CommonModule
1221 ],
1222 exports: [
1223 MatAutocomplete,
1224 MatAutocompleteTrigger,
1225 MatAutocompleteOrigin,
1226 scrolling.CdkScrollableModule,
1227 core.MatOptionModule,
1228 core.MatCommonModule,
1229 ],
1230 declarations: [MatAutocomplete, MatAutocompleteTrigger, MatAutocompleteOrigin],
1231 providers: [MAT_AUTOCOMPLETE_SCROLL_STRATEGY_FACTORY_PROVIDER],
1232 },] }
1233 ];
1234
1235 /**
1236 * @license
1237 * Copyright Google LLC All Rights Reserved.
1238 *
1239 * Use of this source code is governed by an MIT-style license that can be
1240 * found in the LICENSE file at https://angular.io/license
1241 */
1242
1243 /**
1244 * Generated bundle index. Do not edit.
1245 */
1246
1247 exports.MAT_AUTOCOMPLETE_DEFAULT_OPTIONS = MAT_AUTOCOMPLETE_DEFAULT_OPTIONS;
1248 exports.MAT_AUTOCOMPLETE_DEFAULT_OPTIONS_FACTORY = MAT_AUTOCOMPLETE_DEFAULT_OPTIONS_FACTORY;
1249 exports.MAT_AUTOCOMPLETE_SCROLL_STRATEGY = MAT_AUTOCOMPLETE_SCROLL_STRATEGY;
1250 exports.MAT_AUTOCOMPLETE_SCROLL_STRATEGY_FACTORY = MAT_AUTOCOMPLETE_SCROLL_STRATEGY_FACTORY;
1251 exports.MAT_AUTOCOMPLETE_SCROLL_STRATEGY_FACTORY_PROVIDER = MAT_AUTOCOMPLETE_SCROLL_STRATEGY_FACTORY_PROVIDER;
1252 exports.MAT_AUTOCOMPLETE_VALUE_ACCESSOR = MAT_AUTOCOMPLETE_VALUE_ACCESSOR;
1253 exports.MatAutocomplete = MatAutocomplete;
1254 exports.MatAutocompleteModule = MatAutocompleteModule;
1255 exports.MatAutocompleteOrigin = MatAutocompleteOrigin;
1256 exports.MatAutocompleteSelectedEvent = MatAutocompleteSelectedEvent;
1257 exports.MatAutocompleteTrigger = MatAutocompleteTrigger;
1258 exports._MatAutocompleteBase = _MatAutocompleteBase;
1259 exports._MatAutocompleteOriginBase = _MatAutocompleteOriginBase;
1260 exports._MatAutocompleteTriggerBase = _MatAutocompleteTriggerBase;
1261 exports.getMatAutocompleteMissingPanelError = getMatAutocompleteMissingPanelError;
1262
1263 Object.defineProperty(exports, '__esModule', { value: true });
1264
1265})));
1266//# sourceMappingURL=material-autocomplete.umd.js.map
Note: See TracBrowser for help on using the repository browser.