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

Fix: Dottips do not disappear when other parts of the editor are engaged #17663

Merged
Show file tree
Hide file tree
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
2 changes: 2 additions & 0 deletions packages/e2e-test-utils/src/disable-pre-publish-checks.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@
* Internal dependencies
*/
import { toggleScreenOption } from './toggle-screen-option';
import { toggleMoreMenu } from './toggle-more-menu';

/**
* Disables Pre-publish checks.
*/
export async function disablePrePublishChecks() {
await toggleScreenOption( 'Pre-publish Checks', false );
await toggleMoreMenu();
}
2 changes: 2 additions & 0 deletions packages/e2e-test-utils/src/enable-pre-publish-checks.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@
* Internal dependencies
*/
import { toggleScreenOption } from './toggle-screen-option';
import { toggleMoreMenu } from './toggle-more-menu';

/**
* Enables Pre-publish checks.
*/
export async function enablePrePublishChecks() {
await toggleScreenOption( 'Pre-publish Checks', true );
await toggleMoreMenu();
}
2 changes: 0 additions & 2 deletions packages/e2e-test-utils/src/toggle-screen-option.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
*/
import { clickOnCloseModalButton } from './click-on-close-modal-button';
import { clickOnMoreMenuItem } from './click-on-more-menu-item';
import { toggleMoreMenu } from './toggle-more-menu';

/**
* Toggles the screen option with the given label.
Expand All @@ -25,5 +24,4 @@ export async function toggleScreenOption( label, shouldBeChecked = undefined ) {
}

await clickOnCloseModalButton();
await toggleMoreMenu();
}
24 changes: 23 additions & 1 deletion packages/nux/src/components/dot-tip/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { compose } from '@wordpress/compose';
import { Popover, Button, IconButton } from '@wordpress/components';
import { __ } from '@wordpress/i18n';
import { withSelect, withDispatch } from '@wordpress/data';
import { useCallback, useRef } from '@wordpress/element';

function getAnchorRect( anchor ) {
// The default getAnchorRect() excludes an element's top and bottom padding
Expand All @@ -27,6 +28,26 @@ export function DotTip( {
onDismiss,
onDisable,
} ) {
const anchorParent = useRef( null );
const getAnchorRectCallback = useCallback(
( anchor ) => {
anchorParent.current = anchor.parentNode;
return getAnchorRect( anchor );
},
[ anchorParent ]
);
const onFocusOutsideCallback = useCallback(
( event ) => {
if ( ! anchorParent.current ) {
return;
}
if ( anchorParent.current.contains( event.relatedTarget ) ) {
return;
}
onDisable();
},
[ onDisable, anchorParent ]
);
if ( ! isVisible ) {
return null;
}
Expand All @@ -37,10 +58,11 @@ export function DotTip( {
position={ position }
noArrow
focusOnMount="container"
getAnchorRect={ getAnchorRect }
getAnchorRect={ getAnchorRectCallback }
role="dialog"
aria-label={ __( 'Editor tips' ) }
onClick={ onClick }
onFocusOutside={ onFocusOutsideCallback }
>
<p>{ children }</p>
<p>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ exports[`DotTip should render correctly 1`] = `
getAnchorRect={[Function]}
noArrow={true}
onClick={[Function]}
onFocusOutside={[Function]}
position="middle right"
role="dialog"
>
Expand Down