UNPKG

@angular/material

Version:
10 lines (9 loc) 14.9 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(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(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"],e):e((t.ng=t.ng||{},t.ng.material=t.ng.material||{},t.ng.material.autocomplete={}),t.ng.core,t.ng.material.core,t.ng.cdk.a11y,t.ng.cdk.coercion,t.ng.cdk.bidi,t.ng.cdk.keycodes,t.ng.cdk.overlay,t.ng.cdk.portal,t.ng.common,t.Rx.operators,t.ng.forms,t.ng.material.formField,t.Rx)}(this,function(t,e,o,i,n,a,r,s,l,p,c,u,h,m){"use strict";function _(t,e){function o(){this.constructor=t}y(t,e),t.prototype=null===e?Object.create(e):(o.prototype=e.prototype,new o)}function d(){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 y=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])},f=0,g=function(){function t(t,e){this.source=t,this.option=e}return t}(),v=function(){function t(){}return t}(),O=o.mixinDisableRipple(v),b=new e.InjectionToken("mat-autocomplete-default-options",{providedIn:"root",factory:function(){return{autoActiveFirstOption:!1}}}),A=function(t){function a(o,i,n){var a=t.call(this)||this;return a._changeDetectorRef=o,a._elementRef=i,a.showPanel=!1,a._isOpen=!1,a.displayWith=null,a.optionSelected=new e.EventEmitter,a.opened=new e.EventEmitter,a.closed=new e.EventEmitter,a._classList={},a.id="mat-autocomplete-"+f++,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=n.coerceBooleanProperty(t)},enumerable:!0,configurable:!0}),Object.defineProperty(a.prototype,"classList",{set:function(t){var e=this;t&&t.length&&(t.split(" ").forEach(function(t){return e._classList[t.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(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._classList["mat-autocomplete-visible"]=this.showPanel,this._classList["mat-autocomplete-hidden"]=!this.showPanel,this._changeDetectorRef.markForCheck()},a.prototype._emitSelectEvent=function(t){var e=new g(this,t);this.optionSelected.emit(e)},a.decorators=[{type:e.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}"],encapsulation:e.ViewEncapsulation.None,changeDetection:e.ChangeDetectionStrategy.OnPush,exportAs:"matAutocomplete",inputs:["disableRipple"],host:{class:"mat-autocomplete"},providers:[{provide:o.MAT_OPTION_PARENT_COMPONENT,useExisting:a}]}]}],a.ctorParameters=function(){return[{type:e.ChangeDetectorRef},{type:e.ElementRef},{type:void 0,decorators:[{type:e.Inject,args:[b]}]}]},a.propDecorators={template:[{type:e.ViewChild,args:[e.TemplateRef]}],panel:[{type:e.ViewChild,args:["panel"]}],options:[{type:e.ContentChildren,args:[o.MatOption,{descendants:!0}]}],optionGroups:[{type:e.ContentChildren,args:[o.MatOptgroup]}],displayWith:[{type:e.Input}],autoActiveFirstOption:[{type:e.Input}],optionSelected:[{type:e.Output}],opened:[{type:e.Output}],closed:[{type:e.Output}],classList:[{type:e.Input,args:["class"]}]},a}(O),E=new e.InjectionToken("mat-autocomplete-scroll-strategy",{providedIn:"root",factory:function(){var t=e.inject(s.Overlay);return function(){return t.scrollStrategies.reposition()}}}),C={provide:u.NG_VALUE_ACCESSOR,useExisting:e.forwardRef(function(){return w}),multi:!0},w=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._scrollStrategy=a,this._dir=r,this._formField=s,this._document=l,this._viewportRuler=p,this._componentDestroyed=!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(t){return t.onSelectionChange})):u._zone.onStable.asObservable().pipe(c.take(1),c.switchMap(function(){return u.optionSelections}))})}return t.prototype.ngOnDestroy=function(){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())},Object.defineProperty(t.prototype,"panelClosingActions",{get:function(){var t=this;return m.merge(this.optionSelections,this.autocomplete._keyManager.tabOut.pipe(c.filter(function(){return t._overlayAttached})),this._closeKeyEventStream,this._outsideClickStream,this._overlayRef?this._overlayRef.detachments().pipe(c.filter(function(){return t._overlayAttached})):m.of())},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}),Object.defineProperty(t.prototype,"_outsideClickStream",{get:function(){var t=this;return this._document?m.merge(m.fromEvent(this._document,"click"),m.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)})):m.of(null)},enumerable:!0,configurable:!0}),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.panelOpen&&(e===r.ESCAPE||e===r.UP_ARROW&&t.altKey))this._resetActiveItem(),this._closeKeyEventStream.next(),t.stopPropagation();else if(this.activeOption&&e===r.ENTER&&this.panelOpen)this.activeOption._selectViaInteraction(),this._resetActiveItem(),t.preventDefault();else{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._canOpen()&&this._previousValue!==o&&document.activeElement===t.target&&(this._previousValue=o,this._onChange(o),this.openPanel())},t.prototype._handleFocus=function(){this._canOpen()&&(this._previousValue=this._element.nativeElement.value,this._attachOverlay(),this._floatLabel(!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=o._countGroupLabelsBeforeOption(t,this.autocomplete.options,this.autocomplete.optionGroups),i=o._getOptionScrollPosition(t+e,48,this.autocomplete._getScrollTop(),256);this.autocomplete._setScrollTop(i)},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 m.merge(e,o).pipe(c.switchMap(function(){return t._resetActiveItem(),t.autocomplete._setVisibility(),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},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 d();this._overlayRef?this._overlayRef.updateSize({width:this._getHostWidth()}):(this._portal=new l.TemplatePortal(this.autocomplete.template,this._viewContainerRef),this._overlayRef=this._overlay.create(this._getOverlayConfig()),this._viewportRuler&&(this._viewportSubscription=this._viewportRuler.change().subscribe(function(){t.panelOpen&&t._overlayRef&&t._overlayRef.updateSize({width:t._getHostWidth()})}))),this._overlayRef&&!this._overlayRef.hasAttached()&&(this._overlayRef.attach(this._portal),this._closingActionsSubscription=this._subscribeToClosingActions());var e=this.panelOpen;this.autocomplete._setVisibility(),this.autocomplete._isOpen=this._overlayAttached=!0,this.panelOpen&&e!==this.panelOpen&&this.autocomplete.opened.emit()},t.prototype._getOverlayConfig=function(){return new s.OverlayConfig({positionStrategy:this._getOverlayPosition(),scrollStrategy:this._scrollStrategy(),width:this._getHostWidth(),direction:this._dir?this._dir.value:"ltr"})},t.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},t.prototype._getConnectedElement=function(){return this._formField?this._formField.getConnectedOverlayOrigin():this._element},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},t.decorators=[{type:e.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:[C]}]}],t.ctorParameters=function(){return[{type:e.ElementRef},{type:s.Overlay},{type:e.ViewContainerRef},{type:e.NgZone},{type:e.ChangeDetectorRef},{type:void 0,decorators:[{type:e.Inject,args:[E]}]},{type:a.Directionality,decorators:[{type:e.Optional}]},{type:h.MatFormField,decorators:[{type:e.Optional},{type:e.Host}]},{type:Document,decorators:[{type:e.Optional},{type:e.Inject,args:[p.DOCUMENT]}]},{type:s.ViewportRuler}]},t.propDecorators={autocomplete:[{type:e.Input,args:["matAutocomplete"]}]},t}(),P=function(){function t(){}return t.decorators=[{type:e.NgModule,args:[{imports:[o.MatOptionModule,s.OverlayModule,o.MatCommonModule,p.CommonModule],exports:[A,o.MatOptionModule,w,o.MatCommonModule],declarations:[A,w]}]}],t}();t.MatAutocompleteSelectedEvent=g,t.MatAutocompleteBase=v,t._MatAutocompleteMixinBase=O,t.MAT_AUTOCOMPLETE_DEFAULT_OPTIONS=b,t.MatAutocomplete=A,t.MatAutocompleteModule=P,t.AUTOCOMPLETE_OPTION_HEIGHT=48,t.AUTOCOMPLETE_PANEL_HEIGHT=256,t.MAT_AUTOCOMPLETE_SCROLL_STRATEGY=E,t.MAT_AUTOCOMPLETE_VALUE_ACCESSOR=C,t.getMatAutocompleteMissingPanelError=d,t.MatAutocompleteTrigger=w,Object.defineProperty(t,"__esModule",{value:!0})}); //# sourceMappingURL=material-autocomplete.umd.min.js.map