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

DataViews list layout: hide actions menu when there is only one action and is primary #67015

Merged
merged 2 commits into from
Nov 15, 2024
Merged
Changes from 1 commit
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
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;
Copy link
Member Author

Choose a reason for hiding this comment

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

Note this checks actions, not eligibleActions. This is intentional to make sure that we only hide the item menu when all the items has a single action. We wouldn't want to show only the icon for some and the icon + the actions menu for others.


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
Loading