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

Cover Block: Move Clear Media button from Inspector Controls to Block Controls. #64630

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
13 changes: 12 additions & 1 deletion packages/block-library/src/cover/edit/block-controls.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
__experimentalBlockFullHeightAligmentControl as FullHeightAlignmentControl,
privateApis as blockEditorPrivateApis,
} from '@wordpress/block-editor';
import { MenuItem } from '@wordpress/components';
import { __ } from '@wordpress/i18n';

/**
Expand All @@ -26,6 +27,7 @@ export default function CoverBlockControls( {
onSelectMedia,
currentSettings,
toggleUseFeaturedImage,
onClearMedia,
} ) {
const { contentPosition, id, useFeaturedImage, minHeight, minHeightUnit } =
attributes;
Expand Down Expand Up @@ -101,7 +103,16 @@ export default function CoverBlockControls( {
onToggleFeaturedImage={ toggleUseFeaturedImage }
useFeaturedImage={ useFeaturedImage }
name={ ! url ? __( 'Add Media' ) : __( 'Replace' ) }
/>
>
{ !! url && (
<MenuItem
className="block-library-cover__reset-button"
onClick={ onClearMedia }
>
{ __( 'Reset' ) }
</MenuItem>
) }
</MediaReplaceFlow>
</BlockControls>
</>
);
Expand Down
1 change: 1 addition & 0 deletions packages/block-library/src/cover/edit/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -398,6 +398,7 @@ function CoverEdit( {
onSelectMedia={ onSelectMedia }
currentSettings={ currentSettings }
toggleUseFeaturedImage={ toggleUseFeaturedImage }
onClearMedia={ onClearMedia }
/>
);

Expand Down
13 changes: 0 additions & 13 deletions packages/block-library/src/cover/edit/inspector-controls.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,9 @@
*/
import { useMemo } from '@wordpress/element';
import {
Button,
ExternalLink,
FocalPointPicker,
PanelBody,
PanelRow,
RangeControl,
TextareaControl,
ToggleControl,
Expand Down Expand Up @@ -93,7 +91,6 @@ export default function CoverInspectorControls( {
coverRef,
currentSettings,
updateDimRatio,
onClearMedia,
} ) {
const {
useFeaturedImage,
Expand Down Expand Up @@ -228,16 +225,6 @@ export default function CoverInspectorControls( {
}
/>
) }
<PanelRow>
<Button
variant="secondary"
size="small"
className="block-library-cover__reset-button"
onClick={ onClearMedia }
>
{ __( 'Clear Media' ) }
</Button>
</PanelRow>
</PanelBody>
) }
</InspectorControls>
Expand Down
52 changes: 28 additions & 24 deletions packages/block-library/src/cover/test/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,34 @@ describe( 'Cover block', () => {
'is-position-top-left'
);
} );

test( 'clears media when clear media button clicked', async () => {
await setup( {
url: 'http://localhost/my-image.jpg',
} );

await selectBlock( 'Block: Cover' );
expect(
within( screen.getByLabelText( 'Block: Cover' ) ).getByRole(
'img'
)
).toBeInTheDocument();

await userEvent.click(
screen.getByRole( 'button', { name: 'Replace' } )
);
await userEvent.click(
screen.getByRole( 'menuitem', {
name: 'Reset',
} )
);

expect(
within( screen.getByLabelText( 'Block: Cover' ) ).queryByRole(
'img'
)
).not.toBeInTheDocument();
} );
} );

describe( 'Inspector controls', () => {
Expand Down Expand Up @@ -242,30 +270,6 @@ describe( 'Cover block', () => {
expect( screen.getByAltText( 'Me' ) ).toBeInTheDocument();
} );

test( 'clears media when clear media button clicked', async () => {
await setup( {
url: 'http://localhost/my-image.jpg',
} );

await selectBlock( 'Block: Cover' );
expect(
within( screen.getByLabelText( 'Block: Cover' ) ).getByRole(
'img'
)
).toBeInTheDocument();

await userEvent.click(
screen.getByRole( 'button', {
name: 'Clear Media',
} )
);
expect(
within( screen.getByLabelText( 'Block: Cover' ) ).queryByRole(
'img'
)
).not.toBeInTheDocument();
} );

describe( 'Color panel', () => {
test( 'applies selected opacity to block when number control value changed', async () => {
const { container } = await setup();
Expand Down
Loading