Skip to content

Commit

Permalink
Tooltip: Don't render buttons tooltip when show button text labels is…
Browse files Browse the repository at this point in the history
… enabled (#55842)

* Don't render Preview button tooltip when show text labels is enabled.

* Don't render View button tooltip when show text labels is enabled.

* Fix comment block.

* Don't render View Post button tooltip when show text labels is enabled.
  • Loading branch information
afercia authored Nov 23, 2023
1 parent 130a145 commit a7d76c3
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 27 deletions.
2 changes: 2 additions & 0 deletions packages/block-editor/src/components/preview-options/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export default function PreviewOptions( {
deviceType,
setDeviceType,
label,
showIconLabels,
} ) {
const isMobile = useViewportMatch( 'small', '<' );
if ( isMobile ) return null;
Expand All @@ -35,6 +36,7 @@ export default function PreviewOptions( {
disabled: ! isEnabled,
__experimentalIsFocusable: ! isEnabled,
children: viewLabel,
showTooltip: ! showIconLabels,
};
const menuProps = {
'aria-label': __( 'View options' ),
Expand Down
36 changes: 21 additions & 15 deletions packages/edit-post/src/components/device-preview/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,22 +15,27 @@ import { store as coreStore } from '@wordpress/core-data';
import { store as editPostStore } from '../../store';

export default function DevicePreview() {
const { hasActiveMetaboxes, isPostSaveable, isViewable, deviceType } =
useSelect( ( select ) => {
const { getEditedPostAttribute } = select( editorStore );
const { getPostType } = select( coreStore );
const postType = getPostType( getEditedPostAttribute( 'type' ) );
const {
hasActiveMetaboxes,
isPostSaveable,
isViewable,
deviceType,
showIconLabels,
} = useSelect( ( select ) => {
const { getEditedPostAttribute } = select( editorStore );
const { getPostType } = select( coreStore );
const postType = getPostType( getEditedPostAttribute( 'type' ) );

return {
hasActiveMetaboxes: select( editPostStore ).hasMetaBoxes(),
isPostSaveable: select( editorStore ).isEditedPostSaveable(),
isViewable: postType?.viewable ?? false,
deviceType:
select(
editPostStore
).__experimentalGetPreviewDeviceType(),
};
}, [] );
return {
hasActiveMetaboxes: select( editPostStore ).hasMetaBoxes(),
isPostSaveable: select( editorStore ).isEditedPostSaveable(),
isViewable: postType?.viewable ?? false,
deviceType:
select( editPostStore ).__experimentalGetPreviewDeviceType(),
showIconLabels:
select( editPostStore ).isFeatureActive( 'showIconLabels' ),
};
}, [] );
const { __experimentalSetPreviewDeviceType: setPreviewDeviceType } =
useDispatch( editPostStore );

Expand All @@ -41,6 +46,7 @@ export default function DevicePreview() {
deviceType={ deviceType }
setDeviceType={ setPreviewDeviceType }
label={ __( 'Preview' ) }
showIconLabels={ showIconLabels }
>
{ ( { onClose } ) =>
isViewable && (
Expand Down
31 changes: 21 additions & 10 deletions packages/edit-post/src/components/view-link/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,28 @@ import { store as editorStore } from '@wordpress/editor';
import { store as coreStore } from '@wordpress/core-data';
import { useSelect } from '@wordpress/data';

/**
* Internal dependencies
*/
import { store as editPostStore } from '../../store';

export default function ViewLink() {
const { permalink, isPublished, label } = useSelect( ( select ) => {
// Grab post type to retrieve the view_item label.
const postTypeSlug = select( editorStore ).getCurrentPostType();
const postType = select( coreStore ).getPostType( postTypeSlug );
const { permalink, isPublished, label, showIconLabels } = useSelect(
( select ) => {
// Grab post type to retrieve the view_item label.
const postTypeSlug = select( editorStore ).getCurrentPostType();
const postType = select( coreStore ).getPostType( postTypeSlug );

return {
permalink: select( editorStore ).getPermalink(),
isPublished: select( editorStore ).isCurrentPostPublished(),
label: postType?.labels.view_item,
};
}, [] );
return {
permalink: select( editorStore ).getPermalink(),
isPublished: select( editorStore ).isCurrentPostPublished(),
label: postType?.labels.view_item,
showIconLabels:
select( editPostStore ).isFeatureActive( 'showIconLabels' ),
};
},
[]
);

// Only render the view button if the post is published and has a permalink.
if ( ! isPublished || ! permalink ) {
Expand All @@ -32,6 +42,7 @@ export default function ViewLink() {
label={ label || __( 'View post' ) }
href={ permalink }
target="_blank"
showTooltip={ ! showIconLabels }
/>
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,7 @@ export default function HeaderEditMode( { setListViewToggleElement } ) {
isEnabled={
! isFocusMode && hasDefaultEditorCanvasView
}
showIconLabels={ showIconLabels }
>
{ ( { onClose } ) => (
<MenuGroup>
Expand Down
2 changes: 1 addition & 1 deletion packages/edit-site/src/components/save-button/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ export default function SaveButton( {
* Displaying the keyboard shortcut conditionally makes the tooltip
* itself show conditionally. This would trigger a full-rerendering
* of the button that we want to avoid. By setting `showTooltip`,
& the tooltip is always rendered even when there's no keyboard shortcut.
* the tooltip is always rendered even when there's no keyboard shortcut.
*/
showTooltip={ showTooltip }
icon={ icon }
Expand Down
2 changes: 1 addition & 1 deletion packages/editor/src/components/post-saved-state/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ export default function PostSavedState( {
* Displaying the keyboard shortcut conditionally makes the tooltip
* itself show conditionally. This would trigger a full-rerendering
* of the button that we want to avoid. By setting `showTooltip`,
& the tooltip is always rendered even when there's no keyboard shortcut.
* the tooltip is always rendered even when there's no keyboard shortcut.
*/
showTooltip
variant="tertiary"
Expand Down

0 comments on commit a7d76c3

Please sign in to comment.