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(form): update label alignment #2200

Merged
merged 14 commits into from Sep 5, 2019
Merged

Conversation

christiemolloy
Copy link
Member

closes #2167

Spoke with @kybaker about how we should handle form labels. We came to the conclusion that: -

  • for form labels adjacent to a form control with one line, the label should be vertically aligned in the center.
  • for form labels adjacent to a form control with two lines, the label should be aligned to the top.

This should allow for these labels to more flexible, especially with font-sizes changing. The downside is that the user will have to add a modifier to change the label to align to the top.

Here is the example in the horizontal form demo:
Screen Shot 2019-08-28 at 10 05 46 AM

Bootstrap does something similar:
Screen Shot 2019-08-28 at 9 56 51 AM

@patternfly-build
Copy link

PatternFly-Next preview: https://patternfly-next-pr-2200.surge.sh


<br>

{{#> form form--modifier="pf-m-horizontal" form--id="horizontal-align-labels"}}
Copy link
Contributor

Choose a reason for hiding this comment

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

form--id needs to be unique

@mcoker
Copy link
Contributor

mcoker commented Aug 28, 2019

If a user has a horizontal group with multiple form control elements, or just a tall element, the label is going to be vertically aligned to the center. Is that OK or would that be breaking?

This is what that will look like if a user just pulls in this PR without adding the pf-m-align-top class.

Screen Shot 2019-08-28 at 6 03 45 PM

And personally I think labels adjacent to groups with multiple lines where the first line is a form control element, I would still expect the label text to align with the text in the form control element.

So this (top padding)

Screen Shot 2019-08-28 at 6 05 22 PM

instead of this (no padding)

Screen Shot 2019-08-28 at 6 05 29 PM

@christiemolloy
Copy link
Member Author

@mcoker Yeah I think that will be a breaking change, would you recommend that I make this an opt-in solution or release it during the breaking change period?

In the screenshot below is this how you would expect to see it happen? By default the label is vertically-aligned in the center (helper text is outside of pf-c-form__horizontal-group) so that it doesn't make the form control taller than it needs to be. For labels adjacent to a text area they can use the modifier pf-m-align-top so that is aligned to the top and has a top padding so that the text is aligned horizontally?

Screen Shot 2019-08-30 at 10 57 11 AM

@mcoker
Copy link
Contributor

mcoker commented Aug 30, 2019

In the screenshot below is this how you would expect to see it happen?

It is, but that's just my opinion :)

If we went that way, couldn't we just add a pf-m-no-padding-top modifier to the existing form labels that removes the top padding when the label is adjacent to something that isn't a form control element?

I was also going to say that we could also just apply the padding-top that is applied to labels to both the label and the horizontal form group to the right, then say .pf-c-form__horizontal-group > .pf-c-form-control:first-child, .pf-c-form__horizontal-group > .pf-c-select:first-child, [etc] { margin-top: -[the padding top of the horizontal group]; } to offset the padding when one of those components that uses --pf-global--spacer--form-element as the top padding is the first child of the horizontal form group. I don't actually think we should do that, as I think it could get tricky and we might end up with a really long list of components in the selector, but that would be one way to make the same adjustment and a user wouldn't need to use a modifier for the label and content in the horizontal form group to align.

@christiemolloy
Copy link
Member Author

@mcoker my thoughts on the padding for alignment is that it isn't the most flexible option especially when font-sizes change

@kybaker what are your thoughts on having the label that is aligned to the top, have a padding-top? Or should it just be aligned to the top?

@christiemolloy
Copy link
Member Author

@mcoker @mattnolting made updates so that this isn't breaking... adding a modifier for when the label is adjacent to a non-formcontrol element

Screen Shot 2019-09-05 at 1 40 53 PM

Also confirmed with @mcarrano that wrapping the label is fine, but from a design perspective long labels should be avoided.

.pf-c-form__group .pf-c-form__label {
padding-top: var(--pf-c-form__label--PaddingTop);
padding-bottom: 0;

&.pf-m-no-padding {
padding-top: 0;
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
padding-top: 0;
--pf-c-form__label--PaddingTop: 0;

Copy link
Member Author

Choose a reason for hiding this comment

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

updated

@@ -28,4 +28,5 @@
| `.pf-m-inactive` | `.pf-c-form__helper-text`| Modifies display of helper text to none. |
| `.pf-m-border` | `.pf-c-form__section` | Modifies form element border-bottom. |
| `.pf-m-disabled` | `.pf-c-form__label` | Modifies form label to show disabled state. |
| `.pf-m-no-padding` | `.pf-c-form__label` | Removes top padding from the label element for labels adjacent to an element that isn't a form control. |
Copy link
Contributor

Choose a reason for hiding this comment

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

should this be .pf-m-no-padding-top?

Copy link
Member Author

Choose a reason for hiding this comment

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

updated

@mcoker
Copy link
Contributor

mcoker commented Sep 5, 2019

There is some extra space under the textarea for some reason...

Screen Shot 2019-09-05 at 1 38 01 PM

Also since we have a helper text example, I wonder if we should remove that and just show helper text in the vertical and horizontal examples.

Copy link
Contributor

@mcoker mcoker left a comment

Choose a reason for hiding this comment

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

This looks great to me!! I left a couple of comments. We can address in this PR if you want, or we can open a new issue to look at later.

@christiemolloy
Copy link
Member Author

Thanks for reviewing. I think I captured all of your comments and removed the text underneath

Copy link
Contributor

@mattnolting mattnolting left a comment

Choose a reason for hiding this comment

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

Great work! LGTM

@mcoker mcoker merged commit dacd01d into patternfly:master Sep 5, 2019
@redallen
Copy link
Contributor

redallen commented Sep 5, 2019

🎉 This PR is included in version 2.31.2 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants