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

Border Controls: Add ability to apply custom CSS classes to popover content #39753

Merged
merged 3 commits into from
Mar 28, 2022

Conversation

aaronrobertshaw
Copy link
Contributor

Related:

What?

This provides consumers with a means of applying custom class names to the dropdown popover content in both the BorderControl and BorderBoxControl.

Why?

We need to be able to customize the positioning of the border control popovers in the block editor to match the color control flyouts.

How?

Adds new props to the BorderControl and BorderBoxControl components so that we can plumb through custom CSS classes and pass them to the inner Dropdown components via their contentClassName prop.

As we can't yet leverage the component context system in the block editor this approach avoids adding any hardcoded classes to the components.

Testing Instructions

  1. Fire up the Storybook and ensure BorderControl and BorderBoxControl continue to function correctly.
  2. Checkout Borders: Use new border control components in block support #37770 which is based on this PR
  3. Create a post, add a group block, and select it
  4. In the sidebar, experiment with the BorderBoxControl opening each of the border color/style dropdowns (including those in the "unlinked" view). Their width and positioning should be different to the Storybook controls.
  5. If still in doubt, inspect a border control popover and confirm the presence of a custom class on the popover.

Screenshots or screencast

This is for consumers to be able to provide tailored positioning e.g. matching the color control's flyout in the block editor.
@aaronrobertshaw aaronrobertshaw added [Type] Enhancement A suggestion for improvement. [Feature] UI Components Impacts or related to the UI component system labels Mar 25, 2022
@aaronrobertshaw aaronrobertshaw self-assigned this Mar 25, 2022
Copy link
Contributor

@andrewserong andrewserong left a comment

Choose a reason for hiding this comment

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

Nice addition @aaronrobertshaw, the behaviour in the editor makes a great case for adding in the additional classnames. It feels much nicer to have the popover aligned to the editor sidebar rather than covering the border controls:

border-popover-position

I just left a (totally optional) suggestion for an additional comment in the readme file, to explain the intended use case, because it took me a minute to work out why we'd need all the additional classnames — though the usage is much clearer when looking at the real world usage in the other PR.

I quite like that this allows styling to be overridden via classnames / CSS, without committing to a particular hard-coded classname (which I know @ciampo has rightly pointed out the risks of in the past). Allowing arbitrarily named, but semantically structured classnames (in terms of the object keys) seems like a good trade-off to me! 👍

@aaronrobertshaw
Copy link
Contributor Author

Thanks for the review @andrewserong 👍

My understanding is that the ability to make these border control popovers consistent with the color ones in the editor is a requirement to updating our border controls and supporting individual border side configurations.

Given this and that this PR doesn't introduce hardcoded classnames as per previous discussions around new components, I'll merge this now to unblock #37770. I'll take care of any tweaks or follow-ups separately.

@aaronrobertshaw aaronrobertshaw merged commit 4c109f6 into trunk Mar 28, 2022
@aaronrobertshaw aaronrobertshaw deleted the add/custom-classnames-to-border-popovers branch March 28, 2022 03:52
@github-actions github-actions bot added this to the Gutenberg 13.0 milestone Mar 28, 2022
@andrewserong
Copy link
Contributor

Given this and that this PR doesn't introduce hardcoded classnames as per previous discussions around new components, I'll merge this now.

Good thinking! And thanks again for splitting out these features in separate PRs, it's made reviewing a couple of them really straightforward 🙂

@ciampo
Copy link
Contributor

ciampo commented Mar 28, 2022

Just seeing this now (was AFK at the end of last week), thank you folks for making constant improvements to the components (and for avoiding hardcoded classnames!)

@youknowriad
Copy link
Contributor

youknowriad commented May 4, 2022

I've just seen this addition and to be honest I'm not a big fan. I think it actually forces us to position the popover using a "classname" which might be the only solution right now but AFAIK we want to move away from overriding components using classnames and instead rely on props (well defined behavior).

Maybe a generic popoverProps like we have for Dropdown would have been better here.

@youknowriad
Copy link
Contributor

Context: I'm trying to improve the Popover component in #40740 and this is getting in the way a bit :)

@youknowriad
Copy link
Contributor

I think your use-case here is to position the popovers properly on the side of the sidebar. Here's how I'm solving the same issue for the color popovers using just props 10665a1#diff-ad1d53efac56f53733486d999e58f29074e50b74b692ce5f5fd78b4c3163781cR53-R56

@aaronrobertshaw
Copy link
Contributor Author

I've just seen this addition and to be honest I'm not a big fan.

This was the best approach I found to meet previous directions around new components. While creating the ToolsPanel I was advised we shouldn't simply expose all props to inner components and instead more deliberately expose only what the individual component needs.

So for these border controls specifically, we didn't want to allow further customization of the popovers beyond that positioning and the class name is (until your refactor I believe) the only way to achieve it.

The repositioning of the popover was a specific request in feedback on the new border controls in order to be able to get them to land and clean up the border support UI which was blocking adoption of that support for a few core blocks.

That is just the history of how we arrived here. The work you are doing on the Popover changes the goalposts a bit so I'm happy to revisit this.

I think it actually forces us to position the popover using a "classname" which might be the only solution right now but AFAIK we want to move away from overriding components using classnames and instead rely on props (well defined behavior).

Thanks for raising the desire to move away from overriding components using classnames.

I'm trying to improve the Popover component in #40740 and this is getting in the way a bit :)

In light of this, I'll create a new PR exposing a popoverProps approach for us to continue the discussion on. Hopefully, that will help unblock your efforts on the Popover.

@aaronrobertshaw
Copy link
Contributor Author

As promised a PR moving to a popoverProps approach for the border controls is available in #40836

@youknowriad
Copy link
Contributor

Thanks for following up here :) I really appreciate it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Feature] UI Components Impacts or related to the UI component system [Type] Enhancement A suggestion for improvement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants