Skip to content

Commit

Permalink
Fix: Dottips do not disappear when other parts of the editor are enga…
Browse files Browse the repository at this point in the history
…ged. (#17663)
  • Loading branch information
jorgefilipecosta authored Oct 4, 2019
1 parent 3d7e813 commit f68a107
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 3 deletions.
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

0 comments on commit f68a107

Please sign in to comment.