UNPKG

@angular/material

Version:
10 lines (9 loc) 16 kB
/** * @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(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("@angular/core"),require("@angular/material/core"),require("@angular/cdk/a11y"),require("@angular/cdk/coercion"),require("@angular/cdk/bidi"),require("@angular/cdk/keycodes"),require("@angular/cdk/overlay"),require("@angular/cdk/portal"),require("@angular/common"),require("rxjs/operators"),require("@angular/forms"),require("@angular/material/form-field"),require("rxjs")):"function"==typeof define&&define.amd?define("@angular/material/autocomplete",["exports","@angular/core","@angular/material/core","@angular/cdk/a11y","@angular/cdk/coercion","@angular/cdk/bidi","@angular/cdk/keycodes","@angular/cdk/overlay","@angular/cdk/portal","@angular/common","rxjs/operators","@angular/forms","@angular/material/form-field","rxjs"],t):t((e.ng=e.ng||{},e.ng.material=e.ng.material||{},e.ng.material.autocomplete={}),e.ng.core,e.ng.material.core,e.ng.cdk.a11y,e.ng.cdk.coercion,e.ng.cdk.bidi,e.ng.cdk.keycodes,e.ng.cdk.overlay,e.ng.cdk.portal,e.ng.common,e.rxjs.operators,e.ng.forms,e.ng.material.formField,e.rxjs)}(this,function(e,t,o,i,n,a,r,l,s,p,c,u,h,m){"use strict";function d(e,t){function o(){this.constructor=e}g(e,t),e.prototype=null===t?Object.create(t):(o.prototype=t.prototype,new o)}function _(){return{autoActiveFirstOption:!1}}function y(e){return function(){return e.scrollStrategies.reposition()}}function f(){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 g=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var o in t)t.hasOwnProperty(o)&&(e[o]=t[o])},v=0,O=function(){function e(e,t){this.source=e,this.option=t}return e}(),b=function(){function e(){}return e}(),A=o.mixinDisableRipple(b),E=new t.InjectionToken("mat-autocomplete-default-options",{providedIn:"root",factory:_}),T=function(e){function a(o,i,n){var a=e.call(this)||this;return a._changeDetectorRef=o,a._elementRef=i,a.showPanel=!1,a._isOpen=!1,a.displayWith=null,a.optionSelected=new t.EventEmitter,a.opened=new t.EventEmitter,a.closed=new t.EventEmitter,a._classList={},a.id="mat-autocomplete-"+v++,a._autoActiveFirstOption=!!n.autoActiveFirstOption,a}return d(a,e),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(e){this._autoActiveFirstOption=n.coerceBooleanProperty(e)},enumerable:!0,configurable:!0}),Object.defineProperty(a.prototype,"classList",{set:function(e){var t=this;e&&e.length&&(e.split(" ").forEach(function(e){return t._classList[e.trim()]=!0}),this._elementRef.nativeElement.className="")},enumerable:!0,configurable:!0}),a.prototype.ngAfterContentInit=function(){this._keyManager=new i.ActiveDescendantKeyManager(this.options).withWrap(),this._setVisibility()},a.prototype._setScrollTop=function(e){this.panel&&(this.panel.nativeElement.scrollTop=e)},a.prototype._getScrollTop=function(){return this.panel?this.panel.nativeElement.scrollTop:0},a.prototype._setVisibility=function(){this.showPanel=!!this.options.length,this._classList["mat-autocomplete-visible"]=this.showPanel,this._classList["mat-autocomplete-hidden"]=!this.showPanel,this._changeDetectorRef.markForCheck()},a.prototype._emitSelectEvent=function(e){var t=new O(this,e);this.optionSelected.emit(t)},a.decorators=[{type:t.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%}.mat-autocomplete-panel:not([class*=mat-elevation-z]){box-shadow:0 5px 5px -3px rgba(0,0,0,.2),0 8px 10px 1px rgba(0,0,0,.14),0 3px 14px 2px rgba(0,0,0,.12)}.mat-autocomplete-panel.mat-autocomplete-visible{visibility:visible}.mat-autocomplete-panel.mat-autocomplete-hidden{visibility:hidden}@media screen and (-ms-high-contrast:active){.mat-autocomplete-panel{outline:solid 1px}}"],encapsulation:t.ViewEncapsulation.None,changeDetection:t.ChangeDetectionStrategy.OnPush,exportAs:"matAutocomplete",inputs:["disableRipple"],host:{class:"mat-autocomplete"},providers:[{provide:o.MAT_OPTION_PARENT_COMPONENT,useExisting:a}]}]}],a.ctorParameters=function(){return[{type:t.ChangeDetectorRef},{type:t.ElementRef},{type:void 0,decorators:[{type:t.Inject,args:[E]}]}]},a.propDecorators={template:[{type:t.ViewChild,args:[t.TemplateRef]}],panel:[{type:t.ViewChild,args:["panel"]}],options:[{type:t.ContentChildren,args:[o.MatOption,{descendants:!0}]}],optionGroups:[{type:t.ContentChildren,args:[o.MatOptgroup]}],displayWith:[{type:t.Input}],autoActiveFirstOption:[{type:t.Input}],optionSelected:[{type:t.Output}],opened:[{type:t.Output}],closed:[{type:t.Output}],classList:[{type:t.Input,args:["class"]}]},a}(A),C=function(){function e(e){this.elementRef=e}return e.decorators=[{type:t.Directive,args:[{selector:"[matAutocompleteOrigin]",exportAs:"matAutocompleteOrigin"}]}],e.ctorParameters=function(){return[{type:t.ElementRef}]},e}(),R=new t.InjectionToken("mat-autocomplete-scroll-strategy"),P={provide:R,deps:[l.Overlay],useFactory:y},S={provide:u.NG_VALUE_ACCESSOR,useExisting:t.forwardRef(function(){return w}),multi:!0},w=function(){function e(e,t,o,i,n,a,r,l,s,p){var u=this;this._element=e,this._overlay=t,this._viewContainerRef=o,this._zone=i,this._changeDetectorRef=n,this._scrollStrategy=a,this._dir=r,this._formField=l,this._document=s,this._viewportRuler=p,this._componentDestroyed=!1,this._autocompleteDisabled=!1,this._manuallyFloatingLabel=!1,this._viewportSubscription=m.Subscription.EMPTY,this._closeKeyEventStream=new m.Subject,this._onChange=function(){},this._onTouched=function(){},this._overlayAttached=!1,this.optionSelections=m.defer(function(){return u.autocomplete&&u.autocomplete.options?m.merge.apply(void 0,u.autocomplete.options.map(function(e){return e.onSelectionChange})):u._zone.onStable.asObservable().pipe(c.take(1),c.switchMap(function(){return u.optionSelections}))})}return Object.defineProperty(e.prototype,"autocompleteDisabled",{get:function(){return this._autocompleteDisabled},set:function(e){this._autocompleteDisabled=n.coerceBooleanProperty(e)},enumerable:!0,configurable:!0}),e.prototype.ngOnDestroy=function(){this._viewportSubscription.unsubscribe(),this._componentDestroyed=!0,this._destroyPanel(),this._closeKeyEventStream.complete()},Object.defineProperty(e.prototype,"panelOpen",{get:function(){return this._overlayAttached&&this.autocomplete.showPanel},enumerable:!0,configurable:!0}),e.prototype.openPanel=function(){this._attachOverlay(),this._floatLabel()},e.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())},Object.defineProperty(e.prototype,"panelClosingActions",{get:function(){var e=this;return m.merge(this.optionSelections,this.autocomplete._keyManager.tabOut.pipe(c.filter(function(){return e._overlayAttached})),this._closeKeyEventStream,this._outsideClickStream,this._overlayRef?this._overlayRef.detachments().pipe(c.filter(function(){return e._overlayAttached})):m.of()).pipe(c.map(function(e){return e instanceof o.MatOptionSelectionChange?e:null}))},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"activeOption",{get:function(){return this.autocomplete&&this.autocomplete._keyManager?this.autocomplete._keyManager.activeItem:null},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"_outsideClickStream",{get:function(){var e=this;return this._document?m.merge(m.fromEvent(this._document,"click"),m.fromEvent(this._document,"touchend")).pipe(c.filter(function(t){var o=t.target,i=e._formField?e._formField._elementRef.nativeElement:null;return e._overlayAttached&&o!==e._element.nativeElement&&(!i||!i.contains(o))&&!!e._overlayRef&&!e._overlayRef.overlayElement.contains(o)})):m.of(null)},enumerable:!0,configurable:!0}),e.prototype.writeValue=function(e){var t=this;Promise.resolve(null).then(function(){return t._setTriggerValue(e)})},e.prototype.registerOnChange=function(e){this._onChange=e},e.prototype.registerOnTouched=function(e){this._onTouched=e},e.prototype.setDisabledState=function(e){this._element.nativeElement.disabled=e},e.prototype._handleKeydown=function(e){var t=e.keyCode;if(t===r.ESCAPE&&e.preventDefault(),this.panelOpen&&(t===r.ESCAPE||t===r.UP_ARROW&&e.altKey))this._resetActiveItem(),this._closeKeyEventStream.next(),e.stopPropagation();else if(this.activeOption&&t===r.ENTER&&this.panelOpen)this.activeOption._selectViaInteraction(),this._resetActiveItem(),e.preventDefault();else{var o=this.autocomplete._keyManager.activeItem,i=t===r.UP_ARROW||t===r.DOWN_ARROW;this.panelOpen||t===r.TAB?this.autocomplete._keyManager.onKeydown(e):i&&this._canOpen()&&this.openPanel(),(i||this.autocomplete._keyManager.activeItem!==o)&&this._scrollToOption()}},e.prototype._handleInput=function(e){var t=e.target,o=t.value;"number"===t.type&&(o=""==o?null:parseFloat(o)),this._previousValue!==o&&document.activeElement===e.target&&(this._previousValue=o,this._onChange(o),this._canOpen()&&this.openPanel())},e.prototype._handleFocus=function(){this._canOpen()&&(this._previousValue=this._element.nativeElement.value,this._attachOverlay(),this._floatLabel(!0))},e.prototype._floatLabel=function(e){void 0===e&&(e=!1),this._formField&&"auto"===this._formField.floatLabel&&(e?this._formField._animateAndLockLabel():this._formField.floatLabel="always",this._manuallyFloatingLabel=!0)},e.prototype._resetLabel=function(){this._manuallyFloatingLabel&&(this._formField.floatLabel="auto",this._manuallyFloatingLabel=!1)},e.prototype._scrollToOption=function(){var e=this.autocomplete._keyManager.activeItemIndex||0,t=o._countGroupLabelsBeforeOption(e,this.autocomplete.options,this.autocomplete.optionGroups),i=o._getOptionScrollPosition(e+t,48,this.autocomplete._getScrollTop(),256);this.autocomplete._setScrollTop(i)},e.prototype._subscribeToClosingActions=function(){var e=this,t=this._zone.onStable.asObservable().pipe(c.take(1)),o=this.autocomplete.options.changes.pipe(c.tap(function(){return e._positionStrategy.reapplyLastPosition()}),c.delay(0));return m.merge(t,o).pipe(c.switchMap(function(){return e._resetActiveItem(),e.autocomplete._setVisibility(),e.panelClosingActions}),c.take(1)).subscribe(function(t){return e._setValueAndClose(t)})},e.prototype._destroyPanel=function(){this._overlayRef&&(this.closePanel(),this._overlayRef.dispose(),this._overlayRef=null)},e.prototype._setTriggerValue=function(e){var t=this.autocomplete&&this.autocomplete.displayWith?this.autocomplete.displayWith(e):e,o=null!=t?t:"";this._formField?this._formField._control.value=o:this._element.nativeElement.value=o},e.prototype._setValueAndClose=function(e){e&&e.source&&(this._clearPreviousSelectedOption(e.source),this._setTriggerValue(e.source.value),this._onChange(e.source.value),this._element.nativeElement.focus(),this.autocomplete._emitSelectEvent(e.source)),this.closePanel()},e.prototype._clearPreviousSelectedOption=function(e){this.autocomplete.options.forEach(function(t){t!=e&&t.selected&&t.deselect()})},e.prototype._attachOverlay=function(){var e=this;if(!this.autocomplete)throw f();this._overlayRef?this._overlayRef.updateSize({width:this._getHostWidth()}):(this._portal=new s.TemplatePortal(this.autocomplete.template,this._viewContainerRef),this._overlayRef=this._overlay.create(this._getOverlayConfig()),this._viewportRuler&&(this._viewportSubscription=this._viewportRuler.change().subscribe(function(){e.panelOpen&&e._overlayRef&&e._overlayRef.updateSize({width:e._getHostWidth()})}))),this._overlayRef&&!this._overlayRef.hasAttached()&&(this._overlayRef.attach(this._portal),this._closingActionsSubscription=this._subscribeToClosingActions());var t=this.panelOpen;this.autocomplete._setVisibility(),this.autocomplete._isOpen=this._overlayAttached=!0,this.panelOpen&&t!==this.panelOpen&&this.autocomplete.opened.emit()},e.prototype._getOverlayConfig=function(){return new l.OverlayConfig({positionStrategy:this._getOverlayPosition(),scrollStrategy:this._scrollStrategy(),width:this._getHostWidth(),direction:this._dir})},e.prototype._getOverlayPosition=function(){return this._positionStrategy=this._overlay.position().flexibleConnectedTo(this._getConnectedElement()).withFlexibleDimensions(!1).withPush(!1).withPositions([{originX:"start",originY:"bottom",overlayX:"start",overlayY:"top"},{originX:"start",originY:"top",overlayX:"start",overlayY:"bottom"}]),this._positionStrategy},e.prototype._getConnectedElement=function(){return this.connectedTo?this.connectedTo.elementRef:this._formField?this._formField.getConnectedOverlayOrigin():this._element},e.prototype._getHostWidth=function(){return this._getConnectedElement().nativeElement.getBoundingClientRect().width},e.prototype._resetActiveItem=function(){this.autocomplete._keyManager.setActiveItem(this.autocomplete.autoActiveFirstOption?0:-1)},e.prototype._canOpen=function(){var e=this._element.nativeElement;return!e.readOnly&&!e.disabled&&!this._autocompleteDisabled},e.decorators=[{type:t.Directive,args:[{selector:"input[matAutocomplete], textarea[matAutocomplete]",host:{autocomplete:"off","[attr.role]":'autocompleteDisabled ? null : "combobox"',"[attr.aria-autocomplete]":'autocompleteDisabled ? null : "list"',"[attr.aria-activedescendant]":"activeOption?.id","[attr.aria-expanded]":"autocompleteDisabled ? null : panelOpen.toString()","[attr.aria-owns]":"autocompleteDisabled ? null : autocomplete?.id","(focusin)":"_handleFocus()","(blur)":"_onTouched()","(input)":"_handleInput($event)","(keydown)":"_handleKeydown($event)"},exportAs:"matAutocompleteTrigger",providers:[S]}]}],e.ctorParameters=function(){return[{type:t.ElementRef},{type:l.Overlay},{type:t.ViewContainerRef},{type:t.NgZone},{type:t.ChangeDetectorRef},{type:void 0,decorators:[{type:t.Inject,args:[R]}]},{type:a.Directionality,decorators:[{type:t.Optional}]},{type:h.MatFormField,decorators:[{type:t.Optional},{type:t.Host}]},{type:void 0,decorators:[{type:t.Optional},{type:t.Inject,args:[p.DOCUMENT]}]},{type:l.ViewportRuler}]},e.propDecorators={autocomplete:[{type:t.Input,args:["matAutocomplete"]}],connectedTo:[{type:t.Input,args:["matAutocompleteConnectedTo"]}],autocompleteDisabled:[{type:t.Input,args:["matAutocompleteDisabled"]}]},e}(),M=function(){function e(){}return e.decorators=[{type:t.NgModule,args:[{imports:[o.MatOptionModule,l.OverlayModule,o.MatCommonModule,p.CommonModule],exports:[T,o.MatOptionModule,w,C,o.MatCommonModule],declarations:[T,w,C],providers:[P]}]}],e}();e.MatAutocompleteSelectedEvent=O,e.MatAutocompleteBase=b,e._MatAutocompleteMixinBase=A,e.MAT_AUTOCOMPLETE_DEFAULT_OPTIONS=E,e.MAT_AUTOCOMPLETE_DEFAULT_OPTIONS_FACTORY=_,e.MatAutocomplete=T,e.MatAutocompleteModule=M,e.AUTOCOMPLETE_OPTION_HEIGHT=48,e.AUTOCOMPLETE_PANEL_HEIGHT=256,e.MAT_AUTOCOMPLETE_SCROLL_STRATEGY=R,e.MAT_AUTOCOMPLETE_SCROLL_STRATEGY_FACTORY=y,e.MAT_AUTOCOMPLETE_SCROLL_STRATEGY_FACTORY_PROVIDER=P,e.MAT_AUTOCOMPLETE_VALUE_ACCESSOR=S,e.getMatAutocompleteMissingPanelError=f,e.MatAutocompleteTrigger=w,e.ɵa28=C,Object.defineProperty(e,"__esModule",{value:!0})}); //# sourceMappingURL=material-autocomplete.umd.min.js.map