Skip to content
2 changes: 1 addition & 1 deletion packages/components/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@
- `CardDivider`: Apply the Card's width, display, and border color consistently inside iframes ([#82577](https://github.com/WordPress/gutenberg/pull/82577)).
- `BorderControl`, `BorderBoxControl`: Stop offering `%` as a width unit, since `border-width` does not accept percentages. A width already set in `%` keeps showing its unit ([#83492](https://github.com/WordPress/gutenberg/pull/83492)).
- `UnitControl`: After clearing a value whose unit is not in `units`, give the next typed value the unit shown in the select instead of the cleared one ([#83492](https://github.com/WordPress/gutenberg/pull/83492)).
- `ResizableBox`: Update `re-resizable` to `6.11.2`, which supports React 18 and renders the top and left handles before the content so focus order matches visual order ([#83754](https://github.com/WordPress/gutenberg/pull/83754)).
- `ResizableBox`: Update `re-resizable` from `6.9.0` to `6.11.2`, which supports React 18. A dimension missing from `size` is now reset to `auto` when a resize ends, instead of keeping its resized value ([#83754](https://github.com/WordPress/gutenberg/pull/83754)).
- `SandBox`: Send the page URL as the referrer from iframes inside `allowSameOrigin` sandboxes in Safari, fixing embed previews that require a referrer, such as YouTube's "Error 153" ([#84014](https://github.com/WordPress/gutenberg/pull/84014)).
- `PaletteEdit`: Keep an item's slug when it is renamed, so blocks and styles that reference the preset keep working ([#83750](https://github.com/WordPress/gutenberg/pull/83750)).
- `FocalPointPicker`: End a drag when the pointer is released outside the control, including over the editor canvas ([#83348](https://github.com/WordPress/gutenberg/pull/83348)).
Expand Down
2 changes: 2 additions & 0 deletions packages/components/src/resizable-box/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ ResizableBox is a wrapper around the [re-resizable package](https://github.com/b

Most options are passed directly through to [re-resizable](https://github.com/bokuweb/re-resizable) so you may wish to refer to their documentation. The primary differences in this component are that we set `handleClasses` (to use custom class names) and pass some null values to `handleStyles` (to unset some inline styles).

When you pass `size`, include every dimension that can be resized. When a resize ends, a dimension missing from `size` is reset to `auto` instead of keeping its resized value.

The example below shows how you might use `ResizableBox` to set a width and height inside a block's `edit` component.

```jsx
Expand Down
7 changes: 4 additions & 3 deletions packages/edit-site/src/components/resizable-frame/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ function ResizableFrame( {
};

// Calculate the frame size based on the window width as its resized.
const handleResize = ( _event, _direction, _ref, delta ) => {
const handleResize = ( _event, _direction, ref, delta ) => {
const normalizedDelta = delta.width / resizeRatio;
const deltaAbs = Math.abs( normalizedDelta );
const maxDoubledDelta =
Expand All @@ -127,9 +127,10 @@ function ResizableFrame( {

setIsOversized( updatedWidth > defaultSize.width );

// Width will be controlled by the library (via `resizeRatio`),
// so we only need to update the height.
// `re-resizable` resets a dimension missing from `size` to `auto` when
// the resize ends.
setFrameSize( {
width: ref.style.width,
Comment thread
t-hamano marked this conversation as resolved.
Resolved
height: isOversized
? '100%'
: calculateNewHeight( updatedWidth, defaultAspectRatio ),
Expand Down
57 changes: 57 additions & 0 deletions test/e2e/specs/site-editor/resizable-frame.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import { test, expect } from '@wordpress/e2e-test-utils-playwright';

// Whether the run targets the extensible site editor (v2).
const isSiteEditorV2 = !! process.env.GUTENBERG_E2E_SITE_EDITOR_V2;

test.describe( 'Resizable frame', () => {
test.skip(
isSiteEditorV2,
'The extensible site editor does not render the resizable frame.'
);

test.beforeAll( async ( { requestUtils } ) => {
await requestUtils.activateTheme( 'emptytheme' );
} );

test.afterAll( async ( { requestUtils } ) => {
await requestUtils.activateTheme( 'twentytwentyone' );
} );

test( 'keeps its width after being resized with the mouse', async ( {

Check notice on line 20 in test/e2e/specs/site-editor/resizable-frame.spec.ts

View workflow job for this annotation

GitHub Actions / Run new e2e tests on trunk

This test fails on trunk, a good sign that it catches the bug.
admin,
page,
} ) => {
await admin.visitSiteEditor();

const frame = page.locator( '.edit-site-resizable-frame__inner' );
const getFrameWidth = () =>
frame.evaluate(
( element ) => element.getBoundingClientRect().width
);
await frame.hover();

const handle = page.getByRole( 'separator', {
name: 'Drag to resize',
} );
await expect( handle ).toBeVisible();

const initialWidth = await getFrameWidth();
const handleBox = await handle.boundingBox();
if ( ! handleBox ) {
throw new Error( 'Resize handle bounding box not available' );
}
const handleX = handleBox.x + handleBox.width / 2;
const handleY = handleBox.y + handleBox.height / 2;

await page.mouse.move( handleX, handleY );
await page.mouse.down();
await page.mouse.move( handleX + 100, handleY, { steps: 10 } );

const resizedWidth = await getFrameWidth();
expect( resizedWidth ).toBeLessThan( initialWidth );

await page.mouse.up();
await expect( frame ).not.toContainClass( 'is-resizing' );
expect( await getFrameWidth() ).toBeCloseTo( resizedWidth, 0 );
} );
} );
Loading