Skip to content

Commit

Permalink
If there is only one action and is primary, hide the actions menu
Browse files Browse the repository at this point in the history
  • Loading branch information
oandregal committed Nov 14, 2024
1 parent e7f0dc5 commit 3fb8ef7
Showing 1 changed file with 30 additions and 26 deletions.
56 changes: 30 additions & 26 deletions packages/dataviews/src/dataviews-layouts/list/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,8 @@ function ListItem< Item >( {
};
}, [ 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

0 comments on commit 3fb8ef7

Please sign in to comment.