fix(webui): keep DataGrid actions out of form submission

This commit is contained in:
2026-07-20 17:58:32 +02:00
parent 1678602fd6
commit 9b5418db78
4 changed files with 39 additions and 0 deletions

View File

@@ -0,0 +1,32 @@
function assertEqual<T>(actual: T, expected: T, message: string): void {
if (actual !== expected) throw new Error(`${message}: expected ${String(expected)}, got ${String(actual)}`);
}
import { renderToStaticMarkup } from "react-dom/server";
import { DataGridEmptyAction, DataGridRowActions } from "../src/components/table/DataGrid";
function noop() {}
function buttonCount(markup: string): number {
return markup.match(/<button\b/g)?.length ?? 0;
}
function nonSubmittingButtonCount(markup: string): number {
return markup.match(/<button\b[^>]*\btype="button"/g)?.length ?? 0;
}
const rowActions = renderToStaticMarkup(
<form>
<DataGridRowActions onAddBelow={noop} onRemove={noop} onMoveUp={noop} onMoveDown={noop} />
</form>
);
assertEqual(buttonCount(rowActions), 4, "row actions render the expected controls");
assertEqual(nonSubmittingButtonCount(rowActions), 4, "row actions do not submit an enclosing form");
const emptyAction = renderToStaticMarkup(
<form>
<DataGridEmptyAction onAdd={noop} />
</form>
);
assertEqual(buttonCount(emptyAction), 1, "empty action renders the expected control");
assertEqual(nonSubmittingButtonCount(emptyAction), 1, "empty action does not submit an enclosing form");