Skip to content

Virtual whiteboard for sketching hand-drawn like diagrams

feat(packages/excalidraw): add `props.ui.enabled.zoom/scrollBackToContent` (#11677)

David Luzar93dd51060a30
diff --git a/excalidraw-app/tests/LanguageList.test.tsx b/excalidraw-app/tests/LanguageList.test.tsx
index 8170b89dc7..4081371308 100644
--- a/excalidraw-app/tests/LanguageList.test.tsx
+++ b/excalidraw-app/tests/LanguageList.test.tsx
@@ -1,3 +1,4 @@
+import { Excalidraw, MainMenu } from "@excalidraw/excalidraw";
import { defaultLang, languages } from "@excalidraw/excalidraw/i18n";
import { UI } from "@excalidraw/excalidraw/tests/helpers/ui";
import {
@@ -7,15 +8,35 @@ import {
render,
} from "@excalidraw/excalidraw/tests/test-utils";
-import ExcalidrawApp from "../App";
+import { LanguageList } from "../app-language/LanguageList";
+import { useAppLangCode } from "../app-language/language-state";
+import { Provider } from "../app-jotai";
const TEST_LANG_CODE = "fr-FR";
+const TestApp = () => {
+ const [langCode] = useAppLangCode();
+
+ return (
+ <Excalidraw langCode={langCode}>
+ <MainMenu>
+ <MainMenu.ItemCustom>
+ <LanguageList />
+ </MainMenu.ItemCustom>
+ </MainMenu>
+ </Excalidraw>
+ );
+};
+
describe("Test LanguageList", () => {
it("rerenders UI on language change", async () => {
expect(languages.some((lang) => lang.code === TEST_LANG_CODE)).toBe(true);
- await render(<ExcalidrawApp />);
+ await render(
+ <Provider>
+ <TestApp />
+ </Provider>,
+ );
// select rectangle tool to show properties menu
UI.clickTool("rectangle");
diff --git a/excalidraw-app/tests/MobileMenu.test.tsx b/excalidraw-app/tests/MobileMenu.test.tsx
index 70f2162f9b..2d3a031e65 100644
--- a/excalidraw-app/tests/MobileMenu.test.tsx
+++ b/excalidraw-app/tests/MobileMenu.test.tsx
@@ -1,3 +1,4 @@
+import { Excalidraw, WelcomeScreen } from "@excalidraw/excalidraw";
import { UI } from "@excalidraw/excalidraw/tests/helpers/ui";
import {
mockBoundingClientRect,
@@ -5,8 +6,6 @@ import {
restoreOriginalGetBoundingClientRect,
} from "@excalidraw/excalidraw/tests/test-utils";
-import ExcalidrawApp from "../App";
-
describe("Test MobileMenu", () => {
const { h } = window;
const dimensions = { height: 400, width: 800 };
@@ -16,7 +15,11 @@ describe("Test MobileMenu", () => {
});
beforeEach(async () => {
- await render(<ExcalidrawApp />);
+ await render(
+ <Excalidraw>
+ <WelcomeScreen />
+ </Excalidraw>,
+ );
h.app.refreshEditorInterface();
});
diff --git a/excalidraw-app/tests/__snapshots__/MobileMenu.test.tsx.snap b/excalidraw-app/tests/__snapshots__/MobileMenu.test.tsx.snap
index 8bdc0f99ff..13d048abfe 100644
--- a/excalidraw-app/tests/__snapshots__/MobileMenu.test.tsx.snap
+++ b/excalidraw-app/tests/__snapshots__/MobileMenu.test.tsx.snap
@@ -50,11 +50,7 @@ exports[`Test MobileMenu > should initialize with welcome screen and hide once u
<div
class="welcome-screen-center__heading welcome-screen-decor excalifont"
>
- Your drawings are saved in your browser's storage.
- <br />
- Browser storage can be cleared unexpectedly.
- <br />
- Save your work to a file regularly to avoid losing it.
+ Diagrams. Made. Simple.
</div>
<div
class="welcome-screen-menu"
@@ -149,103 +145,6 @@ exports[`Test MobileMenu > should initialize with welcome screen and hide once u
?
</div>
</button>
- <button
- class="welcome-screen-menu-item "
- type="button"
- >
- <div
- class="welcome-screen-menu-item__icon"
- >
- <svg
- aria-hidden="true"
- class=""
- fill="none"
- focusable="false"
- role="img"
- stroke="currentColor"
- stroke-linecap="round"
- stroke-linejoin="round"
- stroke-width="2"
- viewBox="0 0 24 24"
- >
- <g
- stroke-width="1.5"
- >
- <path
- d="M0 0h24v24H0z"
- fill="none"
- stroke="none"
- />
- <circle
- cx="9"
- cy="7"
- r="4"
- />
- <path
- d="M3 21v-2a4 4 0 0 1 4 -4h4a4 4 0 0 1 4 4v2"
- />
- <path
- d="M16 3.13a4 4 0 0 1 0 7.75"
- />
- <path
- d="M21 21v-2a4 4 0 0 0 -3 -3.85"
- />
- </g>
- </svg>
- </div>
- <div
- class="welcome-screen-menu-item__text"
- >
- Live collaboration...
- </div>
- </button>
- <a
- class="welcome-screen-menu-item "
- href="undefined/plus?utm_source=excalidraw&utm_medium=app&utm_content=welcomeScreenGuest"
- rel="noopener"
- target="_blank"
- >
- <div
- class="welcome-screen-menu-item__icon"
- >
- <svg
- aria-hidden="true"
- class=""
- fill="none"
- focusable="false"
- role="img"
- stroke="currentColor"
- stroke-linecap="round"
- stroke-linejoin="round"
- stroke-width="2"
- viewBox="0 0 24 24"
- >
- <g
- stroke-width="1.5"
- >
- <path
- d="M0 0h24v24H0z"
- fill="none"
- stroke="none"
- />
- <path
- d="M15 8v-2a2 2 0 0 0 -2 -2h-7a2 2 0 0 0 -2 2v12a2 2 0 0 0 2 2h7a2 2 0 0 0 2 -2v-2"
- />
- <path
- d="M21 12h-13l3 -3"
- />
- <path
- d="M11 15l-3 -3"
- />
- </g>
- </svg>
- </div>
- <div
- class="welcome-screen-menu-item__text"
- >
- Sign up
- </div>
- </a>
</div>
</div>
`;
diff --git a/packages/excalidraw/CHANGELOG.md b/packages/excalidraw/CHANGELOG.md
index 653bfdbf94..705bec3915 100644
--- a/packages/excalidraw/CHANGELOG.md
+++ b/packages/excalidraw/CHANGELOG.md
@@ -29,7 +29,7 @@ Please add the latest change on the top under the correct section.
- Added `interaction` prop (`boolean | { enabled?: { navigation?: boolean; links?: boolean; embeds?: boolean; interactiveContent?: boolean; browserZoom?: boolean } }`). When set to `false`, the editor becomes fully inert for the user — no panning, zooming, selecting, editing, keyboard shortcuts, clipboard, or drag&drop. It implies view mode (`appState.viewModeEnabled` reports `true` and cannot be unset while non-interactive), and the page scrolls naturally over the component since wheel/touch input is no longer captured (the browser's own zoom is still prevented over the editor by default). Interactions under `enabled` are opt-in exceptions: with `navigation` allowed, the user can pan (pointer drag, wheel, PageUp/PageDown — shift for horizontal) and zoom (ctrl/cmd + wheel, pinch, and the canvas zoom & zoom-to-fit shortcuts — ctrl/cmd +/-/0, shift+1/2/3) the canvas view-mode style — respecting `appState.scrollConstraints`, so it composes with viewport locking for constrained viewers, while the rest of the keyboard stays disabled and the editor consumes wheel & touch input again (the page no longer scrolls over the editor); with `links` allowed, link icons render and linked elements stay clickable (view-mode behavior: clicking anywhere on a linked element opens its link) while the editor stays otherwise non-interactive — when links are not allowed, link icons are not rendered at all; with `embeds` allowed, embeddable & iframe elements stay interactive (hover & click activates them, view-mode style); `interactiveContent` is an additive shorthand enabling `links` & `embeds` (and future interactive content kinds) together; with `browserZoom` allowed, the browser's own zoom gestures (ctrl/cmd + wheel, pinch, keyboard) stay available over the editor (moot when `navigation` is allowed, since the editor consumes the zoom input instead). The scene still renders and remains fully controllable through the imperative API (`updateScene`, `setViewport`, ...), making it suitable for live previews, thumbnails, and annotation overlays.
-- Added `ui` prop. When set to `false`, Excalidraw's default UI is not rendered — toolbar, default menu and footer controls, sidebars, canvas popups, and context menu. Canvas content (elements, text editing, frame names, embeds) still renders, and the editor remains interactive unless `interaction={false}` is set as well. Host children continue to mount (they may be functional, e.g. a collaboration component), and host-supplied UI — including Excalidraw-exported components such as `<MainMenu>` and `<Footer>` — continues to render together with any supporting dialogs it opens. You're responsible for hiding your own presentational components.
+- Added `ui` prop (`boolean | { enabled: { zoom?: boolean; scrollBackToContent?: boolean } }`). When set to `false`, Excalidraw's default UI is not rendered — toolbar, default menu and footer controls, sidebars, canvas popups, and context menu. The object form likewise hides the default UI but opts the zoom controls and/or scroll-back-to-content button back in. Canvas content (elements, text editing, frame names, embeds) still renders, and the editor remains interactive unless `interaction={false}` is set as well. Host children continue to mount (they may be functional, e.g. a collaboration component), and host-supplied UI — including Excalidraw-exported components such as `<MainMenu>` and `<Footer>` — continues to render together with any supporting dialogs it opens. You're responsible for hiding your own presentational components.
### Tool system & toolbar rework [#11649](https://github.com/excalidraw/excalidraw/pull/11649)
diff --git a/packages/excalidraw/components/App.tsx b/packages/excalidraw/components/App.tsx
index 4aade19fac..2ee45cd829 100644
--- a/packages/excalidraw/components/App.tsx
+++ b/packages/excalidraw/components/App.tsx
@@ -489,6 +489,7 @@ import type {
ExcalidrawImperativeAPIEventMap,
GenerateDiagramToCode,
NullableGridSize,
+ UIConfig,
} from "../types";
import type { RoughCanvas } from "roughjs/bin/canvas";
import type { Action, ActionResult } from "../actions/types";
@@ -1023,8 +1024,21 @@ class App extends React.Component<AppProps, AppState> {
return this.state.activeTool.type === "laser";
}
- /** Whether Excalidraw's default UI is rendered. */
+ /** Whether Excalidraw's full default UI is rendered. */
public isDefaultUIEnabled(props: Pick<AppProps, "ui"> = this.props): boolean {
+ return (
+ props.ui !== false && (typeof props.ui !== "object" || props.ui === null)
+ );
+ }
+
+ /** Whether an individual default UI control is rendered. */
+ public isUIControlEnabled(
+ control: keyof UIConfig["enabled"],
+ props: Pick<AppProps, "ui"> = this.props,
+ ): boolean {
+ if (typeof props.ui === "object" && props.ui !== null) {
+ return props.ui.enabled?.[control] === true;
+ }
return props.ui !== false;
}
@@ -2379,6 +2393,10 @@ class App extends React.Component<AppProps, AppState> {
canvas={this.canvas}
appState={this.state}
defaultUIEnabled={this.isDefaultUIEnabled()}
+ zoomUIEnabled={this.isUIControlEnabled("zoom")}
+ scrollBackToContentUIEnabled={this.isUIControlEnabled(
+ "scrollBackToContent",
+ )}
files={this.files}
setAppState={this.setAppState}
actionManager={this.actionManager}
@@ -12932,11 +12950,12 @@ class App extends React.Component<AppProps, AppState> {
private handleCanvasContextMenu = (
event: React.MouseEvent<HTMLElement | HTMLCanvasElement>,
) => {
- // NOTE no preventDefault so the browser default context menu applies
+ // Always suppress the native menu over the canvas. In non-interactive
+ // mode we stop here so it cannot be mistaken for Excalidraw's own menu.
+ event.preventDefault();
if (!this.isInteractionEnabled()) {
return;
}
- event.preventDefault();
if (
(("pointerType" in event.nativeEvent &&
diff --git a/packages/excalidraw/components/LayerUI.tsx b/packages/excalidraw/components/LayerUI.tsx
index 624133226c..eba358c0ae 100644
--- a/packages/excalidraw/components/LayerUI.tsx
+++ b/packages/excalidraw/components/LayerUI.tsx
@@ -92,6 +92,8 @@ interface LayerUIProps {
children?: React.ReactNode;
app: AppClassProperties;
defaultUIEnabled: boolean;
+ zoomUIEnabled: boolean;
+ scrollBackToContentUIEnabled: boolean;
isCollaborating: boolean;
generateLinkForSelection?: AppProps["generateLinkForSelection"];
}
@@ -151,6 +153,8 @@ const LayerUI = ({
children,
app,
defaultUIEnabled,
+ zoomUIEnabled,
+ scrollBackToContentUIEnabled,
isCollaborating,
generateLinkForSelection,
}: LayerUIProps) => {
@@ -590,6 +594,7 @@ const LayerUI = ({
renderSidebars={renderSidebars}
renderWelcomeScreen={renderWelcomeScreen}
defaultUIEnabled={defaultUIEnabled}
+ scrollBackToContentUIEnabled={scrollBackToContentUIEnabled}
UIOptions={UIOptions}
/>
)}
@@ -613,9 +618,10 @@ const LayerUI = ({
showExitZenModeBtn={showExitZenModeBtn}
renderWelcomeScreen={renderWelcomeScreen}
defaultUIEnabled={defaultUIEnabled}
+ zoomUIEnabled={zoomUIEnabled}
/>
{(appState.toast ||
- (defaultUIEnabled && appState.scrolledOutside)) && (
+ (scrollBackToContentUIEnabled && appState.scrolledOutside)) && (
<div className="floating-status-stack">
{appState.toast && (
<Toast
@@ -626,7 +632,7 @@ const LayerUI = ({
/>
)}
{!appState.toast &&
- defaultUIEnabled &&
+ scrollBackToContentUIEnabled &&
appState.scrolledOutside && (
<button
type="button"
diff --git a/packages/excalidraw/components/MobileMenu.tsx b/packages/excalidraw/components/MobileMenu.tsx
index 32f142125d..43f2833f12 100644
--- a/packages/excalidraw/components/MobileMenu.tsx
+++ b/packages/excalidraw/components/MobileMenu.tsx
@@ -44,6 +44,7 @@ type MobileMenuProps = {
renderSidebars: () => JSX.Element | null;
renderWelcomeScreen: boolean;
defaultUIEnabled: boolean;
+ scrollBackToContentUIEnabled: boolean;
UIOptions: AppProps["UIOptions"];
app: AppClassProperties;
};
@@ -58,6 +59,7 @@ export const MobileMenu = ({
renderSidebars,
renderWelcomeScreen,
defaultUIEnabled,
+ scrollBackToContentUIEnabled,
UIOptions,
app,
onPenModeToggle,
@@ -132,44 +134,50 @@ export const MobileMenu = ({
{renderWelcomeScreen && <WelcomeScreenCenterTunnel.Out />}
</div>
- {defaultUIEnabled && !appState.viewModeEnabled && (
- <div
- className="App-bottom-bar"
- style={{
- marginBottom: SCROLLBAR_WIDTH + SCROLLBAR_MARGIN,
- }}
- data-viewport-ui="bottom"
- >
- <MobileShapeActions
- appState={appState}
- elementsMap={app.scene.getNonDeletedElementsMap()}
- renderAction={actionManager.renderAction}
- app={app}
- setAppState={setAppState}
- />
-
- <Island className="App-toolbar">
- {!appState.viewModeEnabled &&
- appState.openDialog?.name !== "elementLinkSelector" &&
- renderToolbar()}
- {appState.scrolledOutside &&
- !appState.openMenu &&
- !appState.openSidebar && (
- <button
- type="button"
- className="scroll-back-to-content"
- onClick={() => {
- setAppState((appState) => ({
- ...getScrollToContentState(elements, appState),
- }));
- }}
- >
- {t("buttons.scrollBackToContent")}
- </button>
- )}
- </Island>
- </div>
- )}
+ {!appState.viewModeEnabled &&
+ (defaultUIEnabled ||
+ (scrollBackToContentUIEnabled && appState.scrolledOutside)) && (
+ <div
+ className="App-bottom-bar"
+ style={{
+ marginBottom: SCROLLBAR_WIDTH + SCROLLBAR_MARGIN,
+ }}
+ data-viewport-ui="bottom"
+ >
+ {defaultUIEnabled && (
+ <MobileShapeActions
+ appState={appState}
+ elementsMap={app.scene.getNonDeletedElementsMap()}
+ renderAction={actionManager.renderAction}
+ app={app}
+ setAppState={setAppState}
+ />
+ )}
+
+ <Island className="App-toolbar">
+ {defaultUIEnabled &&
+ !appState.viewModeEnabled &&
+ appState.openDialog?.name !== "elementLinkSelector" &&
+ renderToolbar()}
+ {scrollBackToContentUIEnabled &&
+ appState.scrolledOutside &&
+ !appState.openMenu &&
+ !appState.openSidebar && (
+ <button
+ type="button"
+ className="scroll-back-to-content"
+ onClick={() => {
+ setAppState((appState) => ({
+ ...getScrollToContentState(elements, appState),
+ }));
+ }}
+ >
+ {t("buttons.scrollBackToContent")}
+ </button>
+ )}
+ </Island>
+ </div>
+ )}
<FixedSideContainer side="top" className="App-top-bar">
{renderAppTopBar()}
diff --git a/packages/excalidraw/components/footer/Footer.tsx b/packages/excalidraw/components/footer/Footer.tsx
index 72955d4c76..469444ddbe 100644
--- a/packages/excalidraw/components/footer/Footer.tsx
+++ b/packages/excalidraw/components/footer/Footer.tsx
@@ -17,12 +17,14 @@ const Footer = ({
showExitZenModeBtn,
renderWelcomeScreen,
defaultUIEnabled,
+ zoomUIEnabled,
}: {
appState: UIAppState;
actionManager: ActionManager;
showExitZenModeBtn: boolean;
renderWelcomeScreen: boolean;
defaultUIEnabled: boolean;
+ zoomUIEnabled: boolean;
}) => {
const { FooterCenterTunnel, WelcomeScreenHelpHintTunnel } = useTunnels();
const app = useApp();
@@ -32,7 +34,7 @@ const Footer = ({
role="contentinfo"
className="layer-ui__wrapper__footer App-menu App-menu_bottom"
>
- {defaultUIEnabled && (
+ {(defaultUIEnabled || (zoomUIEnabled && app.isNavigationEnabled())) && (
<div
className={clsx(
"layer-ui__wrapper__footer-left zen-mode-transition",
@@ -44,11 +46,11 @@ const Footer = ({
>
<Stack.Col gap={2}>
<Section heading="canvasActions">
- {app.isNavigationEnabled() && (
+ {zoomUIEnabled && app.isNavigationEnabled() && (
<ZoomActions renderAction={actionManager.renderAction} />
)}
- {!appState.viewModeEnabled && (
+ {defaultUIEnabled && !appState.viewModeEnabled && (
<UndoRedoActions
renderAction={actionManager.renderAction}
className={clsx("zen-mode-transition", {
diff --git a/packages/excalidraw/index.tsx b/packages/excalidraw/index.tsx
index 86d939025e..240743cb44 100644
--- a/packages/excalidraw/index.tsx
+++ b/packages/excalidraw/index.tsx
@@ -265,6 +265,7 @@ const areEqual = (prevProps: ExcalidrawProps, nextProps: ExcalidrawProps) => {
UIOptions: prevUIOptions = {},
imageOptions: prevImageOptions,
interaction: prevInteraction,
+ ui: prevUI,
activeTool: prevActiveTool,
...prev
} = prevProps;
@@ -273,6 +274,7 @@ const areEqual = (prevProps: ExcalidrawProps, nextProps: ExcalidrawProps) => {
UIOptions: nextUIOptions = {},
imageOptions: nextImageOptions,
interaction: nextInteraction,
+ ui: nextUI,
activeTool: nextActiveTool,
...next
} = nextProps;
@@ -315,6 +317,22 @@ const areEqual = (prevProps: ExcalidrawProps, nextProps: ExcalidrawProps) => {
return false;
}
+ // compare `ui` semantically so that hosts inlining the config object don't
+ // bust the memo every render
+ const isUISame =
+ prevUI === nextUI ||
+ (typeof prevUI === "object" &&
+ prevUI !== null &&
+ typeof nextUI === "object" &&
+ nextUI !== null &&
+ !!prevUI.enabled?.zoom === !!nextUI.enabled?.zoom &&
+ !!prevUI.enabled?.scrollBackToContent ===
+ !!nextUI.enabled?.scrollBackToContent);
+
+ if (!isUISame) {
+ return false;
+ }
+
// comparing UIOptions
const prevUIOptionsKeys = Object.keys(prevUIOptions) as (keyof Partial<
typeof DEFAULT_UI_OPTIONS
diff --git a/packages/excalidraw/tests/interactivity.test.tsx b/packages/excalidraw/tests/interactivity.test.tsx
index 237e3a6b90..fa6e50dd05 100644
--- a/packages/excalidraw/tests/interactivity.test.tsx
+++ b/packages/excalidraw/tests/interactivity.test.tsx
@@ -57,11 +57,15 @@ const pressZoomShortcut = (code: string) => {
};
const rightClickCanvas = () => {
- fireEvent.contextMenu(GlobalTestState.interactiveCanvas, {
+ const event = new MouseEvent("contextmenu", {
+ bubbles: true,
+ cancelable: true,
button: 2,
clientX: 5,
clientY: 5,
});
+ fireEvent(GlobalTestState.interactiveCanvas, event);
+ return event;
};
const dispatchPaste = async () => {
@@ -227,8 +231,9 @@ describe("interaction={false}", () => {
expect(h.state.selectedElementIds).toEqual({});
});
- it("context menu does not open", () => {
- rightClickCanvas();
+ it("prevents the native context menu without opening Excalidraw's", () => {
+ const event = rightClickCanvas();
+ expect(event.defaultPrevented).toBe(true);
expect(h.state.contextMenu).toBe(null);
expect(UI.queryContextMenu()).toBe(null);
});
@@ -671,6 +676,100 @@ describe("ui={false}", () => {
});
});
+describe("ui={{ enabled: ... }}", () => {
+ beforeEach(() => {
+ mockBoundingClientRect();
+ });
+
+ afterEach(() => {
+ restoreOriginalGetBoundingClientRect();
+ });
+
+ const rectangle = () =>
+ API.createElement({
+ type: "rectangle",
+ x: 10,
+ y: 10,
+ width: 50,
+ height: 50,
+ });
+
+ const scrollAwayFromContent = async () => {
+ act(() => {
+ h.app.setState({ scrollX: -10_000, scrollY: -10_000 });
+ });
+ await waitFor(() => expect(h.state.scrolledOutside).toBe(true));
+ };
+
+ it("renders opted-in zoom controls while the rest of the default UI stays hidden", async () => {
+ await render(<Excalidraw ui={{ enabled: { zoom: true } }} />);
+
+ expect(queryContainer(".zoom-actions")).not.toBe(null);
+ expect(queryContainer(".undo-redo-buttons")).toBe(null);
+ expect(queryContainer(".App-toolbar")).toBe(null);
+ expect(queryContainer(".dropdown-menu-button")).toBe(null);
+ expect(queryContainer(".default-sidebar-trigger")).toBe(null);
+ expect(queryContainer(".help-icon")).toBe(null);
+ expect(
+ queryContainer(".excalidraw-container")!.classList.contains(
+ "excalidraw--ui-hidden",
+ ),
+ ).toBe(true);
+ });
+
+ it("renders an opted-in scroll-back-to-content control", async () => {
+ await render(
+ <Excalidraw
+ ui={{ enabled: { scrollBackToContent: true } }}
+ initialData={{ elements: [rectangle()] }}
+ />,
+ );
+
+ expect(queryContainer(".zoom-actions")).toBe(null);
+ expect(queryContainer(".scroll-back-to-content")).toBe(null);
+
+ await scrollAwayFromContent();
+
+ const scrollBackButton = queryContainer(".scroll-back-to-content");
+ expect(scrollBackButton).not.toBe(null);
+ fireEvent.click(scrollBackButton!);
+ await waitFor(() => expect(h.state.scrolledOutside).toBe(false));
+ });
+
+ it("keeps omitted or false controls hidden", async () => {
+ await render(
+ <Excalidraw
+ ui={{
+ enabled: { zoom: false, scrollBackToContent: false },
+ }}
+ initialData={{ elements: [rectangle()] }}
+ />,
+ );
+
+ await scrollAwayFromContent();
+
+ expect(queryContainer(".zoom-actions")).toBe(null);
+ expect(queryContainer(".scroll-back-to-content")).toBe(null);
+ });
+
+ it("supports the scroll-back-to-content control on mobile", async () => {
+ await render(
+ <Excalidraw
+ ui={{ enabled: { scrollBackToContent: true } }}
+ UIOptions={{ getFormFactor: () => "phone" }}
+ initialData={{ elements: [rectangle()] }}
+ />,
+ );
+ fireEvent.resize(window);
+ await waitFor(() => expect(h.app.editorInterface.formFactor).toBe("phone"));
+
+ await scrollAwayFromContent();
+
+ expect(queryContainer(".scroll-back-to-content")).not.toBe(null);
+ expect(queryContainer(".mobile-toolbar")).toBe(null);
+ });
+});
+
describe("ui={false} with host UI", () => {
it("renders host outlets and dialogs invoked by host UI", async () => {
const { container } = await render(
diff --git a/packages/excalidraw/types.ts b/packages/excalidraw/types.ts
index 543a345b18..68fe94958c 100644
--- a/packages/excalidraw/types.ts
+++ b/packages/excalidraw/types.ts
@@ -719,6 +719,27 @@ export type InteractionConfig = {
};
};
+export type UIConfig = {
+ /**
+ * Default UI controls that stay enabled while the rest of Excalidraw's
+ * default UI is hidden. Opt-in: anything omitted or `false` is disabled.
+ */
+ enabled: {
+ /**
+ * The zoom-out, reset-zoom, and zoom-in controls.
+ *
+ * @default false
+ */
+ zoom?: boolean;
+ /**
+ * The button shown when the viewport is scrolled away from all content.
+ *
+ * @default false
+ */
+ scrollBackToContent?: boolean;
+ };
+};
+
export interface ExcalidrawProps {
onChange?: (
elements: readonly OrderedExcalidrawElement[],
@@ -814,12 +835,19 @@ export interface ExcalidrawProps {
* renders, and the editor remains interactive unless `interaction` is set to
* `false`.
*
+ * Pass a config object to keep specific default controls rendered while the
+ * rest of the default UI is hidden (see `UIConfig`):
+ *
+ * ```tsx
+ * <Excalidraw ui={{ enabled: { zoom: true } }} />
+ * ```
+ *
* NOTE: this is WIP and what default UI is/is not rendered when ui=false
* may yet change.
*
* @default true
*/
- ui?: boolean;
+ ui?: boolean | UIConfig;
/**
* Forces the active editor tool (controlled). While set, user- and
* API-driven tool switching is ignored — `setActiveTool` refuses with a