-
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
Merged
+472
−268
Merged
DropdownMenu V2 tweaks #56041
Changes from all commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
660171a
Expose help text subcomponent (uses truncate under the hood)
ciampo 7811b8d
Remove DropdownMenuGroupLabel
ciampo 967796f
Submenu trigger always display chevron next to suffix
ciampo fb2a46d
Tweak gutter so that submenus overlap by 8px
ciampo c92dbc2
Implement auto-indentation via context
ciampo 33db29b
Revert "Implement auto-indentation via context"
ciampo dcb1bdf
Use CSS grid/subgrid to impement auto-indentation
ciampo e37a4f9
Fix slotfill example
ciampo 6c0377a
Tweak sizes, spacing, and colors. Tidy up styles.
ciampo 7dd7588
Add label subcomponent
ciampo 96ed080
Update storybook examples
ciampo 156fbda
Export help text and label subcomponents
ciampo a729bab
CHANGELOG
ciampo d337661
README
ciampo 202247d
Fix unit test
ciampo 864569a
Allow disabled items to be keyboard focusable / accessible
ciampo 6cde2ec
Display the "not allowed" cursor on disabled menu items
ciampo 56b6117
Add scroll-margin to make sure that menu items are fully visible when…
ciampo d7fe484
Update unit tests
ciampo d8e6465
Use inline styles instead of !important
ciampo a6d5ad4
Apply design feedback
ciampo 5e02c8c
CHANGELOG
ciampo c0f12c3
Update submenu shift
ciampo File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,7 +30,6 @@ import type { | |
DropdownMenuContext as DropdownMenuContextType, | ||
DropdownMenuProps, | ||
DropdownMenuGroupProps, | ||
DropdownMenuGroupLabelProps, | ||
DropdownMenuItemProps, | ||
DropdownMenuCheckboxItemProps, | ||
DropdownMenuRadioItemProps, | ||
|
@@ -55,16 +54,23 @@ export const DropdownMenuItem = forwardRef< | |
<Styled.DropdownMenuItem | ||
ref={ ref } | ||
{ ...props } | ||
accessibleWhenDisabled | ||
hideOnClick={ hideOnClick } | ||
store={ dropdownMenuContext?.store } | ||
> | ||
{ prefix && ( | ||
<Styled.ItemPrefixWrapper>{ prefix }</Styled.ItemPrefixWrapper> | ||
) } | ||
{ children } | ||
{ suffix && ( | ||
<Styled.ItemSuffixWrapper>{ suffix }</Styled.ItemSuffixWrapper> | ||
) } | ||
<Styled.ItemPrefixWrapper>{ prefix }</Styled.ItemPrefixWrapper> | ||
|
||
<Styled.DropdownMenuItemContentWrapper> | ||
<Styled.DropdownMenuItemChildrenWrapper> | ||
{ children } | ||
</Styled.DropdownMenuItemChildrenWrapper> | ||
|
||
{ suffix && ( | ||
<Styled.ItemSuffixWrapper> | ||
{ suffix } | ||
</Styled.ItemSuffixWrapper> | ||
) } | ||
</Styled.DropdownMenuItemContentWrapper> | ||
</Styled.DropdownMenuItem> | ||
); | ||
} ); | ||
|
@@ -82,20 +88,30 @@ export const DropdownMenuCheckboxItem = forwardRef< | |
<Styled.DropdownMenuCheckboxItem | ||
ref={ ref } | ||
{ ...props } | ||
accessibleWhenDisabled | ||
hideOnClick={ hideOnClick } | ||
store={ dropdownMenuContext?.store } | ||
> | ||
<Ariakit.MenuItemCheck | ||
store={ dropdownMenuContext?.store } | ||
render={ <Styled.ItemPrefixWrapper /> } | ||
// Override some ariakit inline styles | ||
style={ { width: 'auto', height: 'auto' } } | ||
> | ||
<Icon icon={ check } size={ 24 } /> | ||
</Ariakit.MenuItemCheck> | ||
|
||
{ children } | ||
{ suffix && ( | ||
<Styled.ItemSuffixWrapper>{ suffix }</Styled.ItemSuffixWrapper> | ||
) } | ||
<Styled.DropdownMenuItemContentWrapper> | ||
<Styled.DropdownMenuItemChildrenWrapper> | ||
{ children } | ||
</Styled.DropdownMenuItemChildrenWrapper> | ||
|
||
{ suffix && ( | ||
<Styled.ItemSuffixWrapper> | ||
{ suffix } | ||
</Styled.ItemSuffixWrapper> | ||
) } | ||
</Styled.DropdownMenuItemContentWrapper> | ||
</Styled.DropdownMenuCheckboxItem> | ||
); | ||
} ); | ||
|
@@ -119,17 +135,30 @@ export const DropdownMenuRadioItem = forwardRef< | |
<Styled.DropdownMenuRadioItem | ||
ref={ ref } | ||
{ ...props } | ||
accessibleWhenDisabled | ||
hideOnClick={ hideOnClick } | ||
store={ dropdownMenuContext?.store } | ||
> | ||
<Ariakit.MenuItemCheck | ||
store={ dropdownMenuContext?.store } | ||
render={ <Styled.ItemPrefixWrapper /> } | ||
// Override some ariakit inline styles | ||
style={ { width: 'auto', height: 'auto' } } | ||
> | ||
<Icon icon={ radioCheck } size={ 24 } /> | ||
</Ariakit.MenuItemCheck> | ||
{ children } | ||
{ suffix } | ||
|
||
<Styled.DropdownMenuItemContentWrapper> | ||
<Styled.DropdownMenuItemChildrenWrapper> | ||
{ children } | ||
</Styled.DropdownMenuItemChildrenWrapper> | ||
|
||
{ suffix && ( | ||
<Styled.ItemSuffixWrapper> | ||
{ suffix } | ||
</Styled.ItemSuffixWrapper> | ||
) } | ||
</Styled.DropdownMenuItemContentWrapper> | ||
</Styled.DropdownMenuRadioItem> | ||
); | ||
} ); | ||
|
@@ -148,20 +177,6 @@ export const DropdownMenuGroup = forwardRef< | |
); | ||
} ); | ||
|
||
export const DropdownMenuGroupLabel = forwardRef< | ||
HTMLDivElement, | ||
WordPressComponentProps< DropdownMenuGroupLabelProps, 'div', false > | ||
>( function DropdownMenuGroupLabel( props, ref ) { | ||
const dropdownMenuContext = useContext( DropdownMenuContext ); | ||
return ( | ||
<Styled.DropdownMenuGroupLabel | ||
ref={ ref } | ||
{ ...props } | ||
store={ dropdownMenuContext?.store } | ||
/> | ||
); | ||
} ); | ||
|
||
const UnconnectedDropdownMenu = ( | ||
props: WordPressComponentProps< DropdownMenuProps, 'div', false >, | ||
ref: React.ForwardedRef< HTMLDivElement > | ||
|
@@ -280,12 +295,16 @@ const UnconnectedDropdownMenu = ( | |
dropdownMenuStore.parent | ||
? cloneElement( trigger, { | ||
// Add submenu arrow, unless a `suffix` is explicitly specified | ||
suffix: trigger.props.suffix ?? ( | ||
<Styled.SubmenuChevronIcon | ||
aria-hidden="true" | ||
icon={ chevronRightSmall } | ||
size={ 24 } | ||
/> | ||
suffix: ( | ||
<> | ||
{ trigger.props.suffix } | ||
<Styled.SubmenuChevronIcon | ||
aria-hidden="true" | ||
icon={ chevronRightSmall } | ||
size={ 24 } | ||
preserveAspectRatio="xMidYMid slice" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
/> | ||
</> | ||
), | ||
} ) | ||
: trigger | ||
|
@@ -297,8 +316,12 @@ const UnconnectedDropdownMenu = ( | |
{ ...otherProps } | ||
modal={ modal } | ||
store={ dropdownMenuStore } | ||
gutter={ gutter ?? ( dropdownMenuStore.parent ? 16 : 8 ) } | ||
shift={ shift ?? ( dropdownMenuStore.parent ? -8 : 0 ) } | ||
// Root menu has an 8px distance from its trigger, | ||
// otherwise 0 (which causes the submenu to slightly overlap) | ||
gutter={ gutter ?? ( dropdownMenuStore.parent ? 0 : 8 ) } | ||
// Align nested menu by the same (but opposite) amount | ||
// as the menu container's padding. | ||
shift={ shift ?? ( dropdownMenuStore.parent ? -4 : 0 ) } | ||
hideOnHoverOutside={ false } | ||
data-side={ appliedPlacementSide } | ||
variant={ variant } | ||
|
@@ -332,3 +355,29 @@ export const DropdownMenuSeparator = forwardRef< | |
/> | ||
); | ||
} ); | ||
|
||
export const DropdownMenuItemLabel = forwardRef< | ||
HTMLSpanElement, | ||
WordPressComponentProps< { children: React.ReactNode }, 'span', true > | ||
>( function DropdownMenuItemLabel( props, ref ) { | ||
return ( | ||
<Styled.DropdownMenuItemLabel | ||
numberOfLines={ 1 } | ||
ref={ ref } | ||
{ ...props } | ||
/> | ||
); | ||
} ); | ||
|
||
export const DropdownMenuItemHelpText = forwardRef< | ||
HTMLSpanElement, | ||
WordPressComponentProps< { children: React.ReactNode }, 'span', true > | ||
>( function DropdownMenuItemHelpText( props, ref ) { | ||
return ( | ||
<Styled.DropdownMenuItemHelpText | ||
numberOfLines={ 2 } | ||
ref={ ref } | ||
{ ...props } | ||
/> | ||
); | ||
} ); |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.