blob: 4d00496ce6fe7a102b34c3f79af5fae1a6747eda [file] [log] [blame]
/**
* @license
* Copyright Google LLC All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.io/license
*/
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("@angular/cdk/a11y"),require("@angular/cdk/coercion"),require("@angular/core"),require("@angular/material/core"),require("@angular/cdk/bidi"),require("@angular/cdk/keycodes"),require("@angular/cdk/overlay"),require("@angular/cdk/portal"),require("@angular/common"),require("rxjs/operators"),require("@angular/cdk/scrolling"),require("@angular/forms"),require("@angular/material/form-field"),require("rxjs")):"function"==typeof define&&define.amd?define("@angular/material/autocomplete",["exports","@angular/cdk/a11y","@angular/cdk/coercion","@angular/core","@angular/material/core","@angular/cdk/bidi","@angular/cdk/keycodes","@angular/cdk/overlay","@angular/cdk/portal","@angular/common","rxjs/operators","@angular/cdk/scrolling","@angular/forms","@angular/material/form-field","rxjs"],e):e((t.ng=t.ng||{},t.ng.material=t.ng.material||{},t.ng.material.autocomplete={}),t.ng.cdk.a11y,t.ng.cdk.coercion,t.ng.core,t.ng.material.core,t.ng.cdk.bidi,t.ng.cdk.keycodes,t.ng.cdk.overlay,t.ng.cdk.portal,t.ng.common,t.rxjs.operators,t.ng.cdk.scrolling,t.ng.forms,t.ng.material.formField,t.rxjs)}(this,function(t,e,o,i,n,a,r,s,l,p,c,u,h,m,d){"use strict";function _(t,e){function o(){this.constructor=t}v(t,e),t.prototype=null===e?Object.create(e):(o.prototype=e.prototype,new o)}function y(){return{autoActiveFirstOption:!1}}function f(t){return function(){return t.scrollStrategies.reposition()}}function g(){return Error("Attempting to open an undefined instance of `mat-autocomplete`. Make sure that the id passed to the `matAutocomplete` is correct and that you're attempting to open it after the ngAfterContentInit hook.")}var v=function(t,e){return(v=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var o in e)e.hasOwnProperty(o)&&(t[o]=e[o])})(t,e)},O=0,b=function(){function t(t,e){this.source=t,this.option=e}return t}(),A=function(){function t(){}return t}(),E=n.mixinDisableRipple(A),C=new i.InjectionToken("mat-autocomplete-default-options",{providedIn:"root",factory:y}),P=function(t){function a(e,o,n){var a=t.call(this)||this;return a._changeDetectorRef=e,a._elementRef=o,a.showPanel=!1,a._isOpen=!1,a.displayWith=null,a.optionSelected=new i.EventEmitter,a.opened=new i.EventEmitter,a.closed=new i.EventEmitter,a._classList={},a.id="mat-autocomplete-"+O++,a._autoActiveFirstOption=!!n.autoActiveFirstOption,a}return _(a,t),Object.defineProperty(a.prototype,"isOpen",{get:function(){return this._isOpen&&this.showPanel},enumerable:!0,configurable:!0}),Object.defineProperty(a.prototype,"autoActiveFirstOption",{get:function(){return this._autoActiveFirstOption},set:function(t){this._autoActiveFirstOption=o.coerceBooleanProperty(t)},enumerable:!0,configurable:!0}),Object.defineProperty(a.prototype,"classList",{set:function(t){t&&t.length?this._classList=t.split(" ").reduce(function(t,e){return t[e.trim()]=!0,t},{}):this._classList={},this._setVisibilityClasses(this._classList),this._elementRef.nativeElement.className=""},enumerable:!0,configurable:!0}),a.prototype.ngAfterContentInit=function(){this._keyManager=new e.ActiveDescendantKeyManager(this.options).withWrap(),this._setVisibility()},a.prototype._setScrollTop=function(t){this.panel&&(this.panel.nativeElement.scrollTop=t)},a.prototype._getScrollTop=function(){return this.panel?this.panel.nativeElement.scrollTop:0},a.prototype._setVisibility=function(){this.showPanel=!!this.options.length,this._setVisibilityClasses(this._classList),this._changeDetectorRef.markForCheck()},a.prototype._emitSelectEvent=function(t){var e=new b(this,t);this.optionSelected.emit(e)},a.prototype._setVisibilityClasses=function(t){t["mat-autocomplete-visible"]=this.showPanel,t["mat-autocomplete-hidden"]=!this.showPanel},a.decorators=[{type:i.Component,args:[{selector:"mat-autocomplete",template:'<ng-template><div class="mat-autocomplete-panel" role="listbox" [id]="id" [ngClass]="_classList" #panel><ng-content></ng-content></div></ng-template>',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}@media (-ms-high-contrast:active){.mat-autocomplete-panel{outline:solid 1px}}"],encapsulation:i.ViewEncapsulation.None,changeDetection:i.ChangeDetectionStrategy.OnPush,exportAs:"matAutocomplete",inputs:["disableRipple"],host:{class:"mat-autocomplete"},providers:[{provide:n.MAT_OPTION_PARENT_COMPONENT,useExisting:a}]}]}],a.ctorParameters=function(){return[{type:i.ChangeDetectorRef},{type:i.ElementRef},{type:void 0,decorators:[{type:i.Inject,args:[C]}]}]},a.propDecorators={template:[{type:i.ViewChild,args:[i.TemplateRef,{static:!0}]}],panel:[{type:i.ViewChild,args:["panel",{static:!1}]}],options:[{type:i.ContentChildren,args:[n.MatOption,{descendants:!0}]}],optionGroups:[{type:i.ContentChildren,args:[n.MatOptgroup]}],displayWith:[{type:i.Input}],autoActiveFirstOption:[{type:i.Input}],panelWidth:[{type:i.Input}],optionSelected:[{type:i.Output}],opened:[{type:i.Output}],closed:[{type:i.Output}],classList:[{type:i.Input,args:["class"]}]},a}(E),T=function(){function t(t){this.elementRef=t}return t.decorators=[{type:i.Directive,args:[{selector:"[matAutocompleteOrigin]",exportAs:"matAutocompleteOrigin"}]}],t.ctorParameters=function(){return[{type:i.ElementRef}]},t}(),w=new i.InjectionToken("mat-autocomplete-scroll-strategy"),S={provide:w,deps:[s.Overlay],useFactory:f},R={provide:h.NG_VALUE_ACCESSOR,useExisting:i.forwardRef(function(){return M}),multi:!0},M=function(){function t(t,e,o,i,n,a,r,s,l,p){var u=this;this._element=t,this._overlay=e,this._viewContainerRef=o,this._zone=i,this._changeDetectorRef=n,this._dir=r,this._formField=s,this._document=l,this._viewportRuler=p,this._componentDestroyed=!1,this._autocompleteDisabled=!1,this._manuallyFloatingLabel=!1,this._viewportSubscription=d.Subscription.EMPTY,this._canOpenOnNextFocus=!0,this._closeKeyEventStream=new d.Subject,this._windowBlurHandler=function(){u._canOpenOnNextFocus=u._document.activeElement!==u._element.nativeElement||u.panelOpen},this._onChange=function(){},this._onTouched=function(){},this.position="auto",this.autocompleteAttribute="off",this._overlayAttached=!1,this.optionSelections=d.defer(function(){return u.autocomplete&&u.autocomplete.options?d.merge.apply(void 0,u.autocomplete.options.map(function(t){return t.onSelectionChange})):u._zone.onStable.asObservable().pipe(c.take(1),c.switchMap(function(){return u.optionSelections}))}),"undefined"!=typeof window&&i.runOutsideAngular(function(){window.addEventListener("blur",u._windowBlurHandler)}),this._scrollStrategy=a}return Object.defineProperty(t.prototype,"autocompleteDisabled",{get:function(){return this._autocompleteDisabled},set:function(t){this._autocompleteDisabled=o.coerceBooleanProperty(t)},enumerable:!0,configurable:!0}),t.prototype.ngOnChanges=function(t){t.position&&this._positionStrategy&&(this._setStrategyPositions(this._positionStrategy),this.panelOpen&&this._overlayRef.updatePosition())},t.prototype.ngOnDestroy=function(){"undefined"!=typeof window&&window.removeEventListener("blur",this._windowBlurHandler),this._viewportSubscription.unsubscribe(),this._componentDestroyed=!0,this._destroyPanel(),this._closeKeyEventStream.complete()},Object.defineProperty(t.prototype,"panelOpen",{get:function(){return this._overlayAttached&&this.autocomplete.showPanel},enumerable:!0,configurable:!0}),t.prototype.openPanel=function(){this._attachOverlay(),this._floatLabel()},t.prototype.closePanel=function(){this._resetLabel(),this._overlayAttached&&(this.panelOpen&&this.autocomplete.closed.emit(),this.autocomplete._isOpen=this._overlayAttached=!1,this._overlayRef&&this._overlayRef.hasAttached()&&(this._overlayRef.detach(),this._closingActionsSubscription.unsubscribe()),this._componentDestroyed||this._changeDetectorRef.detectChanges())},t.prototype.updatePosition=function(){this._overlayAttached&&this._overlayRef.updatePosition()},Object.defineProperty(t.prototype,"panelClosingActions",{get:function(){var t=this;return d.merge(this.optionSelections,this.autocomplete._keyManager.tabOut.pipe(c.filter(function(){return t._overlayAttached})),this._closeKeyEventStream,this._getOutsideClickStream(),this._overlayRef?this._overlayRef.detachments().pipe(c.filter(function(){return t._overlayAttached})):d.of()).pipe(c.map(function(t){return t instanceof n.MatOptionSelectionChange?t:null}))},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"activeOption",{get:function(){return this.autocomplete&&this.autocomplete._keyManager?this.autocomplete._keyManager.activeItem:null},enumerable:!0,configurable:!0}),t.prototype._getOutsideClickStream=function(){var t=this;return d.merge(d.fromEvent(this._document,"click"),d.fromEvent(this._document,"touchend")).pipe(c.filter(function(e){var o=e.target,i=t._formField?t._formField._elementRef.nativeElement:null;return t._overlayAttached&&o!==t._element.nativeElement&&(!i||!i.contains(o))&&!!t._overlayRef&&!t._overlayRef.overlayElement.contains(o)}))},t.prototype.writeValue=function(t){var e=this;Promise.resolve(null).then(function(){return e._setTriggerValue(t)})},t.prototype.registerOnChange=function(t){this._onChange=t},t.prototype.registerOnTouched=function(t){this._onTouched=t},t.prototype.setDisabledState=function(t){this._element.nativeElement.disabled=t},t.prototype._handleKeydown=function(t){var e=t.keyCode;if(e===r.ESCAPE&&t.preventDefault(),this.activeOption&&e===r.ENTER&&this.panelOpen)this.activeOption._selectViaInteraction(),this._resetActiveItem(),t.preventDefault();else if(this.autocomplete){var o=this.autocomplete._keyManager.activeItem,i=e===r.UP_ARROW||e===r.DOWN_ARROW;this.panelOpen||e===r.TAB?this.autocomplete._keyManager.onKeydown(t):i&&this._canOpen()&&this.openPanel(),(i||this.autocomplete._keyManager.activeItem!==o)&&this._scrollToOption()}},t.prototype._handleInput=function(t){var e=t.target,o=e.value;"number"===e.type&&(o=""==o?null:parseFloat(o)),this._previousValue!==o&&(this._previousValue=o,this._onChange(o),this._canOpen()&&this._document.activeElement===t.target&&this.openPanel())},t.prototype._handleFocus=function(){this._canOpenOnNextFocus?this._canOpen()&&(this._previousValue=this._element.nativeElement.value,this._attachOverlay(),this._floatLabel(!0)):this._canOpenOnNextFocus=!0},t.prototype._floatLabel=function(t){void 0===t&&(t=!1),this._formField&&"auto"===this._formField.floatLabel&&(t?this._formField._animateAndLockLabel():this._formField.floatLabel="always",this._manuallyFloatingLabel=!0)},t.prototype._resetLabel=function(){this._manuallyFloatingLabel&&(this._formField.floatLabel="auto",this._manuallyFloatingLabel=!1)},t.prototype._scrollToOption=function(){var t=this.autocomplete._keyManager.activeItemIndex||0,e=n._countGroupLabelsBeforeOption(t,this.autocomplete.options,this.autocomplete.optionGroups),o=n._getOptionScrollPosition(t+e,48,this.autocomplete._getScrollTop(),256);this.autocomplete._setScrollTop(o)},t.prototype._subscribeToClosingActions=function(){var t=this,e=this._zone.onStable.asObservable().pipe(c.take(1)),o=this.autocomplete.options.changes.pipe(c.tap(function(){return t._positionStrategy.reapplyLastPosition()}),c.delay(0));return d.merge(e,o).pipe(c.switchMap(function(){var e=t.panelOpen;return t._resetActiveItem(),t.autocomplete._setVisibility(),t.panelOpen&&(t._overlayRef.updatePosition(),e!==t.panelOpen&&t.autocomplete.opened.emit()),t.panelClosingActions}),c.take(1)).subscribe(function(e){return t._setValueAndClose(e)})},t.prototype._destroyPanel=function(){this._overlayRef&&(this.closePanel(),this._overlayRef.dispose(),this._overlayRef=null)},t.prototype._setTriggerValue=function(t){var e=this.autocomplete&&this.autocomplete.displayWith?this.autocomplete.displayWith(t):t,o=null!=e?e:"";this._formField?this._formField._control.value=o:this._element.nativeElement.value=o,this._previousValue=o},t.prototype._setValueAndClose=function(t){t&&t.source&&(this._clearPreviousSelectedOption(t.source),this._setTriggerValue(t.source.value),this._onChange(t.source.value),this._element.nativeElement.focus(),this.autocomplete._emitSelectEvent(t.source)),this.closePanel()},t.prototype._clearPreviousSelectedOption=function(t){this.autocomplete.options.forEach(function(e){e!=t&&e.selected&&e.deselect()})},t.prototype._attachOverlay=function(){var t=this;if(!this.autocomplete)throw g();var e=this._overlayRef;e?(this._positionStrategy.setOrigin(this._getConnectedElement()),e.updateSize({width:this._getPanelWidth()})):(this._portal=new l.TemplatePortal(this.autocomplete.template,this._viewContainerRef),e=this._overlay.create(this._getOverlayConfig()),this._overlayRef=e,e.keydownEvents().subscribe(function(e){(e.keyCode===r.ESCAPE||e.keyCode===r.UP_ARROW&&e.altKey)&&(t._resetActiveItem(),t._closeKeyEventStream.next(),e.stopPropagation(),e.preventDefault())}),this._viewportRuler&&(this._viewportSubscription=this._viewportRuler.change().subscribe(function(){t.panelOpen&&e&&e.updateSize({width:t._getPanelWidth()})}))),e&&!e.hasAttached()&&(e.attach(this._portal),this._closingActionsSubscription=this._subscribeToClosingActions());var o=this.panelOpen;this.autocomplete._setVisibility(),this.autocomplete._isOpen=this._overlayAttached=!0,this.panelOpen&&o!==this.panelOpen&&this.autocomplete.opened.emit()},t.prototype._getOverlayConfig=function(){return new s.OverlayConfig({positionStrategy:this._getOverlayPosition(),scrollStrategy:this._scrollStrategy(),width:this._getPanelWidth(),direction:this._dir})},t.prototype._getOverlayPosition=function(){var t=this._overlay.position().flexibleConnectedTo(this._getConnectedElement()).withFlexibleDimensions(!1).withPush(!1);return this._setStrategyPositions(t),this._positionStrategy=t,t},t.prototype._setStrategyPositions=function(t){var e,o={originX:"start",originY:"bottom",overlayX:"start",overlayY:"top"},i={originX:"start",originY:"top",overlayX:"start",overlayY:"bottom",panelClass:"mat-autocomplete-panel-above"};e="above"===this.position?[i]:"below"===this.position?[o]:[o,i],t.withPositions(e)},t.prototype._getConnectedElement=function(){return this.connectedTo?this.connectedTo.elementRef:this._formField?this._formField.getConnectedOverlayOrigin():this._element},t.prototype._getPanelWidth=function(){return this.autocomplete.panelWidth||this._getHostWidth()},t.prototype._getHostWidth=function(){return this._getConnectedElement().nativeElement.getBoundingClientRect().width},t.prototype._resetActiveItem=function(){this.autocomplete._keyManager.setActiveItem(this.autocomplete.autoActiveFirstOption?0:-1)},t.prototype._canOpen=function(){var t=this._element.nativeElement;return!t.readOnly&&!t.disabled&&!this._autocompleteDisabled},t.decorators=[{type:i.Directive,args:[{selector:"input[matAutocomplete], textarea[matAutocomplete]",host:{"[attr.autocomplete]":"autocompleteAttribute","[attr.role]":'autocompleteDisabled ? null : "combobox"',"[attr.aria-autocomplete]":'autocompleteDisabled ? null : "list"',"[attr.aria-activedescendant]":"(panelOpen && activeOption) ? activeOption.id : null","[attr.aria-expanded]":"autocompleteDisabled ? null : panelOpen.toString()","[attr.aria-owns]":"(autocompleteDisabled || !panelOpen) ? null : autocomplete?.id","[attr.aria-haspopup]":"!autocompleteDisabled","(focusin)":"_handleFocus()","(blur)":"_onTouched()","(input)":"_handleInput($event)","(keydown)":"_handleKeydown($event)"},exportAs:"matAutocompleteTrigger",providers:[R]}]}],t.ctorParameters=function(){return[{type:i.ElementRef},{type:s.Overlay},{type:i.ViewContainerRef},{type:i.NgZone},{type:i.ChangeDetectorRef},{type:void 0,decorators:[{type:i.Inject,args:[w]}]},{type:a.Directionality,decorators:[{type:i.Optional}]},{type:m.MatFormField,decorators:[{type:i.Optional},{type:i.Host}]},{type:void 0,decorators:[{type:i.Optional},{type:i.Inject,args:[p.DOCUMENT]}]},{type:u.ViewportRuler}]},t.propDecorators={autocomplete:[{type:i.Input,args:["matAutocomplete"]}],position:[{type:i.Input,args:["matAutocompletePosition"]}],connectedTo:[{type:i.Input,args:["matAutocompleteConnectedTo"]}],autocompleteAttribute:[{type:i.Input,args:["autocomplete"]}],autocompleteDisabled:[{type:i.Input,args:["matAutocompleteDisabled"]}]},t}(),k=function(){function t(){}return t.decorators=[{type:i.NgModule,args:[{imports:[n.MatOptionModule,s.OverlayModule,n.MatCommonModule,p.CommonModule],exports:[P,n.MatOptionModule,M,T,n.MatCommonModule],declarations:[P,M,T],providers:[S]}]}],t}();t.MAT_AUTOCOMPLETE_DEFAULT_OPTIONS_FACTORY=y,t.MatAutocompleteSelectedEvent=b,t.MAT_AUTOCOMPLETE_DEFAULT_OPTIONS=C,t.MatAutocomplete=P,t.MatAutocompleteModule=k,t.MAT_AUTOCOMPLETE_SCROLL_STRATEGY_FACTORY=f,t.getMatAutocompleteMissingPanelError=g,t.AUTOCOMPLETE_OPTION_HEIGHT=48,t.AUTOCOMPLETE_PANEL_HEIGHT=256,t.MAT_AUTOCOMPLETE_SCROLL_STRATEGY=w,t.MAT_AUTOCOMPLETE_SCROLL_STRATEGY_FACTORY_PROVIDER=S,t.MAT_AUTOCOMPLETE_VALUE_ACCESSOR=R,t.MatAutocompleteTrigger=M,t.MatAutocompleteOrigin=T,Object.defineProperty(t,"__esModule",{value:!0})});
//# sourceMappingURL=material-autocomplete.umd.min.js.map