Skip to content

refactor(chips): replace disabled property with mixin #5072

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
Jun 12, 2017
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
12 changes: 11 additions & 1 deletion src/lib/chips/chip.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,15 @@ describe('Chips', () => {
expect(testComponent.chipSelect).toHaveBeenCalledWith({ chip: chipInstance });
});

it('should update the aria-label for disabled chips', () => {
expect(chipNativeElement.getAttribute('aria-disabled')).toBe('false');

testComponent.disabled = true;
fixture.detectChanges();

expect(chipNativeElement.getAttribute('aria-disabled')).toBe('true');
});

});
});
});
Expand All @@ -121,7 +130,7 @@ describe('Chips', () => {
template: `
<md-chip-list>
<div *ngIf="shouldShow">
<md-chip [color]="color" [selected]="selected"
<md-chip [color]="color" [selected]="selected" [disabled]="disabled"
(focus)="chipFocus($event)" (destroy)="chipDestroy($event)"
(select)="chipSelect($event)" (deselect)="chipDeselect($event)">
{{name}}
Expand All @@ -130,6 +139,7 @@ describe('Chips', () => {
</md-chip-list>`
})
class SingleChip {
disabled: boolean = false;
name: string = 'Test';
color: string = 'primary';
selected: boolean = false;
Expand Down
11 changes: 4 additions & 7 deletions src/lib/chips/chip.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
import {Focusable} from '../core/a11y/focus-key-manager';
import {coerceBooleanProperty} from '../core/coercion/boolean-property';
import {CanColor, mixinColor} from '../core/common-behaviors/color';
import {CanDisable, mixinDisabled} from '../core/common-behaviors/disabled';

export interface MdChipEvent {
chip: MdChip;
Expand All @@ -20,7 +21,7 @@ export interface MdChipEvent {
export class MdChipBase {
constructor(public _renderer: Renderer2, public _elementRef: ElementRef) {}
}
export const _MdChipMixinBase = mixinColor(MdChipBase, 'primary');
export const _MdChipMixinBase = mixinColor(mixinDisabled(MdChipBase), 'primary');


/**
Expand All @@ -39,7 +40,7 @@ export class MdBasicChip { }
@Directive({
selector: `md-basic-chip, [md-basic-chip], md-chip, [md-chip],
mat-basic-chip, [mat-basic-chip], mat-chip, [mat-chip]`,
inputs: ['color'],
inputs: ['color', 'disabled'],
host: {
'class': 'mat-chip',
'tabindex': '-1',
Expand All @@ -52,11 +53,7 @@ export class MdBasicChip { }
'(blur)': '_hasFocus = false',
}
})
export class MdChip extends _MdChipMixinBase implements Focusable, OnDestroy, CanColor {
/** Whether or not the chip is disabled. */
@Input() get disabled(): boolean { return this._disabled; }
set disabled(value: boolean) { this._disabled = coerceBooleanProperty(value); }
protected _disabled: boolean = null;
export class MdChip extends _MdChipMixinBase implements Focusable, OnDestroy, CanColor, CanDisable {

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