UNPKG

@angular/material

Version:
10 lines (9 loc) 15 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/common"),require("@angular/cdk/overlay"),require("@angular/cdk/bidi"),require("@angular/cdk/keycodes"),require("@angular/cdk/portal"),require("rxjs/operators/filter"),require("rxjs/operators/take"),require("rxjs/operators/switchMap"),require("rxjs/operators/tap"),require("rxjs/operators/delay"),require("@angular/forms"),require("@angular/material/form-field"),require("rxjs/Subject"),require("rxjs/observable/defer"),require("rxjs/observable/fromEvent"),require("rxjs/observable/merge"),require("rxjs/observable/of")):"function"==typeof define&&define.amd?define(["exports","@angular/core","@angular/material/core","@angular/cdk/a11y","@angular/cdk/coercion","@angular/common","@angular/cdk/overlay","@angular/cdk/bidi","@angular/cdk/keycodes","@angular/cdk/portal","rxjs/operators/filter","rxjs/operators/take","rxjs/operators/switchMap","rxjs/operators/tap","rxjs/operators/delay","@angular/forms","@angular/material/form-field","rxjs/Subject","rxjs/observable/defer","rxjs/observable/fromEvent","rxjs/observable/merge","rxjs/observable/of"],t):t((e.ng=e.ng||{},e.ng.material=e.ng.material||{},e.ng.material.autocomplete=e.ng.material.autocomplete||{}),e.ng.core,e.ng.material.core,e.ng.cdk.a11y,e.ng.cdk.coercion,e.ng.common,e.ng.cdk.overlay,e.ng.cdk.bidi,e.ng.cdk.keycodes,e.ng.cdk.portal,e.Rx.operators,e.Rx.operators,e.Rx.operators,e.Rx.operators,e.Rx.operators,e.ng.forms,e.ng.material.formField,e.Rx,e.Rx.Observable,e.Rx.Observable,e.Rx.Observable,e.Rx.Observable)}(this,function(e,t,o,i,n,r,a,s,l,p,c,u,h,m,_,d,f,y,g,v,b,O){"use strict";function A(e,t){function o(){this.constructor=e}C(e,t),e.prototype=null===t?Object.create(t):(o.prototype=t.prototype,new o)}function E(e){return function(){return e.scrollStrategies.reposition()}}function R(){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 C=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])},x=0,T=function(){function e(e,t){this.source=e,this.option=t}return e}(),P=function(){function e(){}return e}(),M=o.mixinDisableRipple(P),S=new t.InjectionToken("mat-autocomplete-default-options"),k=function(e){function r(o,i,n){var r=e.call(this)||this;return r._changeDetectorRef=o,r._elementRef=i,r.showPanel=!1,r._isOpen=!1,r.displayWith=null,r.optionSelected=new t.EventEmitter,r._classList={},r.id="mat-autocomplete-"+x++,r._autoActiveFirstOption=!(!n||void 0===n.autoActiveFirstOption)&&n.autoActiveFirstOption,r}return A(r,e),Object.defineProperty(r.prototype,"isOpen",{get:function(){return this._isOpen&&this.showPanel},enumerable:!0,configurable:!0}),Object.defineProperty(r.prototype,"autoActiveFirstOption",{get:function(){return this._autoActiveFirstOption},set:function(e){this._autoActiveFirstOption=n.coerceBooleanProperty(e)},enumerable:!0,configurable:!0}),Object.defineProperty(r.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}),r.prototype.ngAfterContentInit=function(){this._keyManager=new i.ActiveDescendantKeyManager(this.options).withWrap(),this._setVisibility()},r.prototype._setScrollTop=function(e){this.panel&&(this.panel.nativeElement.scrollTop=e)},r.prototype._getScrollTop=function(){return this.panel?this.panel.nativeElement.scrollTop:0},r.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()},r.prototype._emitSelectEvent=function(e){var t=new T(this,e);this.optionSelected.emit(t)},r.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{-webkit-backface-visibility:hidden;backface-visibility:hidden;min-width:112px;max-width:280px;overflow:auto;-webkit-overflow-scrolling:touch;visibility:hidden;max-width:none;max-height:256px;position:relative}.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}"],encapsulation:t.ViewEncapsulation.None,preserveWhitespaces:!1,changeDetection:t.ChangeDetectionStrategy.OnPush,exportAs:"matAutocomplete",inputs:["disableRipple"],host:{class:"mat-autocomplete"},providers:[{provide:o.MAT_OPTION_PARENT_COMPONENT,useExisting:r}]}]}],r.ctorParameters=function(){return[{type:t.ChangeDetectorRef},{type:t.ElementRef},{type:void 0,decorators:[{type:t.Optional},{type:t.Inject,args:[S]}]}]},r.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}],classList:[{type:t.Input,args:["class"]}]},r}(M),w=new t.InjectionToken("mat-autocomplete-scroll-strategy"),L={provide:w,deps:[a.Overlay],useFactory:E},j={provide:d.NG_VALUE_ACCESSOR,useExisting:t.forwardRef(function(){return F}),multi:!0},F=function(){function e(e,t,o,i,n,r,a,s,l){var p=this;this._element=e,this._overlay=t,this._viewContainerRef=o,this._zone=i,this._changeDetectorRef=n,this._scrollStrategy=r,this._dir=a,this._formField=s,this._document=l,this._componentDestroyed=!1,this._manuallyFloatingLabel=!1,this._closeKeyEventStream=new y.Subject,this._onChange=function(){},this._onTouched=function(){},this._panelOpen=!1,this.optionSelections=g.defer(function(){return p.autocomplete&&p.autocomplete.options?b.merge.apply(void 0,p.autocomplete.options.map(function(e){return e.onSelectionChange})):p._zone.onStable.asObservable().pipe(u.take(1),h.switchMap(function(){return p.optionSelections}))})}return e.prototype.ngOnDestroy=function(){this._componentDestroyed=!0,this._destroyPanel(),this._closeKeyEventStream.complete()},Object.defineProperty(e.prototype,"panelOpen",{get:function(){return this._panelOpen&&this.autocomplete.showPanel},enumerable:!0,configurable:!0}),e.prototype.openPanel=function(){this._attachOverlay(),this._floatLabel()},e.prototype.closePanel=function(){this._resetLabel(),this._panelOpen&&(this.autocomplete._isOpen=this._panelOpen=!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 b.merge(this.optionSelections,this.autocomplete._keyManager.tabOut.pipe(c.filter(function(){return e._panelOpen})),this._closeKeyEventStream,this._outsideClickStream,this._overlayRef?this._overlayRef.detachments().pipe(c.filter(function(){return e._panelOpen})):O.of())},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?b.merge(v.fromEvent(this._document,"click"),v.fromEvent(this._document,"touchend")).pipe(c.filter(function(t){var o=t.target,i=e._formField?e._formField._elementRef.nativeElement:null;return e._panelOpen&&o!==e._element.nativeElement&&(!i||!i.contains(o))&&!!e._overlayRef&&!e._overlayRef.overlayElement.contains(o)})):O.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===l.ESCAPE&&e.preventDefault(),this.panelOpen&&(t===l.ESCAPE||t===l.UP_ARROW&&e.altKey))this._resetActiveItem(),this._closeKeyEventStream.next(),e.stopPropagation();else if(this.activeOption&&t===l.ENTER&&this.panelOpen)this.activeOption._selectViaInteraction(),this._resetActiveItem(),e.preventDefault();else{var o=this.autocomplete._keyManager.activeItem,i=t===l.UP_ARROW||t===l.DOWN_ARROW;this.panelOpen||t===l.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._canOpen()&&this._previousValue!==o&&document.activeElement===e.target&&(this._previousValue=o,this._onChange(o),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(u.take(1)),o=this.autocomplete.options.changes.pipe(m.tap(function(){return e._positionStrategy.recalculateLastPosition()}),_.delay(0));return b.merge(t,o).pipe(h.switchMap(function(){return e._resetActiveItem(),e.autocomplete._setVisibility(),e.panelClosingActions}),u.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(){if(!this.autocomplete)throw R();this._overlayRef?this._overlayRef.updateSize({width:this._getHostWidth()}):(this._portal=new p.TemplatePortal(this.autocomplete.template,this._viewContainerRef),this._overlayRef=this._overlay.create(this._getOverlayConfig())),this._overlayRef&&!this._overlayRef.hasAttached()&&(this._overlayRef.attach(this._portal),this._closingActionsSubscription=this._subscribeToClosingActions()),this.autocomplete._setVisibility(),this.autocomplete._isOpen=this._panelOpen=!0},e.prototype._getOverlayConfig=function(){return new a.OverlayConfig({positionStrategy:this._getOverlayPosition(),scrollStrategy:this._scrollStrategy(),width:this._getHostWidth(),direction:this._dir?this._dir.value:"ltr"})},e.prototype._getOverlayPosition=function(){return this._positionStrategy=this._overlay.position().connectedTo(this._getConnectedElement(),{originX:"start",originY:"bottom"},{overlayX:"start",overlayY:"top"}).withFallbackPosition({originX:"start",originY:"top"},{overlayX:"start",overlayY:"bottom"}),this._positionStrategy},e.prototype._getConnectedElement=function(){return this._formField?this._formField._connectionContainerRef: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},e.decorators=[{type:t.Directive,args:[{selector:"input[matAutocomplete], textarea[matAutocomplete]",host:{role:"combobox",autocomplete:"off","aria-autocomplete":"list","[attr.aria-activedescendant]":"activeOption?.id","[attr.aria-expanded]":"panelOpen.toString()","[attr.aria-owns]":"autocomplete?.id","(focusin)":"_handleFocus()","(blur)":"_onTouched()","(input)":"_handleInput($event)","(keydown)":"_handleKeydown($event)"},exportAs:"matAutocompleteTrigger",providers:[j]}]}],e.ctorParameters=function(){return[{type:t.ElementRef},{type:a.Overlay},{type:t.ViewContainerRef},{type:t.NgZone},{type:t.ChangeDetectorRef},{type:void 0,decorators:[{type:t.Inject,args:[w]}]},{type:s.Directionality,decorators:[{type:t.Optional}]},{type:f.MatFormField,decorators:[{type:t.Optional},{type:t.Host}]},{type:void 0,decorators:[{type:t.Optional},{type:t.Inject,args:[r.DOCUMENT]}]}]},e.propDecorators={autocomplete:[{type:t.Input,args:["matAutocomplete"]}]},e}(),I=function(){function e(){}return e.decorators=[{type:t.NgModule,args:[{imports:[o.MatOptionModule,a.OverlayModule,o.MatCommonModule,r.CommonModule],exports:[k,o.MatOptionModule,F,o.MatCommonModule],declarations:[k,F],providers:[L]}]}],e.ctorParameters=function(){return[]},e}();e.MatAutocompleteSelectedEvent=T,e.MatAutocompleteBase=P,e._MatAutocompleteMixinBase=M,e.MAT_AUTOCOMPLETE_DEFAULT_OPTIONS=S,e.MatAutocomplete=k,e.MatAutocompleteModule=I,e.AUTOCOMPLETE_OPTION_HEIGHT=48,e.AUTOCOMPLETE_PANEL_HEIGHT=256,e.MAT_AUTOCOMPLETE_SCROLL_STRATEGY=w,e.MAT_AUTOCOMPLETE_SCROLL_STRATEGY_PROVIDER_FACTORY=E,e.MAT_AUTOCOMPLETE_SCROLL_STRATEGY_PROVIDER=L,e.MAT_AUTOCOMPLETE_VALUE_ACCESSOR=j,e.getMatAutocompleteMissingPanelError=R,e.MatAutocompleteTrigger=F,Object.defineProperty(e,"__esModule",{value:!0})}); //# sourceMappingURL=material-autocomplete.umd.min.js.map