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

Page list: Fix submenu colors #44310

Closed
wants to merge 4 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 47 additions & 1 deletion packages/block-library/src/page-list/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -164,14 +164,37 @@ const PageItems = memo( function PageItems( {
} ) {
const pages = pagesByParentId.get( parentId );
const frontPageId = useFrontPageId();
const isNavigationChild = 'showSubmenuIcon' in context;
const isSubmenuItem = depth > 0;

// User-set custom colors for the submenu needs to be added inline.
// If there are no user-set colors on the submenu,
// inherit the user-set colors from the navigation block.
const blockProps = useBlockProps();
const customSubmenuStyles = {
...blockProps.style,
color: !! context.customOverlayTextColor
? context.customOverlayTextColor
: context.customTextColor,
background: !! context.customOverlayBackgroundColor
? context.customOverlayBackgroundColor
: context.customBackgroundColor,
};

// If there is no overlay color set, inherit the color from the navigation block.
const textColor = !! context.overlayTextColor
? context.overlayTextColor
: context.textColor;
const backgroundColor = !! context.overlayBackgroundColor
? context.overlayBackgroundColor
: context.backgroundColor;

if ( ! pages?.length ) {
return [];
}

return pages.map( ( page ) => {
const hasChildren = pagesByParentId.has( page.id );
const isNavigationChild = 'showSubmenuIcon' in context;
return (
<li
key={ page.id }
Expand All @@ -183,7 +206,30 @@ const PageItems = memo( function PageItems( {
! context.openSubmenusOnClick &&
context.showSubmenuIcon,
'menu-item-home': page.id === frontPageId,
'has-text-color':
( !! context.overlayTextColor && isSubmenuItem ) ||
( !! context.customOverlayTextColor &&
isSubmenuItem ) ||
( !! context.customTextColor && isSubmenuItem ) ||
( !! context.textColor && isSubmenuItem ),
[ getColorClassName( 'color', textColor ) ]:
!! textColor && isSubmenuItem,
'has-background':
!! (
context.overlayBackgroundColor && isSubmenuItem
) ||
!! (
context.customOverlayBackgroundColor &&
isSubmenuItem
) ||
!! ( context.backgroundColor && isSubmenuItem ) ||
!! ( context.customBackgroundColor && isSubmenuItem ),
[ getColorClassName(
'background-color',
backgroundColor
) ]: !! backgroundColor && isSubmenuItem,
} ) }
style={ !! isSubmenuItem ? customSubmenuStyles : undefined }
>
{ hasChildren && context.openSubmenusOnClick ? (
<>
Expand Down