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

Block options: disable mode toggle when block is in warning state #7886

Closed
wants to merge 1 commit into from
Closed
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: 1 addition & 0 deletions packages/editor/src/components/block-list/block.js
Original file line number Diff line number Diff line change
Expand Up @@ -500,6 +500,7 @@ export class BlockListBlock extends Component {
clientIds={ clientId }
rootClientId={ rootClientId }
isHidden={ ! ( isHovered || isSelected ) || hoverArea !== 'right' || isTypingWithinBlock }
canEdit={ isValid }
/>
) }
{ shouldShowBreadcrumb && (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { getBlockType, hasBlockSupport } from '@wordpress/blocks';
import { withSelect, withDispatch } from '@wordpress/data';
import { compose } from '@wordpress/compose';

export function BlockModeToggle( { blockType, mode, onToggleMode, small = false } ) {
export function BlockModeToggle( { blockType, mode, onToggleMode, small = false, enabled = true } ) {
if ( ! hasBlockSupport( blockType, 'html', true ) ) {
return null;
}
Expand All @@ -25,6 +25,7 @@ export function BlockModeToggle( { blockType, mode, onToggleMode, small = false
<MenuItem
className="editor-block-settings-menu__control"
onClick={ onToggleMode }
disabled={ ! enabled }
icon="html"
label={ small ? label : undefined }
>
Expand Down
2 changes: 2 additions & 0 deletions packages/editor/src/components/block-settings-menu/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ export class BlockSettingsMenu extends Component {
onSelect,
focus,
isHidden,
canEdit,
onDuplicate,
onRemove,
canDuplicate,
Expand Down Expand Up @@ -142,6 +143,7 @@ export class BlockSettingsMenu extends Component {
<BlockModeToggle
clientId={ firstBlockClientId }
onToggle={ onClose }
enabled={ canEdit }
/>
) }
{ count === 1 && (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,10 @@ describe( 'BlockModeToggle', () => {
mode="visual"
/>
);
const text = wrapper.find( 'MenuItem' ).first().prop( 'children' );
const button = wrapper.find( 'MenuItem' ).first();

expect( text ).toEqual( 'Edit as HTML' );
expect( button.prop( 'children' ) ).toEqual( 'Edit as HTML' );
expect( button.prop( 'disabled' ) ).toBe( false );
} );

it( 'should render the Visual mode button', () => {
Expand All @@ -36,8 +37,22 @@ describe( 'BlockModeToggle', () => {
mode="html"
/>
);
const text = wrapper.find( 'MenuItem' ).first().prop( 'children' );
const button = wrapper.find( 'MenuItem' ).first();

expect( text ).toEqual( 'Edit visually' );
expect( button.prop( 'children' ) ).toEqual( 'Edit visually' );
expect( button.prop( 'disabled' ) ).toBe( false );
} );

it( 'should render a disabled button', () => {
const wrapper = shallow(
<BlockModeToggle
blockType={ { supports: { html: true } } }
mode="html"
enabled={ false }
/>
);
const button = wrapper.find( 'MenuItem' ).first();

expect( button.prop( 'disabled' ) ).toBe( true );
} );
} );