Skip to content

feat(autocomplete): allow option ripples to be disabled #8851

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 4, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/lib/autocomplete/autocomplete.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1521,7 +1521,6 @@ describe('MatAutocomplete', () => {
expect(panel.classList).toContain('class-two');
}));


it('should reset correctly when closed programmatically', fakeAsync(() => {
TestBed.overrideProvider(MAT_AUTOCOMPLETE_SCROLL_STRATEGY, {
useFactory: (overlay: Overlay) => () => overlay.scrollStrategies.close(),
Expand Down Expand Up @@ -1673,7 +1672,8 @@ describe('MatAutocomplete', () => {
<input matInput placeholder="State" [matAutocomplete]="auto" [formControl]="stateCtrl">
</mat-form-field>

<mat-autocomplete class="class-one class-two" #auto="matAutocomplete" [displayWith]="displayFn">
<mat-autocomplete class="class-one class-two" #auto="matAutocomplete"
[displayWith]="displayFn" [disableRipple]="disableRipple">
<mat-option *ngFor="let state of filteredStates" [value]="state">
<span> {{ state.code }}: {{ state.name }} </span>
</mat-option>
Expand All @@ -1686,6 +1686,7 @@ class SimpleAutocomplete implements OnDestroy {
valueSub: Subscription;
floatLabel = 'auto';
width: number;
disableRipple = false;

@ViewChild(MatAutocompleteTrigger) trigger: MatAutocompleteTrigger;
@ViewChild(MatAutocomplete) panel: MatAutocomplete;
Expand Down
27 changes: 22 additions & 5 deletions src/lib/autocomplete/autocomplete.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
* 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
*/

import {
AfterContentInit,
Component,
Expand All @@ -21,7 +20,13 @@ import {
EventEmitter,
Output,
} from '@angular/core';
import {MatOption, MatOptgroup} from '@angular/material/core';
import {
MatOption,
MatOptgroup,
MAT_OPTION_PARENT_COMPONENT,
mixinDisableRipple,
CanDisableRipple,
} from '@angular/material/core';
import {ActiveDescendantKeyManager} from '@angular/cdk/a11y';


Expand All @@ -40,6 +45,11 @@ export class MatAutocompleteSelectedEvent {
public option: MatOption) { }
}

// Boilerplate for applying mixins to MatAutocomplete.
/** @docs-private */
export class MatAutocompleteBase {}
export const _MatAutocompleteMixinBase = mixinDisableRipple(MatAutocompleteBase);


@Component({
moduleId: module.id,
Expand All @@ -50,11 +60,16 @@ export class MatAutocompleteSelectedEvent {
preserveWhitespaces: false,
changeDetection: ChangeDetectionStrategy.OnPush,
exportAs: 'matAutocomplete',
inputs: ['disableRipple'],
host: {
'class': 'mat-autocomplete'
}
},
providers: [
{provide: MAT_OPTION_PARENT_COMPONENT, useExisting: MatAutocomplete}
]
})
export class MatAutocomplete implements AfterContentInit {
export class MatAutocomplete extends _MatAutocompleteMixinBase implements AfterContentInit,
CanDisableRipple {

/** Manages active item in option list based on key events. */
_keyManager: ActiveDescendantKeyManager<MatOption>;
Expand Down Expand Up @@ -103,7 +118,9 @@ export class MatAutocomplete implements AfterContentInit {
/** Unique ID to be used by autocomplete trigger's "aria-owns" property. */
id: string = `mat-autocomplete-${_uniqueAutocompleteIdCounter++}`;

constructor(private _changeDetectorRef: ChangeDetectorRef, private _elementRef: ElementRef) { }
constructor(private _changeDetectorRef: ChangeDetectorRef, private _elementRef: ElementRef) {
super();
}

ngAfterContentInit() {
this._keyManager = new ActiveDescendantKeyManager<MatOption>(this.options).withWrap();
Expand Down