1 | import * as i8 from '@angular/cdk/overlay';
|
2 | import { Overlay, CdkConnectedOverlay, OverlayModule } from '@angular/cdk/overlay';
|
3 | import * as i7 from '@angular/common';
|
4 | import { CommonModule } from '@angular/common';
|
5 | import * as i0 from '@angular/core';
|
6 | import { InjectionToken, Directive, EventEmitter, Optional, Inject, Self, Attribute, Input, ViewChild, Output, Component, ViewEncapsulation, ChangeDetectionStrategy, ContentChildren, ContentChild, NgModule } from '@angular/core';
|
7 | import * as i2 from '@angular/material/core';
|
8 | import { mixinDisableRipple, mixinTabIndex, mixinDisabled, mixinErrorState, _countGroupLabelsBeforeOption, _getOptionScrollPosition, MAT_OPTION_PARENT_COMPONENT, MatOption, MAT_OPTGROUP, MatOptionModule, MatCommonModule } from '@angular/material/core';
|
9 | import * as i6 from '@angular/material/form-field';
|
10 | import { MAT_FORM_FIELD, MatFormFieldControl, MatFormFieldModule } from '@angular/material/form-field';
|
11 | import * as i1 from '@angular/cdk/scrolling';
|
12 | import { CdkScrollableModule } from '@angular/cdk/scrolling';
|
13 | import * as i5 from '@angular/cdk/a11y';
|
14 | import { ActiveDescendantKeyManager } from '@angular/cdk/a11y';
|
15 | import * as i3 from '@angular/cdk/bidi';
|
16 | import { coerceBooleanProperty, coerceNumberProperty } from '@angular/cdk/coercion';
|
17 | import { SelectionModel } from '@angular/cdk/collections';
|
18 | import { DOWN_ARROW, UP_ARROW, LEFT_ARROW, RIGHT_ARROW, ENTER, SPACE, hasModifierKey, A } from '@angular/cdk/keycodes';
|
19 | import * as i4 from '@angular/forms';
|
20 | import { Validators } from '@angular/forms';
|
21 | import { Subject, defer, merge } from 'rxjs';
|
22 | import { startWith, switchMap, take, filter, map, distinctUntilChanged, takeUntil } from 'rxjs/operators';
|
23 | import { trigger, transition, query, animateChild, state, style, animate } from '@angular/animations';
|
24 |
|
25 |
|
26 |
|
27 |
|
28 |
|
29 |
|
30 |
|
31 |
|
32 |
|
33 |
|
34 |
|
35 |
|
36 |
|
37 |
|
38 |
|
39 | const matSelectAnimations = {
|
40 | |
41 |
|
42 |
|
43 |
|
44 |
|
45 | transformPanelWrap: trigger('transformPanelWrap', [
|
46 | transition('* => void', query('@transformPanel', [animateChild()], { optional: true })),
|
47 | ]),
|
48 | |
49 |
|
50 |
|
51 |
|
52 |
|
53 |
|
54 |
|
55 |
|
56 |
|
57 | transformPanel: trigger('transformPanel', [
|
58 | state('void', style({
|
59 | transform: 'scaleY(0.8)',
|
60 | minWidth: '100%',
|
61 | opacity: 0,
|
62 | })),
|
63 | state('showing', style({
|
64 | opacity: 1,
|
65 | minWidth: 'calc(100% + 32px)',
|
66 | transform: 'scaleY(1)',
|
67 | })),
|
68 | state('showing-multiple', style({
|
69 | opacity: 1,
|
70 | minWidth: 'calc(100% + 64px)',
|
71 | transform: 'scaleY(1)',
|
72 | })),
|
73 | transition('void => *', animate('120ms cubic-bezier(0, 0, 0.2, 1)')),
|
74 | transition('* => void', animate('100ms 25ms linear', style({ opacity: 0 }))),
|
75 | ]),
|
76 | };
|
77 |
|
78 |
|
79 |
|
80 |
|
81 |
|
82 |
|
83 |
|
84 |
|
85 |
|
86 |
|
87 |
|
88 |
|
89 |
|
90 | function getMatSelectDynamicMultipleError() {
|
91 | return Error('Cannot change `multiple` mode of select after initialization.');
|
92 | }
|
93 |
|
94 |
|
95 |
|
96 |
|
97 |
|
98 |
|
99 | function getMatSelectNonArrayValueError() {
|
100 | return Error('Value must be an array in multiple-selection mode.');
|
101 | }
|
102 |
|
103 |
|
104 |
|
105 |
|
106 |
|
107 | function getMatSelectNonFunctionValueError() {
|
108 | return Error('`compareWith` must be a function.');
|
109 | }
|
110 |
|
111 |
|
112 |
|
113 |
|
114 |
|
115 |
|
116 |
|
117 |
|
118 | let nextUniqueId = 0;
|
119 |
|
120 |
|
121 |
|
122 |
|
123 |
|
124 |
|
125 | const SELECT_PANEL_MAX_HEIGHT = 256;
|
126 |
|
127 | const SELECT_PANEL_PADDING_X = 16;
|
128 |
|
129 | const SELECT_PANEL_INDENT_PADDING_X = SELECT_PANEL_PADDING_X * 2;
|
130 |
|
131 | const SELECT_ITEM_HEIGHT_EM = 3;
|
132 |
|
133 |
|
134 |
|
135 |
|
136 |
|
137 |
|
138 |
|
139 |
|
140 |
|
141 |
|
142 | const SELECT_MULTIPLE_PANEL_PADDING_X = SELECT_PANEL_PADDING_X * 1.5 + 16;
|
143 |
|
144 |
|
145 |
|
146 |
|
147 | const SELECT_PANEL_VIEWPORT_PADDING = 8;
|
148 |
|
149 | const MAT_SELECT_SCROLL_STRATEGY = new InjectionToken('mat-select-scroll-strategy');
|
150 |
|
151 | function MAT_SELECT_SCROLL_STRATEGY_PROVIDER_FACTORY(overlay) {
|
152 | return () => overlay.scrollStrategies.reposition();
|
153 | }
|
154 |
|
155 | const MAT_SELECT_CONFIG = new InjectionToken('MAT_SELECT_CONFIG');
|
156 |
|
157 | const MAT_SELECT_SCROLL_STRATEGY_PROVIDER = {
|
158 | provide: MAT_SELECT_SCROLL_STRATEGY,
|
159 | deps: [Overlay],
|
160 | useFactory: MAT_SELECT_SCROLL_STRATEGY_PROVIDER_FACTORY,
|
161 | };
|
162 |
|
163 | class MatSelectChange {
|
164 | constructor(
|
165 | /** Reference to the select that emitted the change event. */
|
166 | source,
|
167 | /** Current value of the select that emitted the event. */
|
168 | value) {
|
169 | this.source = source;
|
170 | this.value = value;
|
171 | }
|
172 | }
|
173 |
|
174 |
|
175 | const _MatSelectMixinBase = mixinDisableRipple(mixinTabIndex(mixinDisabled(mixinErrorState(class {
|
176 | constructor(_elementRef, _defaultErrorStateMatcher, _parentForm, _parentFormGroup,
|
177 | /**
|
178 | * Form control bound to the component.
|
179 | * Implemented as part of `MatFormFieldControl`.
|
180 | * @docs-private
|
181 | */
|
182 | ngControl) {
|
183 | this._elementRef = _elementRef;
|
184 | this._defaultErrorStateMatcher = _defaultErrorStateMatcher;
|
185 | this._parentForm = _parentForm;
|
186 | this._parentFormGroup = _parentFormGroup;
|
187 | this.ngControl = ngControl;
|
188 | |
189 |
|
190 |
|
191 |
|
192 |
|
193 | this.stateChanges = new Subject();
|
194 | }
|
195 | }))));
|
196 |
|
197 |
|
198 |
|
199 |
|
200 |
|
201 | const MAT_SELECT_TRIGGER = new InjectionToken('MatSelectTrigger');
|
202 |
|
203 |
|
204 |
|
205 | class MatSelectTrigger {
|
206 | }
|
207 | MatSelectTrigger.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.0.1", ngImport: i0, type: MatSelectTrigger, deps: [], target: i0.ɵɵFactoryTarget.Directive });
|
208 | MatSelectTrigger.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "14.0.1", type: MatSelectTrigger, selector: "mat-select-trigger", providers: [{ provide: MAT_SELECT_TRIGGER, useExisting: MatSelectTrigger }], ngImport: i0 });
|
209 | i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.0.1", ngImport: i0, type: MatSelectTrigger, decorators: [{
|
210 | type: Directive,
|
211 | args: [{
|
212 | selector: 'mat-select-trigger',
|
213 | providers: [{ provide: MAT_SELECT_TRIGGER, useExisting: MatSelectTrigger }],
|
214 | }]
|
215 | }] });
|
216 |
|
217 | class _MatSelectBase extends _MatSelectMixinBase {
|
218 | constructor(_viewportRuler, _changeDetectorRef, _ngZone, _defaultErrorStateMatcher, elementRef, _dir, _parentForm, _parentFormGroup, _parentFormField, ngControl, tabIndex, scrollStrategyFactory, _liveAnnouncer, _defaultOptions) {
|
219 | super(elementRef, _defaultErrorStateMatcher, _parentForm, _parentFormGroup, ngControl);
|
220 | this._viewportRuler = _viewportRuler;
|
221 | this._changeDetectorRef = _changeDetectorRef;
|
222 | this._ngZone = _ngZone;
|
223 | this._dir = _dir;
|
224 | this._parentFormField = _parentFormField;
|
225 | this._liveAnnouncer = _liveAnnouncer;
|
226 | this._defaultOptions = _defaultOptions;
|
227 |
|
228 | this._panelOpen = false;
|
229 |
|
230 | this._compareWith = (o1, o2) => o1 === o2;
|
231 |
|
232 | this._uid = `mat-select-${nextUniqueId++}`;
|
233 |
|
234 | this._triggerAriaLabelledBy = null;
|
235 |
|
236 | this._destroy = new Subject();
|
237 |
|
238 | this._onChange = () => { };
|
239 |
|
240 | this._onTouched = () => { };
|
241 |
|
242 | this._valueId = `mat-select-value-${nextUniqueId++}`;
|
243 |
|
244 | this._panelDoneAnimatingStream = new Subject();
|
245 | this._overlayPanelClass = this._defaultOptions?.overlayPanelClass || '';
|
246 | this._focused = false;
|
247 |
|
248 | this.controlType = 'mat-select';
|
249 | this._multiple = false;
|
250 | this._disableOptionCentering = this._defaultOptions?.disableOptionCentering ?? false;
|
251 |
|
252 | this.ariaLabel = '';
|
253 |
|
254 | this.optionSelectionChanges = defer(() => {
|
255 | const options = this.options;
|
256 | if (options) {
|
257 | return options.changes.pipe(startWith(options), switchMap(() => merge(...options.map(option => option.onSelectionChange))));
|
258 | }
|
259 | return this._ngZone.onStable.pipe(take(1), switchMap(() => this.optionSelectionChanges));
|
260 | });
|
261 |
|
262 | this.openedChange = new EventEmitter();
|
263 |
|
264 | this._openedStream = this.openedChange.pipe(filter(o => o), map(() => { }));
|
265 |
|
266 | this._closedStream = this.openedChange.pipe(filter(o => !o), map(() => { }));
|
267 |
|
268 | this.selectionChange = new EventEmitter();
|
269 | |
270 |
|
271 |
|
272 |
|
273 |
|
274 | this.valueChange = new EventEmitter();
|
275 | if (this.ngControl) {
|
276 |
|
277 |
|
278 | this.ngControl.valueAccessor = this;
|
279 | }
|
280 |
|
281 |
|
282 | if (_defaultOptions?.typeaheadDebounceInterval != null) {
|
283 | this._typeaheadDebounceInterval = _defaultOptions.typeaheadDebounceInterval;
|
284 | }
|
285 | this._scrollStrategyFactory = scrollStrategyFactory;
|
286 | this._scrollStrategy = this._scrollStrategyFactory();
|
287 | this.tabIndex = parseInt(tabIndex) || 0;
|
288 |
|
289 | this.id = this.id;
|
290 | }
|
291 |
|
292 | get focused() {
|
293 | return this._focused || this._panelOpen;
|
294 | }
|
295 |
|
296 | get placeholder() {
|
297 | return this._placeholder;
|
298 | }
|
299 | set placeholder(value) {
|
300 | this._placeholder = value;
|
301 | this.stateChanges.next();
|
302 | }
|
303 |
|
304 | get required() {
|
305 | return this._required ?? this.ngControl?.control?.hasValidator(Validators.required) ?? false;
|
306 | }
|
307 | set required(value) {
|
308 | this._required = coerceBooleanProperty(value);
|
309 | this.stateChanges.next();
|
310 | }
|
311 |
|
312 | get multiple() {
|
313 | return this._multiple;
|
314 | }
|
315 | set multiple(value) {
|
316 | if (this._selectionModel && (typeof ngDevMode === 'undefined' || ngDevMode)) {
|
317 | throw getMatSelectDynamicMultipleError();
|
318 | }
|
319 | this._multiple = coerceBooleanProperty(value);
|
320 | }
|
321 |
|
322 | get disableOptionCentering() {
|
323 | return this._disableOptionCentering;
|
324 | }
|
325 | set disableOptionCentering(value) {
|
326 | this._disableOptionCentering = coerceBooleanProperty(value);
|
327 | }
|
328 | |
329 |
|
330 |
|
331 |
|
332 |
|
333 | get compareWith() {
|
334 | return this._compareWith;
|
335 | }
|
336 | set compareWith(fn) {
|
337 | if (typeof fn !== 'function' && (typeof ngDevMode === 'undefined' || ngDevMode)) {
|
338 | throw getMatSelectNonFunctionValueError();
|
339 | }
|
340 | this._compareWith = fn;
|
341 | if (this._selectionModel) {
|
342 |
|
343 | this._initializeSelection();
|
344 | }
|
345 | }
|
346 |
|
347 | get value() {
|
348 | return this._value;
|
349 | }
|
350 | set value(newValue) {
|
351 | const hasAssigned = this._assignValue(newValue);
|
352 | if (hasAssigned) {
|
353 | this._onChange(newValue);
|
354 | }
|
355 | }
|
356 |
|
357 | get typeaheadDebounceInterval() {
|
358 | return this._typeaheadDebounceInterval;
|
359 | }
|
360 | set typeaheadDebounceInterval(value) {
|
361 | this._typeaheadDebounceInterval = coerceNumberProperty(value);
|
362 | }
|
363 |
|
364 | get id() {
|
365 | return this._id;
|
366 | }
|
367 | set id(value) {
|
368 | this._id = value || this._uid;
|
369 | this.stateChanges.next();
|
370 | }
|
371 | ngOnInit() {
|
372 | this._selectionModel = new SelectionModel(this.multiple);
|
373 | this.stateChanges.next();
|
374 |
|
375 |
|
376 |
|
377 | this._panelDoneAnimatingStream
|
378 | .pipe(distinctUntilChanged(), takeUntil(this._destroy))
|
379 | .subscribe(() => this._panelDoneAnimating(this.panelOpen));
|
380 | }
|
381 | ngAfterContentInit() {
|
382 | this._initKeyManager();
|
383 | this._selectionModel.changed.pipe(takeUntil(this._destroy)).subscribe(event => {
|
384 | event.added.forEach(option => option.select());
|
385 | event.removed.forEach(option => option.deselect());
|
386 | });
|
387 | this.options.changes.pipe(startWith(null), takeUntil(this._destroy)).subscribe(() => {
|
388 | this._resetOptions();
|
389 | this._initializeSelection();
|
390 | });
|
391 | }
|
392 | ngDoCheck() {
|
393 | const newAriaLabelledby = this._getTriggerAriaLabelledby();
|
394 | const ngControl = this.ngControl;
|
395 |
|
396 |
|
397 |
|
398 | if (newAriaLabelledby !== this._triggerAriaLabelledBy) {
|
399 | const element = this._elementRef.nativeElement;
|
400 | this._triggerAriaLabelledBy = newAriaLabelledby;
|
401 | if (newAriaLabelledby) {
|
402 | element.setAttribute('aria-labelledby', newAriaLabelledby);
|
403 | }
|
404 | else {
|
405 | element.removeAttribute('aria-labelledby');
|
406 | }
|
407 | }
|
408 | if (ngControl) {
|
409 |
|
410 | if (this._previousControl !== ngControl.control) {
|
411 | if (this._previousControl !== undefined &&
|
412 | ngControl.disabled !== null &&
|
413 | ngControl.disabled !== this.disabled) {
|
414 | this.disabled = ngControl.disabled;
|
415 | }
|
416 | this._previousControl = ngControl.control;
|
417 | }
|
418 | this.updateErrorState();
|
419 | }
|
420 | }
|
421 | ngOnChanges(changes) {
|
422 |
|
423 |
|
424 | if (changes['disabled'] || changes['userAriaDescribedBy']) {
|
425 | this.stateChanges.next();
|
426 | }
|
427 | if (changes['typeaheadDebounceInterval'] && this._keyManager) {
|
428 | this._keyManager.withTypeAhead(this._typeaheadDebounceInterval);
|
429 | }
|
430 | }
|
431 | ngOnDestroy() {
|
432 | this._destroy.next();
|
433 | this._destroy.complete();
|
434 | this.stateChanges.complete();
|
435 | }
|
436 |
|
437 | toggle() {
|
438 | this.panelOpen ? this.close() : this.open();
|
439 | }
|
440 |
|
441 | open() {
|
442 | if (this._canOpen()) {
|
443 | this._panelOpen = true;
|
444 | this._keyManager.withHorizontalOrientation(null);
|
445 | this._highlightCorrectOption();
|
446 | this._changeDetectorRef.markForCheck();
|
447 | }
|
448 | }
|
449 |
|
450 | close() {
|
451 | if (this._panelOpen) {
|
452 | this._panelOpen = false;
|
453 | this._keyManager.withHorizontalOrientation(this._isRtl() ? 'rtl' : 'ltr');
|
454 | this._changeDetectorRef.markForCheck();
|
455 | this._onTouched();
|
456 | }
|
457 | }
|
458 | |
459 |
|
460 |
|
461 |
|
462 |
|
463 |
|
464 | writeValue(value) {
|
465 | this._assignValue(value);
|
466 | }
|
467 | |
468 |
|
469 |
|
470 |
|
471 |
|
472 |
|
473 |
|
474 | registerOnChange(fn) {
|
475 | this._onChange = fn;
|
476 | }
|
477 | |
478 |
|
479 |
|
480 |
|
481 |
|
482 |
|
483 |
|
484 | registerOnTouched(fn) {
|
485 | this._onTouched = fn;
|
486 | }
|
487 | |
488 |
|
489 |
|
490 |
|
491 |
|
492 |
|
493 | setDisabledState(isDisabled) {
|
494 | this.disabled = isDisabled;
|
495 | this._changeDetectorRef.markForCheck();
|
496 | this.stateChanges.next();
|
497 | }
|
498 |
|
499 | get panelOpen() {
|
500 | return this._panelOpen;
|
501 | }
|
502 |
|
503 | get selected() {
|
504 | return this.multiple ? this._selectionModel?.selected || [] : this._selectionModel?.selected[0];
|
505 | }
|
506 |
|
507 | get triggerValue() {
|
508 | if (this.empty) {
|
509 | return '';
|
510 | }
|
511 | if (this._multiple) {
|
512 | const selectedOptions = this._selectionModel.selected.map(option => option.viewValue);
|
513 | if (this._isRtl()) {
|
514 | selectedOptions.reverse();
|
515 | }
|
516 |
|
517 | return selectedOptions.join(', ');
|
518 | }
|
519 | return this._selectionModel.selected[0].viewValue;
|
520 | }
|
521 |
|
522 | _isRtl() {
|
523 | return this._dir ? this._dir.value === 'rtl' : false;
|
524 | }
|
525 |
|
526 | _handleKeydown(event) {
|
527 | if (!this.disabled) {
|
528 | this.panelOpen ? this._handleOpenKeydown(event) : this._handleClosedKeydown(event);
|
529 | }
|
530 | }
|
531 |
|
532 | _handleClosedKeydown(event) {
|
533 | const keyCode = event.keyCode;
|
534 | const isArrowKey = keyCode === DOWN_ARROW ||
|
535 | keyCode === UP_ARROW ||
|
536 | keyCode === LEFT_ARROW ||
|
537 | keyCode === RIGHT_ARROW;
|
538 | const isOpenKey = keyCode === ENTER || keyCode === SPACE;
|
539 | const manager = this._keyManager;
|
540 |
|
541 | if ((!manager.isTyping() && isOpenKey && !hasModifierKey(event)) ||
|
542 | ((this.multiple || event.altKey) && isArrowKey)) {
|
543 | event.preventDefault();
|
544 | this.open();
|
545 | }
|
546 | else if (!this.multiple) {
|
547 | const previouslySelectedOption = this.selected;
|
548 | manager.onKeydown(event);
|
549 | const selectedOption = this.selected;
|
550 |
|
551 | if (selectedOption && previouslySelectedOption !== selectedOption) {
|
552 |
|
553 |
|
554 | this._liveAnnouncer.announce(selectedOption.viewValue, 10000);
|
555 | }
|
556 | }
|
557 | }
|
558 |
|
559 | _handleOpenKeydown(event) {
|
560 | const manager = this._keyManager;
|
561 | const keyCode = event.keyCode;
|
562 | const isArrowKey = keyCode === DOWN_ARROW || keyCode === UP_ARROW;
|
563 | const isTyping = manager.isTyping();
|
564 | if (isArrowKey && event.altKey) {
|
565 |
|
566 | event.preventDefault();
|
567 | this.close();
|
568 |
|
569 |
|
570 | }
|
571 | else if (!isTyping &&
|
572 | (keyCode === ENTER || keyCode === SPACE) &&
|
573 | manager.activeItem &&
|
574 | !hasModifierKey(event)) {
|
575 | event.preventDefault();
|
576 | manager.activeItem._selectViaInteraction();
|
577 | }
|
578 | else if (!isTyping && this._multiple && keyCode === A && event.ctrlKey) {
|
579 | event.preventDefault();
|
580 | const hasDeselectedOptions = this.options.some(opt => !opt.disabled && !opt.selected);
|
581 | this.options.forEach(option => {
|
582 | if (!option.disabled) {
|
583 | hasDeselectedOptions ? option.select() : option.deselect();
|
584 | }
|
585 | });
|
586 | }
|
587 | else {
|
588 | const previouslyFocusedIndex = manager.activeItemIndex;
|
589 | manager.onKeydown(event);
|
590 | if (this._multiple &&
|
591 | isArrowKey &&
|
592 | event.shiftKey &&
|
593 | manager.activeItem &&
|
594 | manager.activeItemIndex !== previouslyFocusedIndex) {
|
595 | manager.activeItem._selectViaInteraction();
|
596 | }
|
597 | }
|
598 | }
|
599 | _onFocus() {
|
600 | if (!this.disabled) {
|
601 | this._focused = true;
|
602 | this.stateChanges.next();
|
603 | }
|
604 | }
|
605 | |
606 |
|
607 |
|
608 |
|
609 | _onBlur() {
|
610 | this._focused = false;
|
611 | if (!this.disabled && !this.panelOpen) {
|
612 | this._onTouched();
|
613 | this._changeDetectorRef.markForCheck();
|
614 | this.stateChanges.next();
|
615 | }
|
616 | }
|
617 | |
618 |
|
619 |
|
620 | _onAttached() {
|
621 | this._overlayDir.positionChange.pipe(take(1)).subscribe(() => {
|
622 | this._changeDetectorRef.detectChanges();
|
623 | this._positioningSettled();
|
624 | });
|
625 | }
|
626 |
|
627 | _getPanelTheme() {
|
628 | return this._parentFormField ? `mat-${this._parentFormField.color}` : '';
|
629 | }
|
630 |
|
631 | get empty() {
|
632 | return !this._selectionModel || this._selectionModel.isEmpty();
|
633 | }
|
634 | _initializeSelection() {
|
635 |
|
636 |
|
637 | Promise.resolve().then(() => {
|
638 | if (this.ngControl) {
|
639 | this._value = this.ngControl.value;
|
640 | }
|
641 | this._setSelectionByValue(this._value);
|
642 | this.stateChanges.next();
|
643 | });
|
644 | }
|
645 | |
646 |
|
647 |
|
648 |
|
649 | _setSelectionByValue(value) {
|
650 | this._selectionModel.selected.forEach(option => option.setInactiveStyles());
|
651 | this._selectionModel.clear();
|
652 | if (this.multiple && value) {
|
653 | if (!Array.isArray(value) && (typeof ngDevMode === 'undefined' || ngDevMode)) {
|
654 | throw getMatSelectNonArrayValueError();
|
655 | }
|
656 | value.forEach((currentValue) => this._selectOptionByValue(currentValue));
|
657 | this._sortValues();
|
658 | }
|
659 | else {
|
660 | const correspondingOption = this._selectOptionByValue(value);
|
661 |
|
662 |
|
663 | if (correspondingOption) {
|
664 | this._keyManager.updateActiveItem(correspondingOption);
|
665 | }
|
666 | else if (!this.panelOpen) {
|
667 |
|
668 |
|
669 | this._keyManager.updateActiveItem(-1);
|
670 | }
|
671 | }
|
672 | this._changeDetectorRef.markForCheck();
|
673 | }
|
674 | |
675 |
|
676 |
|
677 |
|
678 | _selectOptionByValue(value) {
|
679 | const correspondingOption = this.options.find((option) => {
|
680 |
|
681 |
|
682 | if (this._selectionModel.isSelected(option)) {
|
683 | return false;
|
684 | }
|
685 | try {
|
686 |
|
687 | return option.value != null && this._compareWith(option.value, value);
|
688 | }
|
689 | catch (error) {
|
690 | if (typeof ngDevMode === 'undefined' || ngDevMode) {
|
691 |
|
692 | console.warn(error);
|
693 | }
|
694 | return false;
|
695 | }
|
696 | });
|
697 | if (correspondingOption) {
|
698 | this._selectionModel.select(correspondingOption);
|
699 | }
|
700 | return correspondingOption;
|
701 | }
|
702 |
|
703 | _assignValue(newValue) {
|
704 |
|
705 | if (newValue !== this._value || (this._multiple && Array.isArray(newValue))) {
|
706 | if (this.options) {
|
707 | this._setSelectionByValue(newValue);
|
708 | }
|
709 | this._value = newValue;
|
710 | return true;
|
711 | }
|
712 | return false;
|
713 | }
|
714 |
|
715 | _initKeyManager() {
|
716 | this._keyManager = new ActiveDescendantKeyManager(this.options)
|
717 | .withTypeAhead(this._typeaheadDebounceInterval)
|
718 | .withVerticalOrientation()
|
719 | .withHorizontalOrientation(this._isRtl() ? 'rtl' : 'ltr')
|
720 | .withHomeAndEnd()
|
721 | .withAllowedModifierKeys(['shiftKey']);
|
722 | this._keyManager.tabOut.pipe(takeUntil(this._destroy)).subscribe(() => {
|
723 | if (this.panelOpen) {
|
724 |
|
725 |
|
726 | if (!this.multiple && this._keyManager.activeItem) {
|
727 | this._keyManager.activeItem._selectViaInteraction();
|
728 | }
|
729 |
|
730 |
|
731 | this.focus();
|
732 | this.close();
|
733 | }
|
734 | });
|
735 | this._keyManager.change.pipe(takeUntil(this._destroy)).subscribe(() => {
|
736 | if (this._panelOpen && this.panel) {
|
737 | this._scrollOptionIntoView(this._keyManager.activeItemIndex || 0);
|
738 | }
|
739 | else if (!this._panelOpen && !this.multiple && this._keyManager.activeItem) {
|
740 | this._keyManager.activeItem._selectViaInteraction();
|
741 | }
|
742 | });
|
743 | }
|
744 |
|
745 | _resetOptions() {
|
746 | const changedOrDestroyed = merge(this.options.changes, this._destroy);
|
747 | this.optionSelectionChanges.pipe(takeUntil(changedOrDestroyed)).subscribe(event => {
|
748 | this._onSelect(event.source, event.isUserInput);
|
749 | if (event.isUserInput && !this.multiple && this._panelOpen) {
|
750 | this.close();
|
751 | this.focus();
|
752 | }
|
753 | });
|
754 |
|
755 |
|
756 | merge(...this.options.map(option => option._stateChanges))
|
757 | .pipe(takeUntil(changedOrDestroyed))
|
758 | .subscribe(() => {
|
759 | this._changeDetectorRef.markForCheck();
|
760 | this.stateChanges.next();
|
761 | });
|
762 | }
|
763 |
|
764 | _onSelect(option, isUserInput) {
|
765 | const wasSelected = this._selectionModel.isSelected(option);
|
766 | if (option.value == null && !this._multiple) {
|
767 | option.deselect();
|
768 | this._selectionModel.clear();
|
769 | if (this.value != null) {
|
770 | this._propagateChanges(option.value);
|
771 | }
|
772 | }
|
773 | else {
|
774 | if (wasSelected !== option.selected) {
|
775 | option.selected
|
776 | ? this._selectionModel.select(option)
|
777 | : this._selectionModel.deselect(option);
|
778 | }
|
779 | if (isUserInput) {
|
780 | this._keyManager.setActiveItem(option);
|
781 | }
|
782 | if (this.multiple) {
|
783 | this._sortValues();
|
784 | if (isUserInput) {
|
785 |
|
786 |
|
787 |
|
788 |
|
789 | this.focus();
|
790 | }
|
791 | }
|
792 | }
|
793 | if (wasSelected !== this._selectionModel.isSelected(option)) {
|
794 | this._propagateChanges();
|
795 | }
|
796 | this.stateChanges.next();
|
797 | }
|
798 |
|
799 | _sortValues() {
|
800 | if (this.multiple) {
|
801 | const options = this.options.toArray();
|
802 | this._selectionModel.sort((a, b) => {
|
803 | return this.sortComparator
|
804 | ? this.sortComparator(a, b, options)
|
805 | : options.indexOf(a) - options.indexOf(b);
|
806 | });
|
807 | this.stateChanges.next();
|
808 | }
|
809 | }
|
810 |
|
811 | _propagateChanges(fallbackValue) {
|
812 | let valueToEmit = null;
|
813 | if (this.multiple) {
|
814 | valueToEmit = this.selected.map(option => option.value);
|
815 | }
|
816 | else {
|
817 | valueToEmit = this.selected ? this.selected.value : fallbackValue;
|
818 | }
|
819 | this._value = valueToEmit;
|
820 | this.valueChange.emit(valueToEmit);
|
821 | this._onChange(valueToEmit);
|
822 | this.selectionChange.emit(this._getChangeEvent(valueToEmit));
|
823 | this._changeDetectorRef.markForCheck();
|
824 | }
|
825 | |
826 |
|
827 |
|
828 |
|
829 | _highlightCorrectOption() {
|
830 | if (this._keyManager) {
|
831 | if (this.empty) {
|
832 | this._keyManager.setFirstItemActive();
|
833 | }
|
834 | else {
|
835 | this._keyManager.setActiveItem(this._selectionModel.selected[0]);
|
836 | }
|
837 | }
|
838 | }
|
839 |
|
840 | _canOpen() {
|
841 | return !this._panelOpen && !this.disabled && this.options?.length > 0;
|
842 | }
|
843 |
|
844 | focus(options) {
|
845 | this._elementRef.nativeElement.focus(options);
|
846 | }
|
847 |
|
848 | _getPanelAriaLabelledby() {
|
849 | if (this.ariaLabel) {
|
850 | return null;
|
851 | }
|
852 | const labelId = this._parentFormField?.getLabelId();
|
853 | const labelExpression = labelId ? labelId + ' ' : '';
|
854 | return this.ariaLabelledby ? labelExpression + this.ariaLabelledby : labelId;
|
855 | }
|
856 |
|
857 | _getAriaActiveDescendant() {
|
858 | if (this.panelOpen && this._keyManager && this._keyManager.activeItem) {
|
859 | return this._keyManager.activeItem.id;
|
860 | }
|
861 | return null;
|
862 | }
|
863 |
|
864 | _getTriggerAriaLabelledby() {
|
865 | if (this.ariaLabel) {
|
866 | return null;
|
867 | }
|
868 | const labelId = this._parentFormField?.getLabelId();
|
869 | let value = (labelId ? labelId + ' ' : '') + this._valueId;
|
870 | if (this.ariaLabelledby) {
|
871 | value += ' ' + this.ariaLabelledby;
|
872 | }
|
873 | return value;
|
874 | }
|
875 |
|
876 | _panelDoneAnimating(isOpen) {
|
877 | this.openedChange.emit(isOpen);
|
878 | }
|
879 | |
880 |
|
881 |
|
882 |
|
883 | setDescribedByIds(ids) {
|
884 | if (ids.length) {
|
885 | this._elementRef.nativeElement.setAttribute('aria-describedby', ids.join(' '));
|
886 | }
|
887 | else {
|
888 | this._elementRef.nativeElement.removeAttribute('aria-describedby');
|
889 | }
|
890 | }
|
891 | |
892 |
|
893 |
|
894 |
|
895 | onContainerClick() {
|
896 | this.focus();
|
897 | this.open();
|
898 | }
|
899 | |
900 |
|
901 |
|
902 |
|
903 | get shouldLabelFloat() {
|
904 | return this._panelOpen || !this.empty || (this._focused && !!this._placeholder);
|
905 | }
|
906 | }
|
907 | _MatSelectBase.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.0.1", ngImport: i0, type: _MatSelectBase, deps: [{ token: i1.ViewportRuler }, { token: i0.ChangeDetectorRef }, { token: i0.NgZone }, { token: i2.ErrorStateMatcher }, { token: i0.ElementRef }, { token: i3.Directionality, optional: true }, { token: i4.NgForm, optional: true }, { token: i4.FormGroupDirective, optional: true }, { token: MAT_FORM_FIELD, optional: true }, { token: i4.NgControl, optional: true, self: true }, { token: 'tabindex', attribute: true }, { token: MAT_SELECT_SCROLL_STRATEGY }, { token: i5.LiveAnnouncer }, { token: MAT_SELECT_CONFIG, optional: true }], target: i0.ɵɵFactoryTarget.Directive });
|
908 | _MatSelectBase.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "14.0.1", type: _MatSelectBase, inputs: { userAriaDescribedBy: ["aria-describedby", "userAriaDescribedBy"], panelClass: "panelClass", placeholder: "placeholder", required: "required", multiple: "multiple", disableOptionCentering: "disableOptionCentering", compareWith: "compareWith", value: "value", ariaLabel: ["aria-label", "ariaLabel"], ariaLabelledby: ["aria-labelledby", "ariaLabelledby"], errorStateMatcher: "errorStateMatcher", typeaheadDebounceInterval: "typeaheadDebounceInterval", sortComparator: "sortComparator", id: "id" }, outputs: { openedChange: "openedChange", _openedStream: "opened", _closedStream: "closed", selectionChange: "selectionChange", valueChange: "valueChange" }, viewQueries: [{ propertyName: "trigger", first: true, predicate: ["trigger"], descendants: true }, { propertyName: "panel", first: true, predicate: ["panel"], descendants: true }, { propertyName: "_overlayDir", first: true, predicate: CdkConnectedOverlay, descendants: true }], usesInheritance: true, usesOnChanges: true, ngImport: i0 });
|
909 | i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.0.1", ngImport: i0, type: _MatSelectBase, decorators: [{
|
910 | type: Directive
|
911 | }], ctorParameters: function () { return [{ type: i1.ViewportRuler }, { type: i0.ChangeDetectorRef }, { type: i0.NgZone }, { type: i2.ErrorStateMatcher }, { type: i0.ElementRef }, { type: i3.Directionality, decorators: [{
|
912 | type: Optional
|
913 | }] }, { type: i4.NgForm, decorators: [{
|
914 | type: Optional
|
915 | }] }, { type: i4.FormGroupDirective, decorators: [{
|
916 | type: Optional
|
917 | }] }, { type: i6.MatFormField, decorators: [{
|
918 | type: Optional
|
919 | }, {
|
920 | type: Inject,
|
921 | args: [MAT_FORM_FIELD]
|
922 | }] }, { type: i4.NgControl, decorators: [{
|
923 | type: Self
|
924 | }, {
|
925 | type: Optional
|
926 | }] }, { type: undefined, decorators: [{
|
927 | type: Attribute,
|
928 | args: ['tabindex']
|
929 | }] }, { type: undefined, decorators: [{
|
930 | type: Inject,
|
931 | args: [MAT_SELECT_SCROLL_STRATEGY]
|
932 | }] }, { type: i5.LiveAnnouncer }, { type: undefined, decorators: [{
|
933 | type: Optional
|
934 | }, {
|
935 | type: Inject,
|
936 | args: [MAT_SELECT_CONFIG]
|
937 | }] }]; }, propDecorators: { userAriaDescribedBy: [{
|
938 | type: Input,
|
939 | args: ['aria-describedby']
|
940 | }], trigger: [{
|
941 | type: ViewChild,
|
942 | args: ['trigger']
|
943 | }], panel: [{
|
944 | type: ViewChild,
|
945 | args: ['panel']
|
946 | }], _overlayDir: [{
|
947 | type: ViewChild,
|
948 | args: [CdkConnectedOverlay]
|
949 | }], panelClass: [{
|
950 | type: Input
|
951 | }], placeholder: [{
|
952 | type: Input
|
953 | }], required: [{
|
954 | type: Input
|
955 | }], multiple: [{
|
956 | type: Input
|
957 | }], disableOptionCentering: [{
|
958 | type: Input
|
959 | }], compareWith: [{
|
960 | type: Input
|
961 | }], value: [{
|
962 | type: Input
|
963 | }], ariaLabel: [{
|
964 | type: Input,
|
965 | args: ['aria-label']
|
966 | }], ariaLabelledby: [{
|
967 | type: Input,
|
968 | args: ['aria-labelledby']
|
969 | }], errorStateMatcher: [{
|
970 | type: Input
|
971 | }], typeaheadDebounceInterval: [{
|
972 | type: Input
|
973 | }], sortComparator: [{
|
974 | type: Input
|
975 | }], id: [{
|
976 | type: Input
|
977 | }], openedChange: [{
|
978 | type: Output
|
979 | }], _openedStream: [{
|
980 | type: Output,
|
981 | args: ['opened']
|
982 | }], _closedStream: [{
|
983 | type: Output,
|
984 | args: ['closed']
|
985 | }], selectionChange: [{
|
986 | type: Output
|
987 | }], valueChange: [{
|
988 | type: Output
|
989 | }] } });
|
990 | class MatSelect extends _MatSelectBase {
|
991 | constructor() {
|
992 | super(...arguments);
|
993 |
|
994 | this._scrollTop = 0;
|
995 |
|
996 | this._triggerFontSize = 0;
|
997 |
|
998 | this._transformOrigin = 'top';
|
999 | |
1000 |
|
1001 |
|
1002 |
|
1003 |
|
1004 | this._offsetY = 0;
|
1005 | this._positions = [
|
1006 | {
|
1007 | originX: 'start',
|
1008 | originY: 'top',
|
1009 | overlayX: 'start',
|
1010 | overlayY: 'top',
|
1011 | },
|
1012 | {
|
1013 | originX: 'start',
|
1014 | originY: 'bottom',
|
1015 | overlayX: 'start',
|
1016 | overlayY: 'bottom',
|
1017 | },
|
1018 | ];
|
1019 | }
|
1020 | |
1021 |
|
1022 |
|
1023 |
|
1024 |
|
1025 |
|
1026 |
|
1027 | _calculateOverlayScroll(selectedIndex, scrollBuffer, maxScroll) {
|
1028 | const itemHeight = this._getItemHeight();
|
1029 | const optionOffsetFromScrollTop = itemHeight * selectedIndex;
|
1030 | const halfOptionHeight = itemHeight / 2;
|
1031 |
|
1032 |
|
1033 |
|
1034 |
|
1035 | const optimalScrollPosition = optionOffsetFromScrollTop - scrollBuffer + halfOptionHeight;
|
1036 | return Math.min(Math.max(0, optimalScrollPosition), maxScroll);
|
1037 | }
|
1038 | ngOnInit() {
|
1039 | super.ngOnInit();
|
1040 | this._viewportRuler
|
1041 | .change()
|
1042 | .pipe(takeUntil(this._destroy))
|
1043 | .subscribe(() => {
|
1044 | if (this.panelOpen) {
|
1045 | this._triggerRect = this.trigger.nativeElement.getBoundingClientRect();
|
1046 | this._changeDetectorRef.markForCheck();
|
1047 | }
|
1048 | });
|
1049 | }
|
1050 | open() {
|
1051 | if (super._canOpen()) {
|
1052 | super.open();
|
1053 | this._triggerRect = this.trigger.nativeElement.getBoundingClientRect();
|
1054 |
|
1055 |
|
1056 | this._triggerFontSize = parseInt(getComputedStyle(this.trigger.nativeElement).fontSize || '0');
|
1057 | this._calculateOverlayPosition();
|
1058 |
|
1059 | this._ngZone.onStable.pipe(take(1)).subscribe(() => {
|
1060 | if (this._triggerFontSize &&
|
1061 | this._overlayDir.overlayRef &&
|
1062 | this._overlayDir.overlayRef.overlayElement) {
|
1063 | this._overlayDir.overlayRef.overlayElement.style.fontSize = `${this._triggerFontSize}px`;
|
1064 | }
|
1065 | });
|
1066 | }
|
1067 | }
|
1068 |
|
1069 | _scrollOptionIntoView(index) {
|
1070 | const labelCount = _countGroupLabelsBeforeOption(index, this.options, this.optionGroups);
|
1071 | const itemHeight = this._getItemHeight();
|
1072 | if (index === 0 && labelCount === 1) {
|
1073 |
|
1074 |
|
1075 |
|
1076 | this.panel.nativeElement.scrollTop = 0;
|
1077 | }
|
1078 | else {
|
1079 | this.panel.nativeElement.scrollTop = _getOptionScrollPosition((index + labelCount) * itemHeight, itemHeight, this.panel.nativeElement.scrollTop, SELECT_PANEL_MAX_HEIGHT);
|
1080 | }
|
1081 | }
|
1082 | _positioningSettled() {
|
1083 | this._calculateOverlayOffsetX();
|
1084 | this.panel.nativeElement.scrollTop = this._scrollTop;
|
1085 | }
|
1086 | _panelDoneAnimating(isOpen) {
|
1087 | if (this.panelOpen) {
|
1088 | this._scrollTop = 0;
|
1089 | }
|
1090 | else {
|
1091 | this._overlayDir.offsetX = 0;
|
1092 | this._changeDetectorRef.markForCheck();
|
1093 | }
|
1094 | super._panelDoneAnimating(isOpen);
|
1095 | }
|
1096 | _getChangeEvent(value) {
|
1097 | return new MatSelectChange(this, value);
|
1098 | }
|
1099 | |
1100 |
|
1101 |
|
1102 |
|
1103 |
|
1104 |
|
1105 |
|
1106 | _calculateOverlayOffsetX() {
|
1107 | const overlayRect = this._overlayDir.overlayRef.overlayElement.getBoundingClientRect();
|
1108 | const viewportSize = this._viewportRuler.getViewportSize();
|
1109 | const isRtl = this._isRtl();
|
1110 | const paddingWidth = this.multiple
|
1111 | ? SELECT_MULTIPLE_PANEL_PADDING_X + SELECT_PANEL_PADDING_X
|
1112 | : SELECT_PANEL_PADDING_X * 2;
|
1113 | let offsetX;
|
1114 |
|
1115 | if (this.multiple) {
|
1116 | offsetX = SELECT_MULTIPLE_PANEL_PADDING_X;
|
1117 | }
|
1118 | else if (this.disableOptionCentering) {
|
1119 | offsetX = SELECT_PANEL_PADDING_X;
|
1120 | }
|
1121 | else {
|
1122 | let selected = this._selectionModel.selected[0] || this.options.first;
|
1123 | offsetX = selected && selected.group ? SELECT_PANEL_INDENT_PADDING_X : SELECT_PANEL_PADDING_X;
|
1124 | }
|
1125 |
|
1126 | if (!isRtl) {
|
1127 | offsetX *= -1;
|
1128 | }
|
1129 |
|
1130 | const leftOverflow = 0 - (overlayRect.left + offsetX - (isRtl ? paddingWidth : 0));
|
1131 | const rightOverflow = overlayRect.right + offsetX - viewportSize.width + (isRtl ? 0 : paddingWidth);
|
1132 |
|
1133 | if (leftOverflow > 0) {
|
1134 | offsetX += leftOverflow + SELECT_PANEL_VIEWPORT_PADDING;
|
1135 | }
|
1136 | else if (rightOverflow > 0) {
|
1137 | offsetX -= rightOverflow + SELECT_PANEL_VIEWPORT_PADDING;
|
1138 | }
|
1139 |
|
1140 |
|
1141 |
|
1142 | this._overlayDir.offsetX = Math.round(offsetX);
|
1143 | this._overlayDir.overlayRef.updatePosition();
|
1144 | }
|
1145 | |
1146 |
|
1147 |
|
1148 |
|
1149 |
|
1150 | _calculateOverlayOffsetY(selectedIndex, scrollBuffer, maxScroll) {
|
1151 | const itemHeight = this._getItemHeight();
|
1152 | const optionHeightAdjustment = (itemHeight - this._triggerRect.height) / 2;
|
1153 | const maxOptionsDisplayed = Math.floor(SELECT_PANEL_MAX_HEIGHT / itemHeight);
|
1154 | let optionOffsetFromPanelTop;
|
1155 |
|
1156 | if (this.disableOptionCentering) {
|
1157 | return 0;
|
1158 | }
|
1159 | if (this._scrollTop === 0) {
|
1160 | optionOffsetFromPanelTop = selectedIndex * itemHeight;
|
1161 | }
|
1162 | else if (this._scrollTop === maxScroll) {
|
1163 | const firstDisplayedIndex = this._getItemCount() - maxOptionsDisplayed;
|
1164 | const selectedDisplayIndex = selectedIndex - firstDisplayedIndex;
|
1165 |
|
1166 |
|
1167 | let partialItemHeight = itemHeight - ((this._getItemCount() * itemHeight - SELECT_PANEL_MAX_HEIGHT) % itemHeight);
|
1168 |
|
1169 |
|
1170 |
|
1171 |
|
1172 | optionOffsetFromPanelTop = selectedDisplayIndex * itemHeight + partialItemHeight;
|
1173 | }
|
1174 | else {
|
1175 |
|
1176 |
|
1177 |
|
1178 | optionOffsetFromPanelTop = scrollBuffer - itemHeight / 2;
|
1179 | }
|
1180 |
|
1181 |
|
1182 |
|
1183 | return Math.round(optionOffsetFromPanelTop * -1 - optionHeightAdjustment);
|
1184 | }
|
1185 | |
1186 |
|
1187 |
|
1188 |
|
1189 |
|
1190 |
|
1191 | _checkOverlayWithinViewport(maxScroll) {
|
1192 | const itemHeight = this._getItemHeight();
|
1193 | const viewportSize = this._viewportRuler.getViewportSize();
|
1194 | const topSpaceAvailable = this._triggerRect.top - SELECT_PANEL_VIEWPORT_PADDING;
|
1195 | const bottomSpaceAvailable = viewportSize.height - this._triggerRect.bottom - SELECT_PANEL_VIEWPORT_PADDING;
|
1196 | const panelHeightTop = Math.abs(this._offsetY);
|
1197 | const totalPanelHeight = Math.min(this._getItemCount() * itemHeight, SELECT_PANEL_MAX_HEIGHT);
|
1198 | const panelHeightBottom = totalPanelHeight - panelHeightTop - this._triggerRect.height;
|
1199 | if (panelHeightBottom > bottomSpaceAvailable) {
|
1200 | this._adjustPanelUp(panelHeightBottom, bottomSpaceAvailable);
|
1201 | }
|
1202 | else if (panelHeightTop > topSpaceAvailable) {
|
1203 | this._adjustPanelDown(panelHeightTop, topSpaceAvailable, maxScroll);
|
1204 | }
|
1205 | else {
|
1206 | this._transformOrigin = this._getOriginBasedOnOption();
|
1207 | }
|
1208 | }
|
1209 |
|
1210 | _adjustPanelUp(panelHeightBottom, bottomSpaceAvailable) {
|
1211 |
|
1212 | const distanceBelowViewport = Math.round(panelHeightBottom - bottomSpaceAvailable);
|
1213 |
|
1214 |
|
1215 | this._scrollTop -= distanceBelowViewport;
|
1216 | this._offsetY -= distanceBelowViewport;
|
1217 | this._transformOrigin = this._getOriginBasedOnOption();
|
1218 |
|
1219 |
|
1220 |
|
1221 | if (this._scrollTop <= 0) {
|
1222 | this._scrollTop = 0;
|
1223 | this._offsetY = 0;
|
1224 | this._transformOrigin = `50% bottom 0px`;
|
1225 | }
|
1226 | }
|
1227 |
|
1228 | _adjustPanelDown(panelHeightTop, topSpaceAvailable, maxScroll) {
|
1229 |
|
1230 | const distanceAboveViewport = Math.round(panelHeightTop - topSpaceAvailable);
|
1231 |
|
1232 |
|
1233 | this._scrollTop += distanceAboveViewport;
|
1234 | this._offsetY += distanceAboveViewport;
|
1235 | this._transformOrigin = this._getOriginBasedOnOption();
|
1236 |
|
1237 |
|
1238 |
|
1239 | if (this._scrollTop >= maxScroll) {
|
1240 | this._scrollTop = maxScroll;
|
1241 | this._offsetY = 0;
|
1242 | this._transformOrigin = `50% top 0px`;
|
1243 | return;
|
1244 | }
|
1245 | }
|
1246 |
|
1247 | _calculateOverlayPosition() {
|
1248 | const itemHeight = this._getItemHeight();
|
1249 | const items = this._getItemCount();
|
1250 | const panelHeight = Math.min(items * itemHeight, SELECT_PANEL_MAX_HEIGHT);
|
1251 | const scrollContainerHeight = items * itemHeight;
|
1252 |
|
1253 | const maxScroll = scrollContainerHeight - panelHeight;
|
1254 |
|
1255 | let selectedOptionOffset;
|
1256 | if (this.empty) {
|
1257 | selectedOptionOffset = 0;
|
1258 | }
|
1259 | else {
|
1260 | selectedOptionOffset = Math.max(this.options.toArray().indexOf(this._selectionModel.selected[0]), 0);
|
1261 | }
|
1262 | selectedOptionOffset += _countGroupLabelsBeforeOption(selectedOptionOffset, this.options, this.optionGroups);
|
1263 |
|
1264 |
|
1265 | const scrollBuffer = panelHeight / 2;
|
1266 | this._scrollTop = this._calculateOverlayScroll(selectedOptionOffset, scrollBuffer, maxScroll);
|
1267 | this._offsetY = this._calculateOverlayOffsetY(selectedOptionOffset, scrollBuffer, maxScroll);
|
1268 | this._checkOverlayWithinViewport(maxScroll);
|
1269 | }
|
1270 |
|
1271 | _getOriginBasedOnOption() {
|
1272 | const itemHeight = this._getItemHeight();
|
1273 | const optionHeightAdjustment = (itemHeight - this._triggerRect.height) / 2;
|
1274 | const originY = Math.abs(this._offsetY) - optionHeightAdjustment + itemHeight / 2;
|
1275 | return `50% ${originY}px 0px`;
|
1276 | }
|
1277 |
|
1278 | _getItemHeight() {
|
1279 | return this._triggerFontSize * SELECT_ITEM_HEIGHT_EM;
|
1280 | }
|
1281 |
|
1282 | _getItemCount() {
|
1283 | return this.options.length + this.optionGroups.length;
|
1284 | }
|
1285 | }
|
1286 | MatSelect.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.0.1", ngImport: i0, type: MatSelect, deps: null, target: i0.ɵɵFactoryTarget.Component });
|
1287 | MatSelect.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "14.0.1", type: MatSelect, selector: "mat-select", inputs: { disabled: "disabled", disableRipple: "disableRipple", tabIndex: "tabIndex" }, host: { attributes: { "role": "combobox", "aria-autocomplete": "none", "aria-haspopup": "true" }, listeners: { "keydown": "_handleKeydown($event)", "focus": "_onFocus()", "blur": "_onBlur()" }, properties: { "attr.id": "id", "attr.tabindex": "tabIndex", "attr.aria-controls": "panelOpen ? id + \"-panel\" : null", "attr.aria-expanded": "panelOpen", "attr.aria-label": "ariaLabel || null", "attr.aria-required": "required.toString()", "attr.aria-disabled": "disabled.toString()", "attr.aria-invalid": "errorState", "attr.aria-activedescendant": "_getAriaActiveDescendant()", "class.mat-select-disabled": "disabled", "class.mat-select-invalid": "errorState", "class.mat-select-required": "required", "class.mat-select-empty": "empty", "class.mat-select-multiple": "multiple" }, classAttribute: "mat-select" }, providers: [
|
1288 | { provide: MatFormFieldControl, useExisting: MatSelect },
|
1289 | { provide: MAT_OPTION_PARENT_COMPONENT, useExisting: MatSelect },
|
1290 | ], queries: [{ propertyName: "customTrigger", first: true, predicate: MAT_SELECT_TRIGGER, descendants: true }, { propertyName: "options", predicate: MatOption, descendants: true }, { propertyName: "optionGroups", predicate: MAT_OPTGROUP, descendants: true }], exportAs: ["matSelect"], usesInheritance: true, ngImport: i0, template: "<!--\n Note that the select trigger element specifies `aria-owns` pointing to the listbox overlay.\n While aria-owns is not required for the ARIA 1.2 `role=\"combobox\"` interaction pattern,\n it fixes an issue with VoiceOver when the select appears inside of an `aria-model=\"true\"`\n element (e.g. a dialog). Without this `aria-owns`, the `aria-modal` on a dialog prevents\n VoiceOver from \"seeing\" the select's listbox overlay for aria-activedescendant.\n Using `aria-owns` re-parents the select overlay so that it works again.\n See https://github.com/angular/components/issues/20694\n-->\n<div cdk-overlay-origin\n [attr.aria-owns]=\"panelOpen ? id + '-panel' : null\"\n class=\"mat-select-trigger\"\n (click)=\"toggle()\"\n #origin=\"cdkOverlayOrigin\"\n #trigger>\n <div class=\"mat-select-value\" [ngSwitch]=\"empty\" [attr.id]=\"_valueId\">\n <span class=\"mat-select-placeholder mat-select-min-line\" *ngSwitchCase=\"true\">{{placeholder}}</span>\n <span class=\"mat-select-value-text\" *ngSwitchCase=\"false\" [ngSwitch]=\"!!customTrigger\">\n <span class=\"mat-select-min-line\" *ngSwitchDefault>{{triggerValue}}</span>\n <ng-content select=\"mat-select-trigger\" *ngSwitchCase=\"true\"></ng-content>\n </span>\n </div>\n\n <div class=\"mat-select-arrow-wrapper\"><div class=\"mat-select-arrow\"></div></div>\n</div>\n\n<ng-template\n cdk-connected-overlay\n cdkConnectedOverlayLockPosition\n cdkConnectedOverlayHasBackdrop\n cdkConnectedOverlayBackdropClass=\"cdk-overlay-transparent-backdrop\"\n [cdkConnectedOverlayPanelClass]=\"_overlayPanelClass\"\n [cdkConnectedOverlayScrollStrategy]=\"_scrollStrategy\"\n [cdkConnectedOverlayOrigin]=\"origin\"\n [cdkConnectedOverlayOpen]=\"panelOpen\"\n [cdkConnectedOverlayPositions]=\"_positions\"\n [cdkConnectedOverlayMinWidth]=\"_triggerRect?.width!\"\n [cdkConnectedOverlayOffsetY]=\"_offsetY\"\n (backdropClick)=\"close()\"\n (attach)=\"_onAttached()\"\n (detach)=\"close()\">\n <div class=\"mat-select-panel-wrap\" [@transformPanelWrap]>\n <div\n #panel\n role=\"listbox\"\n tabindex=\"-1\"\n class=\"mat-select-panel {{ _getPanelTheme() }}\"\n [attr.id]=\"id + '-panel'\"\n [attr.aria-multiselectable]=\"multiple\"\n [attr.aria-label]=\"ariaLabel || null\"\n [attr.aria-labelledby]=\"_getPanelAriaLabelledby()\"\n [ngClass]=\"panelClass\"\n [@transformPanel]=\"multiple ? 'showing-multiple' : 'showing'\"\n (@transformPanel.done)=\"_panelDoneAnimatingStream.next($event.toState)\"\n [style.transformOrigin]=\"_transformOrigin\"\n [style.font-size.px]=\"_triggerFontSize\"\n (keydown)=\"_handleKeydown($event)\">\n <ng-content></ng-content>\n </div>\n </div>\n</ng-template>\n", styles: [".mat-select{display:inline-block;width:100%;outline:none}.mat-select-trigger{display:inline-flex;align-items:center;cursor:pointer;position:relative;box-sizing:border-box;width:100%}.mat-select-disabled .mat-select-trigger{-webkit-user-select:none;user-select:none;cursor:default}.mat-select-value{width:100%;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}.mat-select-value-text{white-space:nowrap;overflow:hidden;text-overflow:ellipsis}.mat-select-arrow-wrapper{height:16px;flex-shrink:0;display:inline-flex;align-items:center}.mat-form-field-appearance-fill .mat-select-arrow-wrapper{transform:translateY(-50%)}.mat-form-field-appearance-outline .mat-select-arrow-wrapper{transform:translateY(-25%)}.mat-form-field-appearance-standard.mat-form-field-has-label .mat-select:not(.mat-select-empty) .mat-select-arrow-wrapper{transform:translateY(-50%)}.mat-form-field-appearance-standard .mat-select.mat-select-empty .mat-select-arrow-wrapper{transition:transform 400ms cubic-bezier(0.25, 0.8, 0.25, 1)}._mat-animation-noopable.mat-form-field-appearance-standard .mat-select.mat-select-empty .mat-select-arrow-wrapper{transition:none}.mat-select-arrow{width:0;height:0;border-left:5px solid rgba(0,0,0,0);border-right:5px solid rgba(0,0,0,0);border-top:5px solid;margin:0 4px}.mat-form-field.mat-focused .mat-select-arrow{transform:translateX(0)}.mat-select-panel-wrap{flex-basis:100%}.mat-select-panel{min-width:112px;max-width:280px;overflow:auto;-webkit-overflow-scrolling:touch;padding-top:0;padding-bottom:0;max-height:256px;min-width:100%;border-radius:4px;outline:0}.cdk-high-contrast-active .mat-select-panel{outline:solid 1px}.mat-select-panel .mat-optgroup-label,.mat-select-panel .mat-option{font-size:inherit;line-height:3em;height:3em}.mat-form-field-type-mat-select:not(.mat-form-field-disabled) .mat-form-field-flex{cursor:pointer}.mat-form-field-type-mat-select .mat-form-field-label{width:calc(100% - 18px)}.mat-select-placeholder{transition:color 400ms 133.3333333333ms cubic-bezier(0.25, 0.8, 0.25, 1)}._mat-animation-noopable .mat-select-placeholder{transition:none}.mat-form-field-hide-placeholder .mat-select-placeholder{color:rgba(0,0,0,0);-webkit-text-fill-color:rgba(0,0,0,0);transition:none;display:block}.mat-select-min-line:empty::before{content:\" \";white-space:pre;width:1px;display:inline-block;visibility:hidden}"], dependencies: [{ kind: "directive", type: i7.NgClass, selector: "[ngClass]", inputs: ["class", "ngClass"] }, { kind: "directive", type: i7.NgSwitch, selector: "[ngSwitch]", inputs: ["ngSwitch"] }, { kind: "directive", type: i7.NgSwitchCase, selector: "[ngSwitchCase]", inputs: ["ngSwitchCase"] }, { kind: "directive", type: i7.NgSwitchDefault, selector: "[ngSwitchDefault]" }, { kind: "directive", type: i8.CdkConnectedOverlay, selector: "[cdk-connected-overlay], [connected-overlay], [cdkConnectedOverlay]", inputs: ["cdkConnectedOverlayOrigin", "cdkConnectedOverlayPositions", "cdkConnectedOverlayPositionStrategy", "cdkConnectedOverlayOffsetX", "cdkConnectedOverlayOffsetY", "cdkConnectedOverlayWidth", "cdkConnectedOverlayHeight", "cdkConnectedOverlayMinWidth", "cdkConnectedOverlayMinHeight", "cdkConnectedOverlayBackdropClass", "cdkConnectedOverlayPanelClass", "cdkConnectedOverlayViewportMargin", "cdkConnectedOverlayScrollStrategy", "cdkConnectedOverlayOpen", "cdkConnectedOverlayDisableClose", "cdkConnectedOverlayTransformOriginOn", "cdkConnectedOverlayHasBackdrop", "cdkConnectedOverlayLockPosition", "cdkConnectedOverlayFlexibleDimensions", "cdkConnectedOverlayGrowAfterOpen", "cdkConnectedOverlayPush"], outputs: ["backdropClick", "positionChange", "attach", "detach", "overlayKeydown", "overlayOutsideClick"], exportAs: ["cdkConnectedOverlay"] }, { kind: "directive", type: i8.CdkOverlayOrigin, selector: "[cdk-overlay-origin], [overlay-origin], [cdkOverlayOrigin]", exportAs: ["cdkOverlayOrigin"] }], animations: [matSelectAnimations.transformPanelWrap, matSelectAnimations.transformPanel], changeDetection: i0.ChangeDetectionStrategy.OnPush, encapsulation: i0.ViewEncapsulation.None });
|
1291 | i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.0.1", ngImport: i0, type: MatSelect, decorators: [{
|
1292 | type: Component,
|
1293 | args: [{ selector: 'mat-select', exportAs: 'matSelect', inputs: ['disabled', 'disableRipple', 'tabIndex'], encapsulation: ViewEncapsulation.None, changeDetection: ChangeDetectionStrategy.OnPush, host: {
|
1294 | 'role': 'combobox',
|
1295 | 'aria-autocomplete': 'none',
|
1296 |
|
1297 |
|
1298 |
|
1299 | 'aria-haspopup': 'true',
|
1300 | 'class': 'mat-select',
|
1301 | '[attr.id]': 'id',
|
1302 | '[attr.tabindex]': 'tabIndex',
|
1303 | '[attr.aria-controls]': 'panelOpen ? id + "-panel" : null',
|
1304 | '[attr.aria-expanded]': 'panelOpen',
|
1305 | '[attr.aria-label]': 'ariaLabel || null',
|
1306 | '[attr.aria-required]': 'required.toString()',
|
1307 | '[attr.aria-disabled]': 'disabled.toString()',
|
1308 | '[attr.aria-invalid]': 'errorState',
|
1309 | '[attr.aria-activedescendant]': '_getAriaActiveDescendant()',
|
1310 | '[class.mat-select-disabled]': 'disabled',
|
1311 | '[class.mat-select-invalid]': 'errorState',
|
1312 | '[class.mat-select-required]': 'required',
|
1313 | '[class.mat-select-empty]': 'empty',
|
1314 | '[class.mat-select-multiple]': 'multiple',
|
1315 | '(keydown)': '_handleKeydown($event)',
|
1316 | '(focus)': '_onFocus()',
|
1317 | '(blur)': '_onBlur()',
|
1318 | }, animations: [matSelectAnimations.transformPanelWrap, matSelectAnimations.transformPanel], providers: [
|
1319 | { provide: MatFormFieldControl, useExisting: MatSelect },
|
1320 | { provide: MAT_OPTION_PARENT_COMPONENT, useExisting: MatSelect },
|
1321 | ], template: "<!--\n Note that the select trigger element specifies `aria-owns` pointing to the listbox overlay.\n While aria-owns is not required for the ARIA 1.2 `role=\"combobox\"` interaction pattern,\n it fixes an issue with VoiceOver when the select appears inside of an `aria-model=\"true\"`\n element (e.g. a dialog). Without this `aria-owns`, the `aria-modal` on a dialog prevents\n VoiceOver from \"seeing\" the select's listbox overlay for aria-activedescendant.\n Using `aria-owns` re-parents the select overlay so that it works again.\n See https://github.com/angular/components/issues/20694\n-->\n<div cdk-overlay-origin\n [attr.aria-owns]=\"panelOpen ? id + '-panel' : null\"\n class=\"mat-select-trigger\"\n (click)=\"toggle()\"\n #origin=\"cdkOverlayOrigin\"\n #trigger>\n <div class=\"mat-select-value\" [ngSwitch]=\"empty\" [attr.id]=\"_valueId\">\n <span class=\"mat-select-placeholder mat-select-min-line\" *ngSwitchCase=\"true\">{{placeholder}}</span>\n <span class=\"mat-select-value-text\" *ngSwitchCase=\"false\" [ngSwitch]=\"!!customTrigger\">\n <span class=\"mat-select-min-line\" *ngSwitchDefault>{{triggerValue}}</span>\n <ng-content select=\"mat-select-trigger\" *ngSwitchCase=\"true\"></ng-content>\n </span>\n </div>\n\n <div class=\"mat-select-arrow-wrapper\"><div class=\"mat-select-arrow\"></div></div>\n</div>\n\n<ng-template\n cdk-connected-overlay\n cdkConnectedOverlayLockPosition\n cdkConnectedOverlayHasBackdrop\n cdkConnectedOverlayBackdropClass=\"cdk-overlay-transparent-backdrop\"\n [cdkConnectedOverlayPanelClass]=\"_overlayPanelClass\"\n [cdkConnectedOverlayScrollStrategy]=\"_scrollStrategy\"\n [cdkConnectedOverlayOrigin]=\"origin\"\n [cdkConnectedOverlayOpen]=\"panelOpen\"\n [cdkConnectedOverlayPositions]=\"_positions\"\n [cdkConnectedOverlayMinWidth]=\"_triggerRect?.width!\"\n [cdkConnectedOverlayOffsetY]=\"_offsetY\"\n (backdropClick)=\"close()\"\n (attach)=\"_onAttached()\"\n (detach)=\"close()\">\n <div class=\"mat-select-panel-wrap\" [@transformPanelWrap]>\n <div\n #panel\n role=\"listbox\"\n tabindex=\"-1\"\n class=\"mat-select-panel {{ _getPanelTheme() }}\"\n [attr.id]=\"id + '-panel'\"\n [attr.aria-multiselectable]=\"multiple\"\n [attr.aria-label]=\"ariaLabel || null\"\n [attr.aria-labelledby]=\"_getPanelAriaLabelledby()\"\n [ngClass]=\"panelClass\"\n [@transformPanel]=\"multiple ? 'showing-multiple' : 'showing'\"\n (@transformPanel.done)=\"_panelDoneAnimatingStream.next($event.toState)\"\n [style.transformOrigin]=\"_transformOrigin\"\n [style.font-size.px]=\"_triggerFontSize\"\n (keydown)=\"_handleKeydown($event)\">\n <ng-content></ng-content>\n </div>\n </div>\n</ng-template>\n", styles: [".mat-select{display:inline-block;width:100%;outline:none}.mat-select-trigger{display:inline-flex;align-items:center;cursor:pointer;position:relative;box-sizing:border-box;width:100%}.mat-select-disabled .mat-select-trigger{-webkit-user-select:none;user-select:none;cursor:default}.mat-select-value{width:100%;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}.mat-select-value-text{white-space:nowrap;overflow:hidden;text-overflow:ellipsis}.mat-select-arrow-wrapper{height:16px;flex-shrink:0;display:inline-flex;align-items:center}.mat-form-field-appearance-fill .mat-select-arrow-wrapper{transform:translateY(-50%)}.mat-form-field-appearance-outline .mat-select-arrow-wrapper{transform:translateY(-25%)}.mat-form-field-appearance-standard.mat-form-field-has-label .mat-select:not(.mat-select-empty) .mat-select-arrow-wrapper{transform:translateY(-50%)}.mat-form-field-appearance-standard .mat-select.mat-select-empty .mat-select-arrow-wrapper{transition:transform 400ms cubic-bezier(0.25, 0.8, 0.25, 1)}._mat-animation-noopable.mat-form-field-appearance-standard .mat-select.mat-select-empty .mat-select-arrow-wrapper{transition:none}.mat-select-arrow{width:0;height:0;border-left:5px solid rgba(0,0,0,0);border-right:5px solid rgba(0,0,0,0);border-top:5px solid;margin:0 4px}.mat-form-field.mat-focused .mat-select-arrow{transform:translateX(0)}.mat-select-panel-wrap{flex-basis:100%}.mat-select-panel{min-width:112px;max-width:280px;overflow:auto;-webkit-overflow-scrolling:touch;padding-top:0;padding-bottom:0;max-height:256px;min-width:100%;border-radius:4px;outline:0}.cdk-high-contrast-active .mat-select-panel{outline:solid 1px}.mat-select-panel .mat-optgroup-label,.mat-select-panel .mat-option{font-size:inherit;line-height:3em;height:3em}.mat-form-field-type-mat-select:not(.mat-form-field-disabled) .mat-form-field-flex{cursor:pointer}.mat-form-field-type-mat-select .mat-form-field-label{width:calc(100% - 18px)}.mat-select-placeholder{transition:color 400ms 133.3333333333ms cubic-bezier(0.25, 0.8, 0.25, 1)}._mat-animation-noopable .mat-select-placeholder{transition:none}.mat-form-field-hide-placeholder .mat-select-placeholder{color:rgba(0,0,0,0);-webkit-text-fill-color:rgba(0,0,0,0);transition:none;display:block}.mat-select-min-line:empty::before{content:\" \";white-space:pre;width:1px;display:inline-block;visibility:hidden}"] }]
|
1322 | }], propDecorators: { options: [{
|
1323 | type: ContentChildren,
|
1324 | args: [MatOption, { descendants: true }]
|
1325 | }], optionGroups: [{
|
1326 | type: ContentChildren,
|
1327 | args: [MAT_OPTGROUP, { descendants: true }]
|
1328 | }], customTrigger: [{
|
1329 | type: ContentChild,
|
1330 | args: [MAT_SELECT_TRIGGER]
|
1331 | }] } });
|
1332 |
|
1333 |
|
1334 |
|
1335 |
|
1336 |
|
1337 |
|
1338 |
|
1339 |
|
1340 | class MatSelectModule {
|
1341 | }
|
1342 | MatSelectModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.0.1", ngImport: i0, type: MatSelectModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
|
1343 | MatSelectModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "14.0.1", ngImport: i0, type: MatSelectModule, declarations: [MatSelect, MatSelectTrigger], imports: [CommonModule, OverlayModule, MatOptionModule, MatCommonModule], exports: [CdkScrollableModule,
|
1344 | MatFormFieldModule,
|
1345 | MatSelect,
|
1346 | MatSelectTrigger,
|
1347 | MatOptionModule,
|
1348 | MatCommonModule] });
|
1349 | MatSelectModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "14.0.1", ngImport: i0, type: MatSelectModule, providers: [MAT_SELECT_SCROLL_STRATEGY_PROVIDER], imports: [CommonModule, OverlayModule, MatOptionModule, MatCommonModule, CdkScrollableModule,
|
1350 | MatFormFieldModule,
|
1351 | MatOptionModule,
|
1352 | MatCommonModule] });
|
1353 | i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.0.1", ngImport: i0, type: MatSelectModule, decorators: [{
|
1354 | type: NgModule,
|
1355 | args: [{
|
1356 | imports: [CommonModule, OverlayModule, MatOptionModule, MatCommonModule],
|
1357 | exports: [
|
1358 | CdkScrollableModule,
|
1359 | MatFormFieldModule,
|
1360 | MatSelect,
|
1361 | MatSelectTrigger,
|
1362 | MatOptionModule,
|
1363 | MatCommonModule,
|
1364 | ],
|
1365 | declarations: [MatSelect, MatSelectTrigger],
|
1366 | providers: [MAT_SELECT_SCROLL_STRATEGY_PROVIDER],
|
1367 | }]
|
1368 | }] });
|
1369 |
|
1370 |
|
1371 |
|
1372 |
|
1373 |
|
1374 |
|
1375 |
|
1376 |
|
1377 |
|
1378 |
|
1379 |
|
1380 |
|
1381 |
|
1382 |
|
1383 |
|
1384 |
|
1385 |
|
1386 |
|
1387 |
|
1388 |
|
1389 |
|
1390 | export { MAT_SELECT_CONFIG, MAT_SELECT_SCROLL_STRATEGY, MAT_SELECT_SCROLL_STRATEGY_PROVIDER, MAT_SELECT_SCROLL_STRATEGY_PROVIDER_FACTORY, MAT_SELECT_TRIGGER, MatSelect, MatSelectChange, MatSelectModule, MatSelectTrigger, _MatSelectBase, matSelectAnimations };
|
1391 |
|