Skip to content

ToggleGroupControl: Only show enclosing border when isBlock - #45492

Merged
mirka merged 6 commits into
trunkfrom
toggle-group-border
Nov 4, 2022
Merged

mirka merged 6 commits into
trunkfrom
toggle-group-border

Conversation

@mirka

@mirka mirka commented Nov 2, 2022 •

Copy link
Copy Markdown
Member

Follow-up to #45123

What?

When the control is unhovered or unfocused, change the logic so the enclosing border is hidden when isBlock is false.

Why?

We discussed with @jasmussen what a sensible style guideline would be regarding these enclosing borders.

The main requirement from the design team is that we don't want the visible border when the options are icons, or to be more exact, when they are square-proportioned like the buttons in the block toolbar.

Good Bad
Icon toggles with hidden border Icon toggles with visible border

In theory, non-icon options can also be square-proportioned when the text labels are short. And looking at @jasmussen's WIP mockups, it seems possible that not all icon buttons will be square-proportioned. But who knows what will happen. My assessment is that there's still a good amount of uncertainty on what our eventual product requirements are going to be here.

Hence, the main goal of this PR is to accomplish the border-hiding in a minimum viable way without mucking with the API prematurely. I see two approaches:

  1. Bring back the __experimentalIsBorderless prop so consumers set it explicitly. The downside is that the consumers need to be aware of the style guideline, and when that guideline changes, they'll need to update all their instances.
  2. Use the isBlock prop as a proxy to determine whether it needs a border. Looking at the Gutenberg codebase, all instances that use text options have the isBlock prop enabled. All instances with icon options have it disabled.

I think number 2 is the minimum viable approach that will leave the least amount of tech debt down the line when requirements change and we need to change the API in some way. (This includes the possibility of splitting ToggleGroupControl into two components so one of them can handle the square-proportion case specifically.)

Testing Instructions

  1. npm run storybook:dev and see the stories/docs for ToggleGroupControl. The enclosing border (when unhovered & unfocused) should only be visible when isBlock && ! isDeselectable .
  2. npm run dev and smoke test some ToggleGroupControl instances in the editor sidebar.

@mirka mirka added the [Package] Components /packages/components label Nov 2, 2022
@mirka mirka self-assigned this Nov 2, 2022
@mirka
mirka requested a review from ajitbohra as a code owner November 2, 2022 15:56
@codesandbox

codesandbox Bot commented Nov 2, 2022

Copy link
Copy Markdown

CodeSandbox logoCodeSandbox logo  Open in CodeSandbox Web Editor | VS Code | VS Code Insiders

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Added this so it matches our "recommended default". (Note that isBlock is similarly enabled in our README code snippets.)

@mirka
mirka requested review from chad1008 and ciampo November 2, 2022 16:11

@ciampo ciampo left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code changes LGTM 🚀

  • never show the border (not even on hover or focus) when isDeselectable === true (each option is a separate button and tab stop, with its own focus ring)
  • when isDeselectable !== true:
    • always show border if isBlock === true
    • show border only on hover / focus if isBlock !== true

Let's wait for @jasmussen to have a look as well, though.

@mirka
mirka requested a review from jasmussen November 2, 2022 16:28

@jasmussen jasmussen left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Wonderful, thank you! Before:
before

After:

after

At some point in the future, likely as part of the ongoing up-to-40px work that's going on, we'll want the height of all toggle states inside segmented controls, icon-only or not, to be 32px tall to match other similar elements such as these:
Screenshot 2022-11-03 at 09 16 03

They are 30x30 now. But not a blocker at all, something we can look at separately. Thanks again!

@mirka

mirka commented Nov 3, 2022

Copy link
Copy Markdown
Member Author

At some point in the future, likely as part of the ongoing up-to-40px work that's going on, we'll want the height of all toggle states inside segmented controls, icon-only or not, to be 32px tall

Will do! Tracked in #45532

@mirka
mirka force-pushed the toggle-group-border branch from a980de6 to ebe57b4 Compare November 4, 2022 15:59
@mirka
mirka merged commit 984e9d8 into trunk Nov 4, 2022
@mirka
mirka deleted the toggle-group-border branch November 4, 2022 17:47
@github-actions github-actions Bot added this to the Gutenberg 14.6 milestone Nov 4, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

[Package] Components /packages/components

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants