Skip to content

Commit

Permalink
Fix compat layer in disabled context
Browse files Browse the repository at this point in the history
  • Loading branch information
ellatrix committed May 6, 2021
1 parent 81caa98 commit 1de2eb8
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
* WordPress dependencies
*/
import { useContext } from '@wordpress/element';
import { Disabled } from '@wordpress/components';
import deprecated from '@wordpress/deprecated';

/**
Expand All @@ -12,9 +13,10 @@ import BlockPopover from './block-popover';

export default function BlockToolsBackCompat( { children } ) {
const openRef = useContext( InsertionPointOpenRef );
const isDisabled = useContext( Disabled.Context );

// If context is set, `BlockTools` is a parent component.
if ( openRef ) {
if ( openRef || isDisabled ) {
return children;
}

Expand Down
4 changes: 3 additions & 1 deletion packages/components/src/disabled/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ import { focus } from '@wordpress/dom';
*/
import { StyledWrapper } from './styles/disabled-styles';

const { Consumer, Provider } = createContext( false );
const Context = createContext( false );
const { Consumer, Provider } = Context;

/**
* Names of control nodes which qualify for disabled behavior.
Expand Down Expand Up @@ -111,6 +112,7 @@ function Disabled( { className, children, isDisabled = true, ...props } ) {
);
}

Disabled.Context = Context;
Disabled.Consumer = Consumer;

export default Disabled;

0 comments on commit 1de2eb8

Please sign in to comment.