Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
157f8e7
Popover: add new anchor prop, mark other anchor props as deprecated
ciampo Aug 30, 2022
c185f24
Add `anchor` prop to Storybook
ciampo Aug 30, 2022
76fd3f2
Add WP version for deprecated props removal
ciampo Aug 30, 2022
28c7b18
Do not render fallback anchor if there is already a prop-derived anchor
ciampo Aug 30, 2022
16e66d4
Block inbetween inserter: use Popover's new anchor prop (#43693)
ciampo Aug 31, 2022
7b62c02
ListViewDropIndicator: use Popover s new anchor prop (#43694)
ciampo Aug 31, 2022
eef3dc6
Temporarily disable derpecation warnings
ciampo Aug 31, 2022
1866f3f
Block toolbar: use Popover's new anchor prop (#43692)
ciampo Aug 31, 2022
fb6f2ee
Dropdown: use Popover s new anchor prop (#43698)
ciampo Aug 31, 2022
3e59ec1
BlockPopover: prevent error when `selectedElement` is not defined
ciampo Sep 1, 2022
c19495c
Try to avoid infinite loop
ciampo Sep 1, 2022
c342d79
Update PanelRow docs
ciampo Sep 2, 2022
c3a3f61
Edit navigation menu actions: use Popover s new anchor prop
ciampo Sep 2, 2022
03eb730
BorderBoxControl: use Popover's new anchor prop (#43789)
ciampo Sep 5, 2022
33c87f1
Image URL Input: use new anchor prop for Popover (#43784)
ciampo Sep 5, 2022
d1890ed
Edit site Actions: use new anchor prop for Popover (#43810)
ciampo Sep 5, 2022
044dd4a
Buttons block: use new Popover anchor prop (#43785)
ciampo Sep 5, 2022
f9fbae5
Navigation block: use new anchor prop for Popover (#43786)
ciampo Sep 5, 2022
13327ef
Post Date block: use new anchor prop for Popover (#43787)
ciampo Sep 5, 2022
a659e87
Tooltip: refactor using Popover's new anchor prop (#43799)
ciampo Sep 5, 2022
4db67fc
Improve docs around using state instead of refs for the anchor element
ciampo Sep 6, 2022
aadd730
Allow `anchor` to be `null`
ciampo Sep 6, 2022
c787c54
Edit Post: use Popover's new anchor prop (#43808)
ciampo Sep 6, 2022
0ac5e79
Refactor `useAnchorRef` and related components to work with the new P…
ciampo Sep 6, 2022
f9a748a
Re-enable deprecation warnings
ciampo Sep 6, 2022
bc75d2f
Remove fall back to `undefined` from `null`
ciampo Sep 6, 2022
b4973f4
Ensure reactive updates when the popover anchor updates
ciampo Sep 6, 2022
7a7179f
Refactor SocialLinkEdit component to use `anchor` instead of `anchorRef`
ciampo Sep 7, 2022
42a72ac
CHANGELOG
ciampo Sep 7, 2022
8c76d7b
Add new `useAnchor` hook instead of changing existing `useAnchorRef` …
ciampo Sep 7, 2022
d09cbfe
Fix API docs
ciampo Sep 7, 2022
dffc311
Update Popover unit tests
ciampo Sep 7, 2022
dd1b771
Remove unused import
ciampo Sep 7, 2022
24c099a
Use DOMRect in the DomRectWithOwnerDocument type
ciampo Sep 9, 2022
1d11ed2
Improve the wording of deprecation warnings
ciampo Sep 14, 2022
caacb0e
Put more emphasis on storing anchor in local state
ciampo Sep 14, 2022
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
Prev Previous commit
Next Next commit
BorderBoxControl: use Popover's new anchor prop (#43789)
* BorderBoxControl: use new `anchor` prop for `Popover`

* Make sure anchor value is `undefined` instead of `null`
  • Loading branch information
ciampo committed Sep 14, 2022
commit 03eb730f7839c496c1bd5386e23d86fdc571b5e3
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
/**
* External dependencies
*/
import type { ComponentProps } from 'react';
/**
* WordPress dependencies
*/
import { __ } from '@wordpress/i18n';
import { useRef } from '@wordpress/element';
import { useCallback, useState, useEffect } from '@wordpress/element';
import { useMergeRefs } from '@wordpress/compose';

/**
Expand All @@ -18,6 +14,7 @@ import { Grid } from '../../grid';
import { contextConnect, WordPressComponentProps } from '../../ui/context';
import { useBorderBoxControlSplitControls } from './hook';

import type { BorderControlProps } from '../../border-control/types';
import type { SplitControlsProps } from '../types';

const BorderBoxControlSplitControls = (
Expand All @@ -40,18 +37,27 @@ const BorderBoxControlSplitControls = (
__next36pxDefaultSize,
...otherProps
} = useBorderBoxControlSplitControls( props );
const containerRef = useRef();
const mergedRef = useMergeRefs( [ containerRef, forwardedRef ] );
const popoverProps: ComponentProps<
typeof BorderControl
>[ '__unstablePopoverProps' ] = popoverPlacement
? {

const [ popoverProps, setPopoverProps ] =
useState< BorderControlProps[ '__unstablePopoverProps' ] >();
const [ popoverAnchor, setPopoverAnchor ] = useState< Element >();

const containerRef = useCallback( ( node ) => {
setPopoverAnchor( node ?? undefined );
}, [] );

useEffect( () => {
if ( popoverPlacement ) {
setPopoverProps( {
placement: popoverPlacement,
offset: popoverOffset,
anchorRef: containerRef,
anchor: popoverAnchor,
shift: true,
}
: undefined;
} );
} else {
setPopoverProps( undefined );
}
}, [ popoverPlacement, popoverOffset, popoverAnchor ] );

const sharedBorderControlProps = {
colors,
Expand All @@ -64,6 +70,8 @@ const BorderBoxControlSplitControls = (
__next36pxDefaultSize,
};

const mergedRef = useMergeRefs( [ containerRef, forwardedRef ] );

return (
<Grid { ...otherProps } ref={ mergedRef } gap={ 4 }>
<BorderBoxControlVisualizer
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,8 @@
/**
* External dependencies
*/
import type { ComponentProps } from 'react';

/**
* WordPress dependencies
*/
import { __ } from '@wordpress/i18n';
import { useRef } from '@wordpress/element';
import { useCallback, useState, useEffect } from '@wordpress/element';
import { useMergeRefs } from '@wordpress/compose';

/**
Expand All @@ -24,7 +19,10 @@ import { contextConnect, WordPressComponentProps } from '../../ui/context';
import { useBorderBoxControl } from './hook';

import type { BorderBoxControlProps } from '../types';
import type { LabelProps } from '../../border-control/types';
import type {
LabelProps,
BorderControlProps,
} from '../../border-control/types';

const BorderLabel = ( props: LabelProps ) => {
const { label, hideLabelFromVision } = props;
Expand Down Expand Up @@ -67,18 +65,29 @@ const BorderBoxControl = (
__next36pxDefaultSize = false,
...otherProps
} = useBorderBoxControl( props );
const containerRef = useRef();
const mergedRef = useMergeRefs( [ containerRef, forwardedRef ] );
const popoverProps: ComponentProps<
typeof BorderControl
>[ '__unstablePopoverProps' ] = popoverPlacement
? {

const [ popoverProps, setPopoverProps ] =
useState< BorderControlProps[ '__unstablePopoverProps' ] >();
const [ popoverAnchor, setPopoverAnchor ] = useState< Element >();

const containerRef = useCallback( ( node ) => {
setPopoverAnchor( node ?? undefined );
}, [] );

useEffect( () => {
if ( popoverPlacement ) {
setPopoverProps( {
placement: popoverPlacement,
offset: popoverOffset,
anchorRef: containerRef,
anchor: popoverAnchor,
shift: true,
}
: undefined;
} );
} else {
setPopoverProps( undefined );
}
}, [ popoverPlacement, popoverOffset, popoverAnchor ] );

const mergedRef = useMergeRefs( [ containerRef, forwardedRef ] );

return (
<View className={ className } { ...otherProps } ref={ mergedRef }>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ Default.args = {
width: '1px',
},
__next36pxDefaultSize: false,
popoverPlacement: 'right-start',
};

const WrapperView = styled.div`
Expand Down
2 changes: 1 addition & 1 deletion packages/components/src/popover/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export type PopoverProps = {
* be an `Element` or, alternatively, a `VirtualElement` — ie. an object with
* the `getBoundingClientRect()` and the `ownerDocument` properties defined.
*/
anchor: Element | VirtualElement;
anchor?: Element | VirtualElement;
/**
* Whether the popover should animate when opening.
*
Expand Down