fix(grid): allow editing row count in multi-row insert dialog
This commit is contained in:
parent
76501d6ae3
commit
8825a98ca2
|
|
@ -16,7 +16,7 @@ const emit = defineEmits<{ insert: [count: number, position: GridInsertRowPositi
|
|||
|
||||
const canUsePosition = computed(() => props.canPlaceAtSelection !== false);
|
||||
|
||||
const rowCount = ref("1");
|
||||
const rowCount = ref<string | number>("1");
|
||||
const position = ref<GridInsertRowPosition>("below");
|
||||
|
||||
watch(
|
||||
|
|
@ -36,8 +36,8 @@ watch(canUsePosition, (canUse) => {
|
|||
if (!canUse) position.value = "end";
|
||||
});
|
||||
|
||||
function parseIntegerOrNull(raw: string): number | null {
|
||||
const trimmed = raw.trim();
|
||||
function parseIntegerOrNull(raw: string | number): number | null {
|
||||
const trimmed = String(raw).trim();
|
||||
if (!/^\d+$/.test(trimmed)) return null;
|
||||
const value = Number(trimmed);
|
||||
return Number.isInteger(value) && value >= 1 ? value : null;
|
||||
|
|
@ -50,7 +50,7 @@ const parsedCount = computed<number | null>(() => {
|
|||
});
|
||||
|
||||
const inputInvalid = computed(() => {
|
||||
const raw = rowCount.value.trim();
|
||||
const raw = String(rowCount.value).trim();
|
||||
if (raw === "") return false;
|
||||
return parseIntegerOrNull(raw) === null;
|
||||
});
|
||||
|
|
|
|||
|
|
@ -33,20 +33,6 @@ vi.mock("@/components/ui/button", async () => {
|
|||
};
|
||||
});
|
||||
|
||||
vi.mock("@/components/ui/input", async () => {
|
||||
const { defineComponent, h } = await import("vue");
|
||||
return {
|
||||
Input: defineComponent({
|
||||
inheritAttrs: false,
|
||||
props: { modelValue: String },
|
||||
emits: ["update:modelValue"],
|
||||
setup(props, { attrs, emit }) {
|
||||
return () => h("input", { ...attrs, value: props.modelValue, onInput: (event: Event) => emit("update:modelValue", (event.target as HTMLInputElement).value) });
|
||||
},
|
||||
}),
|
||||
};
|
||||
});
|
||||
|
||||
import DataGridInsertRowsDialog from "../DataGridInsertRowsDialog.vue";
|
||||
|
||||
const mountedApps: Array<{ app: App; host: HTMLElement }> = [];
|
||||
|
|
@ -80,4 +66,27 @@ describe("DataGridInsertRowsDialog", () => {
|
|||
await nextTick();
|
||||
expect(onInsert).toHaveBeenCalledWith(1, "end");
|
||||
});
|
||||
|
||||
it("accepts a numeric value emitted by the number input", async () => {
|
||||
const onInsert = vi.fn();
|
||||
const host = document.createElement("div");
|
||||
document.body.append(host);
|
||||
const app = createApp(DataGridInsertRowsDialog, {
|
||||
open: true,
|
||||
canPlaceAtSelection: true,
|
||||
onInsert,
|
||||
});
|
||||
app.use(i18n);
|
||||
app.mount(host);
|
||||
mountedApps.push({ app, host });
|
||||
|
||||
const input = host.querySelector("#insert-rows-count") as HTMLInputElement;
|
||||
input.value = "3";
|
||||
input.dispatchEvent(new Event("input", { bubbles: true }));
|
||||
await nextTick();
|
||||
|
||||
[...host.querySelectorAll("button")].find((button) => button.textContent === "Insert")!.click();
|
||||
await nextTick();
|
||||
expect(onInsert).toHaveBeenCalledWith(3, "below");
|
||||
});
|
||||
});
|
||||
|
|
|
|||
Loading…
Reference in New Issue