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

fix(checkbox): no side margin if label has no content #2121

Merged
merged 1 commit into from
Apr 28, 2017

Conversation

belev
Copy link
Contributor

@belev belev commented Dec 8, 2016

  • Remove side margin in checkbox if label has no content.
  • Use checkboxNativeElement instead of checkboxDebugElement.nativeElement in expect statements.
  • Fix typo.

Closes #2011

@googlebot googlebot added the cla: yes PR author has agreed to Google's Contributor License Agreement label Dec 8, 2016
@tinayuangao tinayuangao self-assigned this Dec 9, 2016
@tinayuangao
Copy link
Contributor

LGTM

@jelbourn
Copy link
Member

Could we not move that margin to the label element and then remove it using the :empty pseudo-class? That would be way simpler.

@belev
Copy link
Contributor Author

belev commented Dec 14, 2016

@jelbourn I totally agree that with such pseudo-class it will be way simpler and better because that's a styling problem. I tried it but couldn't make it work. Using :empty match whitespaces as content and don't apply the changes if we have any whitespace: very simple example. I saw a pseudo-class :blank which handles whitespaces but unfortunately the browsers don't supported it.

@belev
Copy link
Contributor Author

belev commented Jan 5, 2017

@jelbourn Is there some update about this PR and eventually merging it?

@jelbourn
Copy link
Member

@belev I want to dedicate a chunk of time to investigate this more in depth but haven't yet had the opportunity. I'll come back here and update when I do.

@belev
Copy link
Contributor Author

belev commented Mar 14, 2017

@jelbourn Great, looking forward to it.

P.S. sorry for the delayed rebase, I didn't see the changed label.

@@ -293,6 +300,13 @@ $_mat-checkbox-mark-stroke-size: 2 / 15 * $mat-checkbox-size !default;
right: $_mat-checkbox-item-spacing;
}
}

&.mat-checkbox-inner-container-no-side-margin {
Copy link
Member

Choose a reason for hiding this comment

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

You don't need to define this class twice; just one without the parent part of the selector would be better.

@@ -164,6 +164,13 @@ export class MdCheckbox implements ControlValueAccessor, AfterViewInit, OnDestro

@ViewChild(MdRipple) _ripple: MdRipple;

@ViewChild('labelWrapper') _labelWrapper: ElementRef;

get hasLabel(): boolean {
Copy link
Member

Choose a reason for hiding this comment

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

Let's change this to a method rather than a getter. It should also be marked as internal (name with a leading underscore). It also needs a JsDoc description comment.

@ViewChild('labelWrapper') _labelWrapper: ElementRef;

get hasLabel(): boolean {
const labelWrapperTextContent = this._labelWrapper.nativeElement.textContent;
Copy link
Member

Choose a reason for hiding this comment

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

This will be a problem for Angular Universal. Currently, nativeElement is a parse5 node, which doesn't have a textContent property. So for now you can say

const labelText = this._labelWrapper.nativeElement.textContent || '';
return !!labelText.trim().length;

@belev
Copy link
Contributor Author

belev commented Apr 20, 2017

I addressed the comments but can't understand why the build fails.

@dahaupt
Copy link

dahaupt commented Apr 24, 2017

@belev Probably a Travis bug, happens sometimes as far as I know. Can you restart the CI process?

@belev
Copy link
Contributor Author

belev commented Apr 24, 2017

@dahaupt I don't think so, doesn't see any restart button. Maybe I can force it by closing and opening the PR or making some new dummy commit but don't think that's a good idea.

@devversion
Copy link
Member

Yeah looks like a flake. Is your PR rebased properly? Also restarted the build manually.

@belev
Copy link
Contributor Author

belev commented Apr 24, 2017

What do you mean by properly rebased?

@devversion
Copy link
Member

I meant rebased on top of master?

@belev
Copy link
Contributor Author

belev commented Apr 24, 2017

No, it is not.

@devversion
Copy link
Member

That could have caused the SyntaxError in the Travis CI. Just that you know, rebasing could solve those issues.

@belev
Copy link
Contributor Author

belev commented Apr 24, 2017

Thanks. So I assume it is better to always rebase on top of master?

@devversion
Copy link
Member

@belev Yep always :)

@belev
Copy link
Contributor Author

belev commented Apr 24, 2017

Ok, thanks. I will make the proper rebase when I have time then.

* Remove side margin in checkbox if label has no content.
* Use `checkboxNativeElement` instead of `checkboxDebugElement.nativeElement` in expect statements.
* Fix typo.

Closes angular#2011
@belev
Copy link
Contributor Author

belev commented Apr 25, 2017

Done, after all 😄

Copy link
Member

@jelbourn jelbourn left a comment

Choose a reason for hiding this comment

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

LGTM

@jelbourn jelbourn added action: merge The PR is ready for merge by the caretaker and removed pr: needs rebase labels Apr 28, 2017
@mmalerba mmalerba merged commit 4e8d806 into angular:master Apr 28, 2017
@belev belev deleted the issue-2011 branch April 29, 2017 09:27
@w3t
Copy link

w3t commented May 22, 2017

This change broke the layout of my login screen :(

When rendering:
<md-checkbox [(ngModel)]="savePassword">{{ "tx_Login_SavePassword" | translate }}

It considers that is has no label at render time and therefore renders the checkbox without its margin (until one clicks on the checkbox).

@devversion
Copy link
Member

@w3t Please file a new issue and provide a Plunker demo for reproduction?

devversion added a commit to devversion/material2 that referenced this pull request May 22, 2017
With angular#2121 the margin will be removed for checkboxes that don't have any label set.

A problem is that the Checkbox uses the OnPush change detection strategy and therefore the checkbox is not able to detect any delayed / async label change.

This means that checkboxes that set their label from an async binding will not have any margin until the users clicks on the checkbox.

Using the `cdkObserveContent` seems to be an elegant approach when using the OnPush strategy.

The `:empty` CSS selector would be more elegant but it's very sensitive about whitespaces and therefore it doesn't work properly.

Fixes angular#4720
devversion added a commit to devversion/material2 that referenced this pull request May 23, 2017
With angular#2121 the margin will be removed for checkboxes that don't have any label set.

A problem is that the Checkbox uses the OnPush change detection strategy and therefore the checkbox is not able to detect any delayed / async label change.

This means that checkboxes that set their label from an async binding will not have any margin until the users clicks on the checkbox.

Using the `cdkObserveContent` seems to be an elegant approach when using the OnPush strategy.

The `:empty` CSS selector would be more elegant but it's very sensitive about whitespaces and therefore it doesn't work properly.

Fixes angular#4720
devversion added a commit to devversion/material2 that referenced this pull request May 31, 2017
With angular#2121 the margin will be removed for checkboxes that don't have any label set.

A problem is that the Checkbox uses the OnPush change detection strategy and therefore the checkbox is not able to detect any delayed / async label change.

This means that checkboxes that set their label from an async binding will not have any margin until the users clicks on the checkbox.

Using the `cdkObserveContent` seems to be an elegant approach when using the OnPush strategy.

The `:empty` CSS selector would be more elegant but it's very sensitive about whitespaces and therefore it doesn't work properly.

Fixes angular#4720
andrewseguin pushed a commit that referenced this pull request Jun 8, 2017
* fix(checkbox): margin for empty checkboxes incorrectly added

With #2121 the margin will be removed for checkboxes that don't have any label set.

A problem is that the Checkbox uses the OnPush change detection strategy and therefore the checkbox is not able to detect any delayed / async label change.

This means that checkboxes that set their label from an async binding will not have any margin until the users clicks on the checkbox.

Using the `cdkObserveContent` seems to be an elegant approach when using the OnPush strategy.

The `:empty` CSS selector would be more elegant but it's very sensitive about whitespaces and therefore it doesn't work properly.

Fixes #4720

* Updates
@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Sep 6, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
action: merge The PR is ready for merge by the caretaker cla: yes PR author has agreed to Google's Contributor License Agreement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Unlabeled checkboxes shouldn't have prescribed padding/margin
9 participants