Skip to content

Commit

Permalink
Cover Block: Move Clear Media button from Inspector Controls to Block…
Browse files Browse the repository at this point in the history
… Controls. (#64630)


Unlinked contributors: rohitmathur-7.

Co-authored-by: Mamaduka <mamaduka@git.wordpress.org>
Co-authored-by: jasmussen <joen@git.wordpress.org>
Co-authored-by: akasunil <sunil25393@git.wordpress.org>
Co-authored-by: richtabor <richtabor@git.wordpress.org>
  • Loading branch information
5 people authored Aug 24, 2024
1 parent 46ad90a commit 042f320
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 38 deletions.
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

0 comments on commit 042f320

Please sign in to comment.