-
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
Toolbar: set toolbar variant only when in block toolbar #54868
Comments
Hi @jasmussen! I saw you confirmed that the black border for the dropdown menu should only appear in the block toolbar. However, I wanted to check on a few other block-related menus to ensure we have the full requirements. My understanding is the black border is to add contrast over editor content, but some scenarios contradict my assumption: InlinePreviewsList view settingsSmall screensThe following appears to be correct, but I wanted to double-check since the toolbar border color changes on smaller screens: |
Hey @brookewp, thanks for checking in!
No, the text inside each menu item is what's carrying the necessary contrast, the border around both block toolbars and popovers is decorative. To that end this is more about elevation, or materials, so to speak. For that reason, the heuristic is that the dropdown menu should be made of the same material as the container that opened it. For example:
Makes sense? We can flex a bit, it's more of an optimization than a rush job to get this right. |
Thanks for looking, @jasmussen! To confirm I understand - in the examples I shared above, all are correct except for the view on smaller screens since there is a black border around the menu while the Toolbar has the grey menu. Is that right? |
Yep, all those are correct except the view on the smaller screen. But I understand how that one is tricky because it's technically still the block toolbar, suddenly it just shifted position to be docked to the top. If that isn't easily fixed, that's okay, because we probably need to revisit mobile separately, and some different rules might come into play. |
Given that the aim is to visually match the border of the dropdown, in a way the current ( The issue arises more from the fact that A few ideas on how to move forward:
|
Thanks for sharing options, @ciampo!
In this option, we'd still need context for the popover variant when the toolbar's borderless variant isn't present, right? Maybe something like: diff --git a/packages/components/src/toolbar/toolbar/index.tsx b/packages/components/src/toolbar/toolbar/index.tsx
index b6e83dcf6d..b9c725e849 100644
--- a/packages/components/src/toolbar/toolbar/index.tsx
+++ b/packages/components/src/toolbar/toolbar/index.tsx
@@ -19,19 +19,26 @@ import type { ToolbarProps } from './types';
import type { WordPressComponentProps } from '../../context';
import { ContextSystemProvider } from '../../context';
-const CONTEXT_SYSTEM_VALUE = {
- DropdownMenu: {
- variant: 'toolbar',
- },
- Dropdown: {
- variant: 'toolbar',
- },
+const CONTEXT_SYSTEM_VALUE = ( variant: string | undefined ) => {
+ if ( variant !== undefined ) {
+ return {};
+ }
+
+ return {
+ DropdownMenu: {
+ variant: 'toolbar',
+ },
+ Dropdown: {
+ variant: 'toolbar',
+ },
+ };
};
function UnforwardedToolbar(
{
className,
label,
+ variant,
...props
}: WordPressComponentProps< ToolbarProps, 'div', false >,
ref: ForwardedRef< any >
@@ -55,10 +62,12 @@ function UnforwardedToolbar(
// `ToolbarGroup` already uses components-toolbar for compatibility reasons.
const finalClassName = classnames(
'components-accessible-toolbar',
- className
+ className,
+ variant === undefined ? undefined : `is-${ variant }`
);
+
return (
- <ContextSystemProvider value={ CONTEXT_SYSTEM_VALUE }>
+ <ContextSystemProvider value={ CONTEXT_SYSTEM_VALUE( variant ) }>
<ToolbarContainer
className={ finalClassName }
label={ label } However, this doesn't help with the mobile scenario. In that case, I'm unsure how I'd approach it without using CSS and the specific classes/media queries already in place. 🤔 Thoughts? |
Yup, something like that
We'd just need to set the variant correctly — i took a quick look and it seems like there is already a |
Thank you! I was looking at the
I'm also glad you shared this info as I wasn't aware of this hook. Good to know! |
Since #51154, changes were made so that
DropdownMenu
andDropdown
components rendered insideToolbar
would automatically pick thetoolbar
variant — that is achieved through the internal components context system (see here) and it causes the popover to render with theis-alternate
classname.So, given the previous requirements, the popover is currently behaving like expected: it's rendering a black border because it's rendered inside a
Toolbar
component.From what I understand, the requirements that we gathered initially were incomplete, and what we'd really want is the
toolbar
popover variant to be only applied in popovers opened from the block toolbar (and not from any toolbar).That is correct. I guess for now, we could keep the changes from this PR. At the same time, we could work on refining the design requirements once for all, and then apply them at the components level.
Originally posted by @ciampo in #54840 (comment)
The text was updated successfully, but these errors were encountered: