-
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
DropdownMenu V2 tweaks #56041
DropdownMenu V2 tweaks #56041
Conversation
2d40fea
to
8b66d75
Compare
// TODO: | ||
// - those values are different from saved variables? | ||
// - should bring this into the config, and make themeable | ||
// - border color and divider color are different? |
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.
Flagging this for us to discuss
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.
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.
Thank you for clarifying.
There is one more question from the list above that I wanted to clarify — from the design spec, it seems that the border color is gray 300, and the divider is gray 200.
While these values seem to align with the inline comments where the grays are defined, I noticed that we have some variables specific to borders that are not using the same colors — I guess it would be good if you could review where that are being used, and potentially give feedback around whether we can tweak those variables to use gray 300 and 200.
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 second group of vars seem to be applied to the experimental ToggleGroupControl
. They make sense in the context of an interactive element like a form input where there are stricter a11y requirements for contrast. Visual elements (like the menu container) can use the lighter borders.
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.
Good to know, and likely something that we should codify when working on the wider theme / design system
display: grid; | ||
grid-template-columns: minmax( 0, max-content ) 1fr; |
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 is where the main grid layout is defined.
The first column is for the prefix (and can collapse to 0 width if no prefixes are rendered within the same dropdownmenu popover).
The second column take all remaining available space, and is meant to host the wrapper element containing label, help text, and suffix.
{ suffix && ( | ||
<Styled.ItemSuffixWrapper>{ suffix }</Styled.ItemSuffixWrapper> | ||
) } | ||
<Styled.ItemPrefixWrapper>{ prefix }</Styled.ItemPrefixWrapper> |
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 prefix wrapper is always rendered (even when empty) in order to correctly render in the first column of the grid layout.
* from the parent layout (ie. subgrid). | ||
*/ | ||
display: grid; | ||
grid-template-columns: subgrid; |
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.
CSS subgrid enables us to define a grid layout at the menu level, and "propagate" it down all the way to the menu item children.
*/ | ||
grid-column: 2; | ||
|
||
display: flex; |
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 wrapper occupies the second "column" of the grid layout, and is a flexbox container. This mixed grid + flexbox setup enables menu items to align their left indentation based on the presence of at least one prefix, but keeps independent around the right-side alignment
|
||
export const DropdownMenuGroup = styled( Ariakit.MenuGroup )` | ||
/* Ignore this element when calculating the layout. Useful for subgrid */ | ||
display: contents; |
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.
Display contents allows us to ignore this element when calculating the layout, and look at its children directly
aria-hidden="true" | ||
icon={ chevronRightSmall } | ||
size={ 24 } | ||
preserveAspectRatio="xMidYMid slice" |
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.
preserveAspectRatio
is used to resize the width of the icon while preserving its real size (ie. slicing the SVG viewport)
<ExampleSlotFill.Slot | ||
fillProps={ fillProps } | ||
bubblesVirtually | ||
style={ { display: 'contents' } } |
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.
Adding display: contents
to the Slot
element is necessary, otherwise the slotfill example breaks the grid layout.
|
||
export const DropdownMenuItemLabel = styled( Truncate )` | ||
font-size: ${ font( 'default.fontSize' ) }; | ||
line-height: 20px; |
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.
Do we have any presets for line-height? Or are these values ad-hoc for 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.
We have text styles in Figma, so these values aren't ad hoc. I don't know how well those styles are reflected in the codebase though. All I'm aware of is https://github.com/WordPress/gutenberg/blob/trunk/packages/components/src/text/styles/text-mixins.native.js.
Typography is due a bit of a revamp for the admin work (#53322).
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.
Sounds good, then I guess we can leave this as-is and make sure we revisit after we have some better common typography styles.
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 all looks good and tests well to me - the only deviation from the spec that jumped out to me was that disabled items aren't getting a not-allowed
cursor when hovered, but that may be something you're planning to address separately.
I don't know if this is the right place for this feedback, but for want of anywhere else... Scroll marginsWhen there isn't enough space to render the whole menu, it gets a scrollbar, which is fine, but the menu items need a scroll margin to make sure they're fully visible. --- a/packages/components/src/dropdown-menu-v2-ariakit/styles.ts
+++ b/packages/components/src/dropdown-menu-v2-ariakit/styles.ts
@@ -188,16 +188,21 @@ const baseItem = css`
}
`;
-export const DropdownMenuItem = styled( Ariakit.MenuItem )`
+const menuItem = css`
${ baseItem };
+ scroll-margin: ${ CONTENT_WRAPPER_PADDING };
+`;
+
+export const DropdownMenuItem = styled( Ariakit.MenuItem )`
+ ${ menuItem };
`;
export const DropdownMenuCheckboxItem = styled( Ariakit.MenuItemCheckbox )`
- ${ baseItem };
+ ${ menuItem };
`;
export const DropdownMenuRadioItem = styled( Ariakit.MenuItemRadio )`
- ${ baseItem };
+ ${ menuItem };
`;
export const ItemPrefixWrapper = styled.span` Disabled menu itemsEvery menu item should really be focusable, which isn't the default with Ariakit. We should set index aac8a8844f..a318d295a8 100644
--- a/packages/components/src/dropdown-menu-v2-ariakit/index.tsx
+++ b/packages/components/src/dropdown-menu-v2-ariakit/index.tsx
@@ -53,6 +53,7 @@ export const DropdownMenuItem = forwardRef<
return (
<Styled.DropdownMenuItem
ref={ ref }
+ accessibleWhenDisabled
{ ...props }
hideOnClick={ hideOnClick }
store={ dropdownMenuContext?.store }
@@ -86,6 +87,7 @@ export const DropdownMenuCheckboxItem = forwardRef<
return (
<Styled.DropdownMenuCheckboxItem
ref={ ref }
+ accessibleWhenDisabled
{ ...props }
hideOnClick={ hideOnClick }
store={ dropdownMenuContext?.store }
@@ -130,6 +132,7 @@ export const DropdownMenuRadioItem = forwardRef<
return (
<Styled.DropdownMenuRadioItem
ref={ ref }
+ accessibleWhenDisabled
{ ...props }
hideOnClick={ hideOnClick }
store={ dropdownMenuContext?.store } |
accfcf6
to
264b4fc
Compare
Thank you @chad1008 and @andrewhayward for your reviews! I've pushed 310eb12, da57e59 and 264b4fc which should address your feedback. @jameskoster , would you be able to take a look at this PR? I also left a couple of comments (one, two) highlighting a few points that I wanted to discuss. |
Flaky tests detected in 264b4fc. 🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/6955817559
|
… scrolled into view
c2c80e6
to
d8e6465
Compare
c1ce534
to
5e02c8c
Compare
@jameskoster and @WordPress/gutenberg-components , I believe that this PR is ready for a last round of review. It would be great if we could merge this PR soon, since it unblocks a bunch of other dropdownmenu-related work. |
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.
@jameskoster thank you for the detailed screenshot! Done |
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 think we're looking good. There might be some minor visual tweaks down the road as we make more practical use of the component, but those are easy to revisit in smaller PRs as required.
What?
Closes #55933
This PR includes a series of tweaks to the experimental new version of
DropdownMenu
, based on the specs shared in #55933.Main tweaks:
Why?
The design spec brings a coherent look with the rest of the components library, and addresses a few complex scenarios when dealing with some combinations of menu items and their contents.
How?
The most complex bits in the implementation:
Truncate
component under the hoodTesting Instructions
Open the "DropdownMenu v2 ariakit" Storybook examples, make sure that the component follows the design specs
Screenshots or screencast
dropdown-menu-v2-tweaks.mp4