diff --git a/packages/editor/src/components/post-saved-state/index.js b/packages/editor/src/components/post-saved-state/index.js index 57c46ab301338..c3bbad2268276 100644 --- a/packages/editor/src/components/post-saved-state/index.js +++ b/packages/editor/src/components/post-saved-state/index.js @@ -9,6 +9,7 @@ import classnames from 'classnames'; import { __unstableGetAnimateClassName as getAnimateClassName, Button, + Tooltip, } from '@wordpress/components'; import { usePrevious, useViewportMatch } from '@wordpress/compose'; import { useDispatch, useSelect } from '@wordpress/data'; @@ -128,45 +129,53 @@ export default function PostSavedState( { text = shortLabel; } + const buttonAccessibleLabel = text || label; + + /** + * The tooltip needs to be enabled only if the button is not disabled. When + * relying on the internal Button tooltip functionality, this causes the + * resulting `button` element to be always removed and re-added to the DOM, + * causing focus loss. An alternative approach to circumvent the issue + * is not to use the `label` and `shortcut` props on `Button` (which would + * trigger the tooltip), and instead manually wrap the `Button` in a separate + * `Tooltip` component. + */ + const tooltipProps = isDisabled + ? undefined + : { + text: buttonAccessibleLabel, + shortcut: displayShortcut.primary( 's' ), + }; + // Use common Button instance for all saved states so that focus is not // lost. return ( - + + + ); }