Skip to content

A reactive notebook for Python — run reproducible experiments, query with SQL, execute as a script, deploy as an app, and version with git. Stored as pure Python. All in a modern, AI-native editor.

fix(a11y): preserve cell-toolbar keyboard activation (#10827)

Juliod88680c3135e
diff --git a/frontend/e2e-tests/cell-toolbar.spec.ts b/frontend/e2e-tests/cell-toolbar.spec.ts
new file mode 100644
index 0000000000..fcfdc1c5c5
--- /dev/null
+++ b/frontend/e2e-tests/cell-toolbar.spec.ts
@@ -0,0 +1,60 @@
+/* Copyright 2026 Marimo. All rights reserved. */
+
+import { expect, test } from "@playwright/test";
+import { getAppUrl, resetFile } from "../playwright.config";
+import { pressShortcut } from "./helper";
+import { waitForMarimoApp } from "./test-utils";
+
+const appUrl = getAppUrl("cells.py");
+
+test.beforeEach(async ({ page }) => {
+ await page.goto(appUrl);
+ await waitForMarimoApp(page);
+ await expect(page.locator("h1").getByText("Cell 2")).toBeVisible();
+});
+
+test.afterEach(async () => {
+ await resetFile("cells.py");
+});
+
+for (const key of ["Enter", "Space"]) {
+ test(`${key} activates the focused run button once`, async ({ page }) => {
+ const cell = page.locator(".marimo-cell").first();
+ const runButton = cell.getByTestId("run-button").first();
+ await cell.hover();
+ await expect(runButton).toBeEnabled();
+ await runButton.focus();
+ await expect(runButton).toBeFocused();
+
+ const runs: string[] = [];
+ page.on("request", (request) => {
+ if (request.url().endsWith("/api/kernel/run")) {
+ runs.push(request.postData() ?? "");
+ }
+ });
+ const response = page.waitForResponse("**/api/kernel/run");
+ await page.keyboard.press(key);
+ expect((await response).ok()).toBe(true);
+ await expect(runButton).toBeEnabled();
+ expect(runs).toHaveLength(1);
+ });
+}
+
+test("modified run shortcuts still work from a toolbar button", async ({ page }) => {
+ const cell = page.locator(".marimo-cell").first();
+ const runButton = cell.getByTestId("run-button").first();
+ await cell.hover();
+ await expect(runButton).toBeEnabled();
+ await cell.getByTestId("cell-actions-button").focus();
+ const response = page.waitForResponse("**/api/kernel/run");
+ await pressShortcut(page, "cell.run");
+ expect((await response).ok()).toBe(true);
+ await expect(page.getByPlaceholder("Search actions...")).not.toBeVisible();
+});
+
+test("Enter on the cell itself still focuses its editor", async ({ page }) => {
+ const cell = page.locator(".marimo-cell").first();
+ await cell.focus();
+ await page.keyboard.press("Enter");
+ await expect(cell.locator(".cm-content").first()).toBeFocused();
+});
diff --git a/frontend/src/components/editor/cell/__tests__/toolbar.test.tsx b/frontend/src/components/editor/cell/__tests__/toolbar.test.tsx
new file mode 100644
index 0000000000..f8d6e87928
--- /dev/null
+++ b/frontend/src/components/editor/cell/__tests__/toolbar.test.tsx
@@ -0,0 +1,73 @@
+/* Copyright 2026 Marimo. All rights reserved. */
+
+import { fireEvent, render, screen } from "@testing-library/react";
+import { describe, expect, it, vi } from "vitest";
+import { ToolbarItem } from "../toolbar";
+
+describe("ToolbarItem keyboard activation", () => {
+ it.each(["Enter", " "])(
+ "keeps native %s activation out of cell navigation and calls the consumer handler",
+ (key) => {
+ const onCellKeyDown = vi.fn();
+ const onKeyDown = vi.fn();
+ render(
+ <div onKeyDown={onCellKeyDown}>
+ <ToolbarItem tooltip={null} onKeyDown={onKeyDown}>
+ Run
+ </ToolbarItem>
+ </div>,
+ );
+ const button = screen.getByRole("button", { name: "Run" });
+
+ expect(fireEvent.keyDown(button, { key })).toBe(true);
+ expect(onCellKeyDown).not.toHaveBeenCalled();
+ expect(onKeyDown).toHaveBeenCalledOnce();
+ expect(onKeyDown.mock.calls[0][0].defaultPrevented).toBe(false);
+ },
+ );
+
+ it.each([
+ { key: "Enter", ctrlKey: true },
+ { key: "Enter", metaKey: true },
+ { key: "Enter", shiftKey: true },
+ { key: "Enter", altKey: true },
+ { key: " ", ctrlKey: true },
+ { key: "ArrowLeft" },
+ { key: "ArrowRight" },
+ { key: "Tab" },
+ { key: "Escape" },
+ ])("preserves propagation for %j", (event) => {
+ const onCellKeyDown = vi.fn();
+ render(
+ <div onKeyDown={onCellKeyDown}>
+ <ToolbarItem tooltip={null}>Run</ToolbarItem>
+ </div>,
+ );
+
+ expect(fireEvent.keyDown(screen.getByRole("button"), event)).toBe(true);
+ expect(onCellKeyDown).toHaveBeenCalledOnce();
+ });
+
+ it("does not submit forms and preserves disabled and mouse-focus behavior", () => {
+ const onClick = vi.fn();
+ const { rerender } = render(
+ <ToolbarItem tooltip={null} onClick={onClick}>
+ Run
+ </ToolbarItem>,
+ );
+ const button = screen.getByRole("button");
+ expect(button).toHaveAttribute("type", "button");
+ expect(fireEvent.mouseDown(button)).toBe(false);
+ fireEvent.click(button);
+ expect(onClick).toHaveBeenCalledOnce();
+
+ rerender(
+ <ToolbarItem tooltip={null} onClick={onClick} disabled={true}>
+ Run
+ </ToolbarItem>,
+ );
+ expect(button).toBeDisabled();
+ fireEvent.click(button);
+ expect(onClick).toHaveBeenCalledOnce();
+ });
+});
diff --git a/frontend/src/components/editor/cell/toolbar.tsx b/frontend/src/components/editor/cell/toolbar.tsx
index e1f2cb2681..e5be994310 100644
--- a/frontend/src/components/editor/cell/toolbar.tsx
+++ b/frontend/src/components/editor/cell/toolbar.tsx
@@ -43,8 +43,19 @@ export const ToolbarItem: React.FC<ToolbarItemProps> = ({
}) => {
const content = (
<button
+ type="button"
disabled={disabled}
{...rest}
+ onKeyDown={(evt) => {
+ // Preserve native button activation without triggering cell navigation.
+ if (
+ !Events.hasModifier(evt) &&
+ (evt.key === "Enter" || evt.key === " ")
+ ) {
+ evt.stopPropagation();
+ }
+ rest.onKeyDown?.(evt);
+ }}
onClick={(evt) => {
if (!disabled) {
rest.onClick?.(evt);