Skip to content
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
8 changes: 8 additions & 0 deletions packages/dom/src/dom/hidden-caret-range-from-point.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import getComputedStyle from './get-computed-style';
export default function hiddenCaretRangeFromPoint( doc, x, y, container ) {
const originalZIndex = container.style.zIndex;
const originalPosition = container.style.position;
const originalBorderRadius = container.style.borderRadius;

const { position = 'static' } = getComputedStyle( container );

Expand All @@ -29,10 +30,17 @@ export default function hiddenCaretRangeFromPoint( doc, x, y, container ) {

container.style.zIndex = '10000';

// When an element has border radius, the x/y coordinates can incorrectly fall
// outside the element because of the radius. Temporarily reset the value
// to ensure the coordinates are tested against a rectangle and not a pill-shaped
// element. See https://github.com/WordPress/gutenberg/issues/72053 for more info.
container.style.borderRadius = '0';

const range = caretRangeFromPoint( doc, x, y );

container.style.zIndex = originalZIndex;
container.style.position = originalPosition;
container.style.borderRadius = originalBorderRadius;

return range;
}
25 changes: 25 additions & 0 deletions test/e2e/specs/editor/various/writing-flow.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -539,6 +539,31 @@ test.describe( 'Writing Flow (@firefox, @webkit)', () => {
] );
} );

// Regression test for https://github.com/WordPress/gutenberg/issues/72053.
test( 'should navigate contenteditable with border radius', async ( {
editor,
page,
} ) => {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You probably did, but you double checked this failed on trunk? :)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fails on trunk 👍🏻

Screenshot 2026-03-04 at 10 36 05 am

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep 👍

await page.keyboard.press( 'Enter' );
await page.keyboard.press( 'Enter' );
await editor.canvas.locator( ':root' ).evaluate( () => {
document.activeElement.style.borderRadius = '50px';
} );
await page.keyboard.press( 'ArrowUp' );
await page.keyboard.type( '1' );

expect( await editor.getBlocks() ).toMatchObject( [
{
name: 'core/paragraph',
attributes: { content: '1' },
},
{
name: 'core/paragraph',
attributes: { content: '' },
},
] );
} );

test( 'should not prematurely multi-select', async ( {
editor,
page,
Expand Down
Loading