-
Notifications
You must be signed in to change notification settings - Fork 6.8k
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
Conversation
LGTM |
Could we not move that margin to the label element and then remove it using the |
@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 |
@jelbourn Is there some update about this PR and eventually merging it? |
@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. |
@jelbourn Great, looking forward to it. P.S. sorry for the delayed rebase, I didn't see the changed label. |
src/lib/checkbox/checkbox.scss
Outdated
@@ -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 { |
There was a problem hiding this comment.
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.
src/lib/checkbox/checkbox.ts
Outdated
@@ -164,6 +164,13 @@ export class MdCheckbox implements ControlValueAccessor, AfterViewInit, OnDestro | |||
|
|||
@ViewChild(MdRipple) _ripple: MdRipple; | |||
|
|||
@ViewChild('labelWrapper') _labelWrapper: ElementRef; | |||
|
|||
get hasLabel(): boolean { |
There was a problem hiding this comment.
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.
src/lib/checkbox/checkbox.ts
Outdated
@ViewChild('labelWrapper') _labelWrapper: ElementRef; | ||
|
||
get hasLabel(): boolean { | ||
const labelWrapperTextContent = this._labelWrapper.nativeElement.textContent; |
There was a problem hiding this comment.
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;
I addressed the comments but can't understand why the build fails. |
@belev Probably a Travis bug, happens sometimes as far as I know. Can you restart the CI process? |
@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. |
Yeah looks like a flake. Is your PR rebased properly? Also restarted the build manually. |
What do you mean by properly rebased? |
I meant rebased on top of |
No, it is not. |
That could have caused the |
Thanks. So I assume it is better to always rebase on top of master? |
@belev Yep always :) |
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
Done, after all 😄 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
This change broke the layout of my login screen :( When rendering: It considers that is has no label at render time and therefore renders the checkbox without its margin (until one clicks on the checkbox). |
@w3t Please file a new issue and provide a Plunker demo for reproduction? |
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
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
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
* 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
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
checkboxNativeElement
instead ofcheckboxDebugElement.nativeElement
in expect statements.Closes #2011