Skip to content

fix(button): remove disabled attribute when disabled value is false… #1789

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
Nov 11, 2016
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
18 changes: 18 additions & 0 deletions src/lib/button/button.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,24 @@ describe('MdButton', () => {
fixture.detectChanges();
expect(buttonDebugElement.nativeElement.getAttribute('aria-disabled')).toBe('true');
});

it('should not add aria-disabled attribute if disabled is false', () => {
let fixture = TestBed.createComponent(TestApp);
let testComponent = fixture.debugElement.componentInstance;
let buttonDebugElement = fixture.debugElement.query(By.css('a'));
fixture.detectChanges();
expect(buttonDebugElement.nativeElement.getAttribute('aria-disabled'))
.toBe('false', 'Expect aria-disabled="false"');
expect(buttonDebugElement.nativeElement.getAttribute('disabled'))
.toBeNull('Expect disabled="false"');

testComponent.isDisabled = false;
fixture.detectChanges();
expect(buttonDebugElement.nativeElement.getAttribute('aria-disabled'))
.toBe('false', 'Expect no aria-disabled');
expect(buttonDebugElement.nativeElement.getAttribute('disabled'))
.toBeNull('Expect no disabled');
});
});

// Ripple tests.
Expand Down
4 changes: 2 additions & 2 deletions src/lib/button/button.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,15 @@ export class MdButton {

/** Whether the ripple effect on click should be disabled. */
private _disableRipple: boolean = false;
private _disabled: boolean = false;
private _disabled: boolean = null;

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

@Input()
get disabled() { return this._disabled; }
set disabled(value: boolean) { this._disabled = coerceBooleanProperty(value); }
set disabled(value: boolean) { this._disabled = coerceBooleanProperty(value) ? true : null; }

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

Expand Down