-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Polish the checkbox, update switch documentation #8588
Conversation
@@ -168,6 +168,32 @@ body.gutenberg-editor-page { | |||
outline-offset: 0; | |||
} | |||
} | |||
|
|||
input[type=checkbox] { |
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.
Should we move these styles to the "Checkbox control" or do we want them to apply globally to checkboxes?
- Moving to CheckboxControl means, it works outside Gutenberg, outside WordPress, whenever you use the component
- It also means that if you use a checkbox with the
CheckboxControl
component, it won't have the styles.
So each option has pros/cons.
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.
Shoot, I thought I commented on this but didn't hit submit. Was gonna say the same thing, I don't think this should be a global checkbox style. We should scope it to our component and just make sure we're using the CheckboxControl
.
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.
The presence here is intentional in the same way as the custom styles for input fields here are intentional. They are new designs for these base ingredients, not just the components. In a way the presence here is tied to #8588 (comment), which is — these should be styles for all of WordPress.
Also, I initially had it in the checkbox control, but then it did not apply to categories.
Should we have these styles in both places? If there's a JavaScripty future for the rest of WordPress, we could imagine one day having these styles live only in the Checkbox component and every checkbox in WordPress would use that component. But in the mean time, what's the best approach?
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.
If there's a JavaScripty future for the rest of WordPress
I think there is 😄
I think we should try to contain our styles and apply them only to our components. We should simply get more things using our components, but the benefits of component-based development is that we can scope styles to an easily-reusable component and then just use it everywhere.
I'd really prefer we scope the styles to this component.
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.
@tofumatt I appreciate your passion for code cleanliness. I share it. My favorite t-shirt is one my friend @MichaelArestad wore a few years ago, that spells "Hella Clean Code" with sparkles around it.
In this case, however, if I scope the checkbox component to be just scoped to the component, the categories aren't styled:
I'm guessing that can be fixed by actually using the checkbox control as part of the categories component, and that this in turn would be the right thing to do. But you'll notice that the input styles starting on this line are also located in this very same file. Should they also be moved to components? And in turn, which input styles will then break if we do this?
I think an argument can be made that the these form widgets, input
, select
, checkboxes, etc. are sort of base ingredients that should be styled in a global stylesheet, as opposed to on a scoped component basis. Or, should each of those HTML elements be a component on its own? And if so, is that a separate PR?
I'm not trying to be difficult — truly my biggest goal here is to simply make sure that all the textfields and checkboxes inside Gutenberg look consistent, and longer term that those same styles can be removed from Gutenberg because they are now default in WordPress as a whole (hence the need for the upstream tickets).
What's the best path forward?
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.
Hmmm... okay. So I'd say that what we really want is:
- styles are *always scoped to a component
- we use a component for everything (even making our own
checkbox
component so it has styles)
That said, you're right for now: it's too much of a pain to do that and it's out of scope.
Your PR is an improvement. Let's not let me make perfect the enemy of great! 😄
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.
We'll make that vision come true. I share it too. One step at a time we'll get there. Thanks Matt!
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.
I largely dig it, I think a few tweaks would be nice but I'll push a few things and let you respond to feedback... after that it's good to go.
@@ -121,13 +121,13 @@ body.gutenberg-editor-page { | |||
} | |||
} | |||
|
|||
// Override core input styles to provide ones consistent with Gutenberg | |||
// @todo submit as upstream patch as well | |||
// Override core input styles to provide ones consistent with Gutenberg. |
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.
"ones" is a slightly ambiguous word here; it'd say "styles" would be better.
// Override core input styles to provide ones consistent with Gutenberg | ||
// @todo submit as upstream patch as well | ||
// Override core input styles to provide ones consistent with Gutenberg. | ||
// @todo Submit as upstream patch as well. |
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.
Can you file an issue for this please and link to it? These TODOs will get lost to time otherwise 😄
At least if there's an issue it'll get lost to time but be tracked! 😉
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.
So far I've intentionally not filed, because the styles for these components were partially in flux. But as of the most recent input style change, and now this, things are solidifiying. How about this: I await a little feedback on this branch, and if the thumbs point upwards, I will create the ticket, update the PR with a link in the comment, and we'll go from there?
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.
Works for me. In general I say more issues (especially things like this which are easily marked as "code quality" issues we can filter out). Easier to close unneeded ones than remember long-forgotten ones 😉
@@ -168,6 +168,32 @@ body.gutenberg-editor-page { | |||
outline-offset: 0; | |||
} | |||
} | |||
|
|||
input[type=checkbox] { | |||
border: 2px solid $dark-gray-300; |
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.
That hardcoded border width makes me nervous. Do we want a rule that checkboxes have double the usual border width? I dunno.
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.
Hardcoded makes it sound so serious :)
The double border is to give weight to the checkbox, without making it overwhelming. Visually I like the balance but design feedback may change this. What would be good CSS if/when the visuals are settled?
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.
Yeah that makes sense. I just think either a variable named 2px or even just using $border-width + 1
would work? That's what this is... and it makes sense to base it off our global borders.
box-shadow: 0 0 0 1px $dark-gray-300; | ||
} | ||
|
||
&:checked:focus { |
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 would be more readable if it were underneath the plain :checked
style below. I think it's nice to "stack" styles like that.
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.
Pushing a fix in a second, let me know if that actually addresses your comment, wasn't sure I understood you perfectly.
border-color: theme( toggle ); | ||
} | ||
|
||
&:before { |
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.
Isn't this selector technically supposed to be ::before
? I know :before
works but we should use ::before
: https://developer.mozilla.org/en-US/docs/Web/CSS/::before#Syntax
We should probs have a rule for it 🤷♂️
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.
It is, and I know, and I'm pretty sure we've discussed this. The reason I went with single colon (besides habits, but habits can change, you've seen this from me capitalizing and period ending my comments now), is that single colon is what we've used EVERYWHERE else in the code. If we add a linter rule and convert those all to double colons, that could probably be a good separate PR no?
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.
That's legit. Filed #8618.
@@ -1,5 +1,21 @@ | |||
# FormToggle | |||
|
|||
The Form Toggle Control (or Switch) is a complement to the Checkbox Control, which is used when the effect is instant and boolean. Like its light switch counterpart that brings light, when you flip this switch something changes instantanously. |
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.
I have a few tweaks to make here but I'll just push a commit 😄
Also, thanks for the fantastic PR summary, really made this one a breeze to review 😄 |
By changing them to using the |
(Really sorry but I got a bit distracted by another branch so I'll get back to this in a few hours, hope that's okay.) |
No worries, I'm about to push a few fixes based on your feedback so maybe hold off a minute, just npm installing a thing. |
Okay, pushed a fix for some of the comments, be sure to pull if you wanted to change the documentation! |
Thanks, sorry I got distracted, my brain is scattered all over the map today. |
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.
I really like this! Thanks for tackling this issue.
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.
I pushed my docs tweak, but I think we should be scoping our styles and I wonder about that TODO now that design feedback is addressed.
So I think a few things here need to be done before we merge, but largely I dig it. Ping me if I was unclear about anything.
For reference, there's a pending ticket for core (3 years) proposing to improve the checkboxes (and radio buttons) contrast ratio. This new Gutenberg design seems to be a very good improvement. https://core.trac.wordpress.org/ticket/35596 |
955f8ef
to
a8f5319
Compare
Rebased, squashed, addressed border feedback and fixed a few typos. Next I'm going to look at creating the upstream ticket for the other components, link that as a comment. |
I created https://core.trac.wordpress.org/ticket/44749 to track the new styles, and replaced the todos in 9d3aa18. Thanks for the reviews everyone, I will merge if the tests pass. |
Just realized I'd missed a bit of feedback. One last sanity check of 544fc84 please thank you? |
544fc84
to
ae685de
Compare
The tests pass for me locally, but I'm not sure why travis keeps failing. I've tried restarting it twice now. Any insights? |
ae685de
to
4d41ff5
Compare
Upon reinstalling my entire local dev environment, I got a few lovely new linter tests along for the ride, and they revealed a few syntax changes that may have caused the build to fail. It's now fixed, rebased, and I'm expecting the tests to pass. |
The switch has a long history. Before I go into details, here's what this PR does: - It replaces Pending Review, Stick to Front Page, Allow Comments, and Allow Pingbacks from using Switches to using Checkboxes. - It tweaks the design of the checkbox to have a significantly more visible checked state, and a new more visual focus state. - It tweaks the documentation for when to use a switch instead of a checkbox. The Switch is born from mobile, which is increasingly the device of choice for people and long term might become the only choice. It's bigger and more tappable, and implies by its nature that it's a boolean choice. It also has qualities that the checkbox does not embody: - Like its wall lightswitch counterpart, it’s something you flip and the effect is instant. There used to be darkness, now there’s light. - It has only a single purpose, and that purpose is boolean. For example you wouldn’t use switches to select multiple categories. However Allow Comments and the three other aforementioned toggles that use switches in master, do not have an instant effect, they require you to hit "Save" before the toggle option is stored. Given the above reasoning, a checkbox is a better choice in those situations. The toggle is still a good choice in situations where immediate visual feedback is given, like when a dropcap is applied, or when you toggle image croppping for gallery items. In those situations, the pairing of the boolean nature and the larger touch target makes the switch feel more substantial. With this PR I'm trying to take into account all the past discussions on the topic, and I know there have been many. Lay your thoughts on me.
Thanks for the feedback, @paulwilde.
cd57342
to
589eeec
Compare
Not sure if this is kosher, as the ID will change if additional checkboxes are added.
|
The switch has a long history. Before I go into details, here's what this PR does:
The Switch is born from mobile, which is increasingly the device of choice for people and long term might become the only choice. It's bigger and more tappable, and implies by its nature that it's a boolean choice. It also has qualities that the checkbox does not embody:
However "Allow Comments" and the three other aforementioned toggles that use switches in master, do not have an instant effect, they require you to hit "Save" before the toggle option is stored. Given the above reasoning, a checkbox is a better choice in those situations.
The toggle is still a good choice in situations where immediate visual feedback is given, like when a dropcap is applied, or when you toggle image croppping for gallery items. In those situations, the pairing of the boolean nature and the larger touch target makes the switch feel more substantial.
With this PR I'm trying to take into account all the past discussions on the topic, and I know there have been many. Lay your thoughts on me.
Screenshots, checking and focus styles:
Relaxed margins:
Instant effect toggles: