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

Site Editor: Disable the revision button if there is no clickable menu #51851

Merged
merged 1 commit into from
Jun 25, 2023
Merged
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
58 changes: 34 additions & 24 deletions packages/edit-site/src/components/global-styles/ui.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
__experimentalNavigatorScreen as NavigatorScreen,
__experimentalUseNavigator as useNavigator,
createSlotFill,
Button,
DropdownMenu,
MenuGroup,
MenuItem,
Expand Down Expand Up @@ -142,33 +143,42 @@ function GlobalStylesRevisionsMenu() {

return (
<GlobalStylesMenuFill>
<DropdownMenu icon={ backup } label={ __( 'Revisions' ) }>
{ ( { onClose } ) => (
<MenuGroup>
{ hasRevisions && (
{ canReset || hasRevisions ? (
<DropdownMenu icon={ backup } label={ __( 'Revisions' ) }>
{ ( { onClose } ) => (
<MenuGroup>
{ hasRevisions && (
<MenuItem
onClick={ loadRevisions }
icon={
<RevisionsCountBadge>
{ revisionsCount }
</RevisionsCountBadge>
}
>
{ __( 'Revision history' ) }
</MenuItem>
) }
<MenuItem
onClick={ loadRevisions }
icon={
<RevisionsCountBadge>
{ revisionsCount }
</RevisionsCountBadge>
}
onClick={ () => {
onReset();
onClose();
} }
disabled={ ! canReset }
>
{ __( 'Revision history' ) }
{ __( 'Reset to defaults' ) }
</MenuItem>
) }
<MenuItem
onClick={ () => {
onReset();
onClose();
} }
disabled={ ! canReset }
>
{ __( 'Reset to defaults' ) }
</MenuItem>
</MenuGroup>
) }
</DropdownMenu>
</MenuGroup>
) }
</DropdownMenu>
) : (
<Button
label={ __( 'Revisions' ) }
icon={ backup }
disabled
__experimentalIsFocusable
Copy link
Contributor Author

Choose a reason for hiding this comment

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

__experimentalIsFocusable makes inactive buttons focusable. If it is not focusable, the tooltip cannot be displayed, and the user may not know what this button means.

This approach is also used in block mover buttons, for example.

move-up

/>
) }
</GlobalStylesMenuFill>
);
}
Expand Down