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

Polish the checkbox, update switch documentation #8588

Merged
merged 5 commits into from
Aug 8, 2018

Conversation

jasmussen
Copy link
Contributor

@jasmussen jasmussen commented Aug 6, 2018

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.
  • It unifies the margins of checkboxes to use our 4/8/12 grid, and adds a little padding.

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.

Screenshots, checking and focus styles:

styles

Relaxed margins:

tweaks

Instant effect toggles:

switch

@jasmussen jasmussen added [Focus] Accessibility (a11y) Changes that impact accessibility and need corresponding review (e.g. markup changes). Needs Design Feedback Needs general design feedback. labels Aug 6, 2018
@jasmussen jasmussen self-assigned this Aug 6, 2018
@jasmussen jasmussen requested a review from a team August 6, 2018 11:04
@@ -168,6 +168,32 @@ body.gutenberg-editor-page {
outline-offset: 0;
}
}

input[type=checkbox] {
Copy link
Contributor

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.

Copy link
Member

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.

Copy link
Contributor Author

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?

Copy link
Member

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.

Copy link
Contributor Author

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:

screen shot 2018-08-07 at 11 22 52

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?

Copy link
Member

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! 😄

Copy link
Contributor Author

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!

Copy link
Member

@tofumatt tofumatt left a 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.
Copy link
Member

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.
Copy link
Member

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! 😉

Copy link
Contributor Author

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?

Copy link
Member

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;
Copy link
Member

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.

Copy link
Contributor Author

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?

Copy link
Member

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 {
Copy link
Member

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.

Copy link
Contributor Author

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 {
Copy link
Member

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 🤷‍♂️

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 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?

Copy link
Member

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.
Copy link
Member

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 😄

@tofumatt
Copy link
Member

tofumatt commented Aug 6, 2018

Also, thanks for the fantastic PR summary, really made this one a breeze to review 😄

@paulwilde
Copy link
Contributor

paulwilde commented Aug 6, 2018

By changing them to using the CheckboxControl the withInstanceId can now be dropped from these components to clean things up further.

@tofumatt
Copy link
Member

tofumatt commented Aug 6, 2018

(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.)

@tofumatt tofumatt self-assigned this Aug 6, 2018
@jasmussen
Copy link
Contributor Author

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.

@jasmussen
Copy link
Contributor Author

Okay, pushed a fix for some of the comments, be sure to pull if you wanted to change the documentation!

@tofumatt
Copy link
Member

tofumatt commented Aug 6, 2018

Thanks, sorry I got distracted, my brain is scattered all over the map today.

@karmatosed karmatosed self-requested a review August 6, 2018 21:09
Copy link
Member

@karmatosed karmatosed left a 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.

@tofumatt tofumatt removed the Needs Design Feedback Needs general design feedback. label Aug 6, 2018
Copy link
Member

@tofumatt tofumatt left a 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.

@afercia
Copy link
Contributor

afercia commented Aug 7, 2018

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

@jasmussen jasmussen force-pushed the try/checkbox-switch-improvements branch from 955f8ef to a8f5319 Compare August 7, 2018 09:19
@jasmussen
Copy link
Contributor Author

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.

@jasmussen
Copy link
Contributor Author

jasmussen commented Aug 7, 2018

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.

@jasmussen jasmussen added this to the 3.5 milestone Aug 7, 2018
@jasmussen
Copy link
Contributor Author

Just realized I'd missed a bit of feedback. One last sanity check of 544fc84 please thank you?

@jasmussen jasmussen force-pushed the try/checkbox-switch-improvements branch from 544fc84 to ae685de Compare August 7, 2018 12:31
@jasmussen
Copy link
Contributor Author

The tests pass for me locally, but I'm not sure why travis keeps failing. I've tried restarting it twice now. Any insights?

@jasmussen jasmussen force-pushed the try/checkbox-switch-improvements branch from ae685de to 4d41ff5 Compare August 8, 2018 10:14
@jasmussen
Copy link
Contributor Author

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.
@jasmussen jasmussen force-pushed the try/checkbox-switch-improvements branch from cd57342 to 589eeec Compare August 8, 2018 11:47
@jasmussen
Copy link
Contributor Author

jasmussen commented Aug 8, 2018

I'm getting this e2e test:

screen shot 2018-08-08 at 14 00 43

But I'm not sure why that should be affected by this branch, as it's mostly touching CSS and a few panels in the inspector. Is this failing in master too?

This is failling too:

screen shot 2018-08-08 at 14 02 28

This one looks legit:

screen shot 2018-08-08 at 14 04 40

Not sure if this is kosher, as the ID will change if additional checkboxes are added.
@gziolo
Copy link
Member

gziolo commented Aug 8, 2018

test/e2e/specs/writing-flow.test.js fails also locally for me on the latest master branch. Let's merge it as is 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Focus] Accessibility (a11y) Changes that impact accessibility and need corresponding review (e.g. markup changes).
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants