Skip to content

Commit

Permalink
DataViews list layout: hide actions menu when there is only one actio…
Browse files Browse the repository at this point in the history
…n and is primary (#67015)

Co-authored-by: oandregal <[email protected]>
Co-authored-by: Mamaduka <[email protected]>
  • Loading branch information
3 people authored Nov 15, 2024
1 parent 8eb0bf1 commit a750125
Showing 1 changed file with 31 additions and 27 deletions.
58 changes: 31 additions & 27 deletions packages/dataviews/src/dataviews-layouts/list/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -170,11 +170,13 @@ function ListItem< Item >( {
( action ) => action.isPrimary && !! action.icon
);
return {
primaryAction: _primaryActions?.[ 0 ],
primaryAction: _primaryActions[ 0 ],
eligibleActions: _eligibleActions,
};
}, [ actions, item ] );

const hasOnlyOnePrimaryAction = primaryAction && actions.length === 1;

const renderedMediaField = mediaField?.render ? (
<div className="dataviews-view-list__media-wrapper">
<mediaField.render item={ item } />
Expand All @@ -194,33 +196,35 @@ function ListItem< Item >( {
item={ item }
/>
) }
<div role="gridcell">
<Menu
trigger={
<Composite.Item
id={ generateDropdownTriggerCompositeId(
idPrefix
) }
render={
<Button
size="small"
icon={ moreVertical }
label={ __( 'Actions' ) }
accessibleWhenDisabled
disabled={ ! actions.length }
onKeyDown={ onDropdownTriggerKeyDown }
/>
}
{ ! hasOnlyOnePrimaryAction && (
<div role="gridcell">
<Menu
trigger={
<Composite.Item
id={ generateDropdownTriggerCompositeId(
idPrefix
) }
render={
<Button
size="small"
icon={ moreVertical }
label={ __( 'Actions' ) }
accessibleWhenDisabled
disabled={ ! actions.length }
onKeyDown={ onDropdownTriggerKeyDown }
/>
}
/>
}
placement="bottom-end"
>
<ActionsMenuGroup
actions={ eligibleActions }
item={ item }
/>
}
placement="bottom-end"
>
<ActionsMenuGroup
actions={ eligibleActions }
item={ item }
/>
</Menu>
</div>
</Menu>
</div>
) }
</HStack>
);

Expand Down

1 comment on commit a750125

@github-actions
Copy link

Choose a reason for hiding this comment

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

Flaky tests detected in a750125.
Some tests passed with failed attempts. The failures may not be related to this commit but are still reported for visibility. See the documentation for more information.

🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/11854069391
📝 Reported issues:

Please sign in to comment.