Skip to content

refactor(button, chips): use toString method for aria-disabled #5278

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 22, 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
6 changes: 1 addition & 5 deletions src/lib/button/button.ts
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ export class MdButton extends _MdButtonMixinBase implements OnDestroy, CanDisabl
a[mat-button], a[mat-raised-button], a[mat-icon-button], a[mat-fab], a[mat-mini-fab]`,
host: {
'[attr.disabled]': 'disabled || null',
'[attr.aria-disabled]': '_isAriaDisabled',
'[attr.aria-disabled]': 'disabled.toString()',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we're going shorter, could also do disabled + ''

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm not sure about that. toString() explains what it does and is also pretty short.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+ '' is pretty idiomatic javascript imo

Copy link
Member Author

@devversion devversion Jun 21, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah totally. I think it just depends, it's kinda weird doing this in a host binding while we would need to escape the quote (or use the double quote)

I personally prefer toString() as it's describing what it does and is also consistent with all other aria-disabled host bindings.

'(click)': '_haltDisabledEvents($event)',
},
inputs: ['disabled', 'color'],
Expand All @@ -216,10 +216,6 @@ export class MdAnchor extends MdButton {
return this.disabled ? -1 : 0;
}

get _isAriaDisabled(): string {
return this.disabled ? 'true' : 'false';
}

_haltDisabledEvents(event: Event) {
// A disabled button shouldn't apply any actions
if (this.disabled) {
Expand Down
7 changes: 1 addition & 6 deletions src/lib/chips/chip.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ export class MdBasicChip { }
'role': 'option',
'[class.mat-chip-selected]': 'selected',
'[attr.disabled]': 'disabled || null',
'[attr.aria-disabled]': '_isAriaDisabled()',
'[attr.aria-disabled]': 'disabled.toString()',
'(click)': '_handleClick($event)',
'(focus)': '_hasFocus = true',
'(blur)': '_hasFocus = false',
Expand Down Expand Up @@ -109,11 +109,6 @@ export class MdChip extends _MdChipMixinBase implements Focusable, OnDestroy, Ca
this.onFocus.emit({chip: this});
}

/** The aria-disabled state for the chip */
_isAriaDisabled(): string {
return String(this.disabled);
}

/** Ensures events fire properly upon click. */
_handleClick(event: Event) {
// Check disabled
Expand Down