diff --git a/packages/rich-text/CHANGELOG.md b/packages/rich-text/CHANGELOG.md index a51f9e3af765bb..fdb831c1a8f078 100644 --- a/packages/rich-text/CHANGELOG.md +++ b/packages/rich-text/CHANGELOG.md @@ -2,6 +2,10 @@ ## Unreleased +### Bug Fixes + +- Remove the format boundary highlight from a field when the selection moves to another field ([#86168](https://github.com/WordPress/gutenberg/pull/86168)). + ## 8.0.0 (2026-10-20) ### Breaking Changes diff --git a/packages/rich-text/src/hook/index.ts b/packages/rich-text/src/hook/index.ts index 8d4762bc8b4879..b1b2340b4aa2de 100644 --- a/packages/rich-text/src/hook/index.ts +++ b/packages/rich-text/src/hook/index.ts @@ -215,6 +215,13 @@ function useRichTextBase( { hasFocus( ref.current! ) ) { applyRecord( recordRef.current! ); + } else if ( + recordRef.current!.start === undefined && + ref.current!.querySelector( '[data-rich-text-format-boundary]' ) + ) { + // The editing host may be an ancestor that keeps focus, so the + // boundary would remain visible. + applyRecord( recordRef.current! ); } }, [ selectionStart, selectionEnd, isSelected ] ); diff --git a/test/e2e/specs/editor/various/rich-text.spec.js b/test/e2e/specs/editor/various/rich-text.spec.js index 29224e2abad0b5..c3ed93af56f22b 100644 --- a/test/e2e/specs/editor/various/rich-text.spec.js +++ b/test/e2e/specs/editor/various/rich-text.spec.js @@ -154,6 +154,36 @@ test.describe( 'RichText (@firefox, @webkit)', () => { ); } ); + test( 'should not highlight the format of a deselected block', async ( { + page, + editor, + } ) => { + await editor.insertBlock( { + name: 'core/heading', + attributes: { content: 'Heading text end' }, + } ); + await editor.insertBlock( { + name: 'core/paragraph', + attributes: { content: 'a italic b' }, + } ); + const italic = editor.canvas.locator( 'em' ); + await italic.click(); + await expect( italic ).not.toHaveCSS( + 'background-color', + 'rgba(0, 0, 0, 0)' + ); + + await page.keyboard.press( 'ArrowUp' ); + + await expect( + editor.canvas.getByRole( 'document', { name: 'Block: Heading' } ) + ).toHaveClass( /is-selected/ ); + await expect( italic ).toHaveCSS( + 'background-color', + 'rgba(0, 0, 0, 0)' + ); + } ); + test( 'should return focus when pressing formatting button (-firefox)', async ( { page, editor,