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

Enforce isAlternate on ToolbarDropdownMenu #33129

Merged
merged 3 commits into from
Jul 1, 2021
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
1 change: 0 additions & 1 deletion packages/block-library/src/social-links/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,6 @@ export function SocialLinksEdit( props ) {

const POPOVER_PROPS = {
position: 'bottom right',
isAlternate: true,
};

return (
Expand Down
25 changes: 11 additions & 14 deletions packages/components/src/toolbar-dropdown-menu/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* WordPress dependencies
*/
import { useContext } from '@wordpress/element';
import { forwardRef, useContext } from '@wordpress/element';

/**
* Internal dependencies
Expand All @@ -10,33 +10,30 @@ import ToolbarItem from '../toolbar-item';
import ToolbarContext from '../toolbar-context';
import DropdownMenu from '../dropdown-menu';

function ToolbarDropdownMenu( props ) {
function ToolbarDropdownMenu( props, ref ) {
const accessibleToolbarState = useContext( ToolbarContext );

if ( ! accessibleToolbarState ) {
return <DropdownMenu { ...props } />;
}

// ToobarItem will pass all props to the render prop child, which will pass
// all props to the toggle of DrpodownMenu. This means that ToolbarDropdownMenu has the same API as
// DrpodownMenu.
// all props to the toggle of DropdownMenu. This means that ToolbarDropdownMenu
// has the same API as DrpodownMenu.
return (
<ToolbarItem>
<ToolbarItem ref={ ref } { ...props.toggleProps }>
{ ( toolbarItemProps ) => (
<DropdownMenu
{ ...props }
toggleProps={
props.toggleProps
? {
...props.toggleProps,
...toolbarItemProps,
}
: toolbarItemProps
}
popoverProps={ {
isAlternate: true,
diegohaz marked this conversation as resolved.
Show resolved Hide resolved
...props.popoverProps,
} }
toggleProps={ toolbarItemProps }
/>
) }
</ToolbarItem>
);
}

export default ToolbarDropdownMenu;
export default forwardRef( ToolbarDropdownMenu );