Skip to content

Commit 716372b

Browse files
tinayuangaojelbourn
authored andcommitted
fix(button): remove disabled attribute when disabled value is false for MdAnchor (#1789)
1 parent 4183fbc commit 716372b

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

src/lib/button/button.spec.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,24 @@ describe('MdButton', () => {
127127
fixture.detectChanges();
128128
expect(buttonDebugElement.nativeElement.getAttribute('aria-disabled')).toBe('true');
129129
});
130+
131+
it('should not add aria-disabled attribute if disabled is false', () => {
132+
let fixture = TestBed.createComponent(TestApp);
133+
let testComponent = fixture.debugElement.componentInstance;
134+
let buttonDebugElement = fixture.debugElement.query(By.css('a'));
135+
fixture.detectChanges();
136+
expect(buttonDebugElement.nativeElement.getAttribute('aria-disabled'))
137+
.toBe('false', 'Expect aria-disabled="false"');
138+
expect(buttonDebugElement.nativeElement.getAttribute('disabled'))
139+
.toBeNull('Expect disabled="false"');
140+
141+
testComponent.isDisabled = false;
142+
fixture.detectChanges();
143+
expect(buttonDebugElement.nativeElement.getAttribute('aria-disabled'))
144+
.toBe('false', 'Expect no aria-disabled');
145+
expect(buttonDebugElement.nativeElement.getAttribute('disabled'))
146+
.toBeNull('Expect no disabled');
147+
});
130148
});
131149

132150
// Ripple tests.

src/lib/button/button.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,15 +43,15 @@ export class MdButton {
4343

4444
/** Whether the ripple effect on click should be disabled. */
4545
private _disableRipple: boolean = false;
46-
private _disabled: boolean = false;
46+
private _disabled: boolean = null;
4747

4848
@Input()
4949
get disableRipple() { return this._disableRipple; }
5050
set disableRipple(v) { this._disableRipple = coerceBooleanProperty(v); }
5151

5252
@Input()
5353
get disabled() { return this._disabled; }
54-
set disabled(value: boolean) { this._disabled = coerceBooleanProperty(value); }
54+
set disabled(value: boolean) { this._disabled = coerceBooleanProperty(value) ? true : null; }
5555

5656
constructor(private _elementRef: ElementRef, private _renderer: Renderer) { }
5757

0 commit comments

Comments
 (0)