Skip to content
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

feat(checkbox): adds invisible input element to leverage built-in functionality #415

Merged
merged 1 commit into from
May 13, 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
21 changes: 17 additions & 4 deletions src/components/checkbox/checkbox.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,18 @@
<div class="md-checkbox-layout">
<label class="md-checkbox-layout">
<div class="md-checkbox-inner-container">
<input class="md-checkbox-input" type="checkbox"
[id]="inputId"
[checked]="checked"
[disabled]="disabled"
[name]="name"
Copy link
Member

Choose a reason for hiding this comment

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

Also it looks like, the name property doesn't exist as an input / property.

[tabIndex]="tabindex"
[indeterminate]="indeterminate"
[attr.aria-label]="ariaLabel"
[attr.aria-labelledby]="ariaLabelledby"
(focus)="onInputFocus()"
(blur)="onInputBlur()"
(change)="onInteractionEvent($event)">
Copy link
Member

Choose a reason for hiding this comment

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

Does change always capture what you want vs. click ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It appears so

<div class="md-ink-ripple"></div>
<div class="md-checkbox-frame"></div>
<div class="md-checkbox-background">
<svg version="1.1"
Expand All @@ -16,7 +29,7 @@
<div class="md-checkbox-mixedmark"></div>
</div>
</div>
<label [id]="labelId">
<span class="md-checkbox-label">
Copy link
Contributor

Choose a reason for hiding this comment

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

Wouldn't that generates problems with clicks, screen readers and custom label?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No - the outer wrapper is a label which automatically handles this properly since this relies on native behavior.

<ng-content></ng-content>
</label>
</div>
</span>
</label>
18 changes: 12 additions & 6 deletions src/components/checkbox/checkbox.scss
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
@import "default-theme";
@import "theme-functions";
@import "variables";
@import "mixins";

/** The width/height of the checkbox element. */
$md-checkbox-size: $md-toggle-size !default;
Expand Down Expand Up @@ -217,11 +218,8 @@ $_md-checkbox-indeterminate-checked-easing-function: cubic-bezier(0.14, 0, 0, 1)
}

md-checkbox {
cursor: pointer;

&:focus {
// TODO(traviskaufman): Add ink ripple on focus state, once ripple is implemented.
outline: none;
&, label {
cursor: pointer;
}
}

Expand Down Expand Up @@ -251,7 +249,7 @@ md-checkbox {
}

// TODO(kara): Remove this style when fixing vertical baseline
.md-checkbox-layout label {
.md-checkbox-layout .md-checkbox-label {
line-height: 24px;
}

Expand Down Expand Up @@ -461,3 +459,11 @@ md-checkbox {
}
}
}

// Underlying native input element.
// Visually hidden but still able to respond to focus.
.md-checkbox-input {
@include md-visually-hidden;
}

@include md-temporary-ink-ripple(checkbox);
Loading