`,
}),
@@ -80,6 +82,33 @@ describe('useClickOutside', () => {
expect(close).toHaveBeenCalledTimes(1);
});
+ describe('with a boundary', () => {
+ const isInsideBoundary = target => target.dataset.testid === 'save';
+
+ it('syncs and stays open on a click inside the boundary', async () => {
+ const user = userEvent.setup();
+ const { close, syncContent } = renderHarness({ isInsideBoundary });
+ let syncsAtHandler;
+ button('Save').addEventListener('click', () => {
+ syncsAtHandler = syncContent.mock.calls.length;
+ });
+
+ await user.click(button('Save'));
+
+ expect(syncsAtHandler).toBe(1);
+ expect(close).not.toHaveBeenCalled();
+ });
+
+ it('closes on a click outside the boundary', async () => {
+ const user = userEvent.setup();
+ const { close } = renderHarness({ isInsideBoundary });
+
+ await user.click(button('Outside'));
+
+ expect(close).toHaveBeenCalledTimes(1);
+ });
+ });
+
it('stays open on a click inside', async () => {
const user = userEvent.setup();
const { close } = renderHarness();
diff --git a/docs/rich_text_editor.md b/docs/rich_text_editor.md
index 92027d31fd..c2d53f8568 100644
--- a/docs/rich_text_editor.md
+++ b/docs/rich_text_editor.md
@@ -103,6 +103,13 @@ The context is re-evaluated on every transaction; no listener is needed. The edi
- The editor knows a popup is open from its trigger: any element inside the editor with `aria-haspopup` and `aria-expanded="true"`. KDS's `KDropdownMenu` sets both on its trigger.
- A node view whose button opens a panel rendered beside the editor sets both on that button for as long as the panel is open, and the editor stays open while the panel is used. The inline choice chip does this for its options panel.
+### Controls beside the editor
+- A click outside the editor closes it before the click's own handlers run.
+- An ancestor that renders controls acting on the editor, such as Save, calls `provideEditorBoundary(isInside)` from `composables/useEditorBoundary.js`; `isInside(target)` says whether a click on `target` is on one.
+- `isInside` is true only on the controls, not the space around them: a click there would sync and leave the editor open, with nothing to close it.
+- A click outside the editor for which `isInside` is true syncs the content and leaves the editor open: the control's own handler reads the content and closes the editor if it should.
+- One call covers every editor below that ancestor.
+
### Node views reading consumer state
- ProseMirror mounts node views outside the Vue render tree: no slots, no `$emit` listener.
- tiptap mounts them with `parent: editor.contentComponent`, so `inject` reaches whatever an ancestor of `TipTapEditor` provides.