Skip to content

Commit 90e6d3c

Browse files
devversionkara
authored andcommitted
refactor(chips): replace disabled property with mixin (#5072)
1 parent 88089a7 commit 90e6d3c

File tree

2 files changed

+15
-8
lines changed

2 files changed

+15
-8
lines changed

src/lib/chips/chip.spec.ts

+11-1
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,15 @@ describe('Chips', () => {
113113
expect(testComponent.chipSelect).toHaveBeenCalledWith({ chip: chipInstance });
114114
});
115115

116+
it('should update the aria-label for disabled chips', () => {
117+
expect(chipNativeElement.getAttribute('aria-disabled')).toBe('false');
118+
119+
testComponent.disabled = true;
120+
fixture.detectChanges();
121+
122+
expect(chipNativeElement.getAttribute('aria-disabled')).toBe('true');
123+
});
124+
116125
});
117126
});
118127
});
@@ -121,7 +130,7 @@ describe('Chips', () => {
121130
template: `
122131
<md-chip-list>
123132
<div *ngIf="shouldShow">
124-
<md-chip [color]="color" [selected]="selected"
133+
<md-chip [color]="color" [selected]="selected" [disabled]="disabled"
125134
(focus)="chipFocus($event)" (destroy)="chipDestroy($event)"
126135
(select)="chipSelect($event)" (deselect)="chipDeselect($event)">
127136
{{name}}
@@ -130,6 +139,7 @@ describe('Chips', () => {
130139
</md-chip-list>`
131140
})
132141
class SingleChip {
142+
disabled: boolean = false;
133143
name: string = 'Test';
134144
color: string = 'primary';
135145
selected: boolean = false;

src/lib/chips/chip.ts

+4-7
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import {
1111
import {Focusable} from '../core/a11y/focus-key-manager';
1212
import {coerceBooleanProperty} from '../core/coercion/boolean-property';
1313
import {CanColor, mixinColor} from '../core/common-behaviors/color';
14+
import {CanDisable, mixinDisabled} from '../core/common-behaviors/disabled';
1415

1516
export interface MdChipEvent {
1617
chip: MdChip;
@@ -20,7 +21,7 @@ export interface MdChipEvent {
2021
export class MdChipBase {
2122
constructor(public _renderer: Renderer2, public _elementRef: ElementRef) {}
2223
}
23-
export const _MdChipMixinBase = mixinColor(MdChipBase, 'primary');
24+
export const _MdChipMixinBase = mixinColor(mixinDisabled(MdChipBase), 'primary');
2425

2526

2627
/**
@@ -39,7 +40,7 @@ export class MdBasicChip { }
3940
@Directive({
4041
selector: `md-basic-chip, [md-basic-chip], md-chip, [md-chip],
4142
mat-basic-chip, [mat-basic-chip], mat-chip, [mat-chip]`,
42-
inputs: ['color'],
43+
inputs: ['color', 'disabled'],
4344
host: {
4445
'class': 'mat-chip',
4546
'tabindex': '-1',
@@ -52,11 +53,7 @@ export class MdBasicChip { }
5253
'(blur)': '_hasFocus = false',
5354
}
5455
})
55-
export class MdChip extends _MdChipMixinBase implements Focusable, OnDestroy, CanColor {
56-
/** Whether or not the chip is disabled. */
57-
@Input() get disabled(): boolean { return this._disabled; }
58-
set disabled(value: boolean) { this._disabled = coerceBooleanProperty(value); }
59-
protected _disabled: boolean = null;
56+
export class MdChip extends _MdChipMixinBase implements Focusable, OnDestroy, CanColor, CanDisable {
6057

6158
/** Whether the chip is selected. */
6259
@Input() get selected(): boolean { return this._selected; }

0 commit comments

Comments
 (0)