From f1b7630dab27fef1295c7f863b4635678dbf1cc1 Mon Sep 17 00:00:00 2001 From: Claude Date: Tue, 17 Nov 2026 03:50:26 +0000 Subject: [PATCH 1/3] fix(plugin-form): pin the master-detail Save bar and guard the subform close MasterDetailForm's action bar sticks to the bottom of the hosting scroll frame (dialog body, drawer, record page). The master-detail form reports its unsaved input (header, lines, row editor) through a package-internal context into the ModalForm/DrawerForm close guard, and the ModalForm subform arm routes its close paths through the discard dialog. Claude-Session: https://claude.ai/code/session_01WGufzgwLiKcfujYUug7sPs Co-authored-by: Claude --- ui/packages/plugin-form/src/DrawerForm.tsx | 8 +- .../plugin-form/src/MasterDetailForm.tsx | 61 +++++++++++++- ui/packages/plugin-form/src/ModalForm.tsx | 81 +++++++++++-------- ui/packages/plugin-form/src/ObjectForm.tsx | 6 +- ui/packages/plugin-form/src/TabbedForm.tsx | 5 +- .../plugin-form/src/formDirtyReport.ts | 67 +++++++++++++++ 6 files changed, 187 insertions(+), 41 deletions(-) create mode 100644 ui/packages/plugin-form/src/formDirtyReport.ts diff --git a/ui/packages/plugin-form/src/DrawerForm.tsx b/ui/packages/plugin-form/src/DrawerForm.tsx index 02085d5dc6c..75f834a720a 100644 --- a/ui/packages/plugin-form/src/DrawerForm.tsx +++ b/ui/packages/plugin-form/src/DrawerForm.tsx @@ -78,6 +78,7 @@ import { } from './loadFailure'; import { hasInlineFieldSource, noSubmitTargetError } from './submitTarget'; import { useRecordInvalidation } from './recordInvalidation'; +import { FormDirtyReportContext } from './formDirtyReport'; import { useInitialFieldFocus } from './initialFieldFocus'; // Localized strings for the unsaved-changes guard and, since objectui#11039, @@ -953,9 +954,13 @@ const DrawerFormBody: React.FC = ({ ) : null; // Master-detail in a drawer: render the master-detail form (it owns its Save - // bar) when the schema declares inline child collections; saved atomically. + // bar, pinned to the bottom of this drawer's scroll frame) when the schema + // declares inline child collections; saved atomically. It reports its unsaved + // input into this drawer's close guard (`formDirtyReport.ts`), so the close + // paths prompt as they do for the flat body (objectstack#34599). const subforms = (schema as any).subforms as any[] | undefined; const drawerBody = subforms?.length && schema.mode !== 'view' ? ( + = ({ }} dataSource={dataSource} /> + ) : ( <> {closedAffordanceNotice} diff --git a/ui/packages/plugin-form/src/MasterDetailForm.tsx b/ui/packages/plugin-form/src/MasterDetailForm.tsx index 473d029e24c..a24016432a4 100644 --- a/ui/packages/plugin-form/src/MasterDetailForm.tsx +++ b/ui/packages/plugin-form/src/MasterDetailForm.tsx @@ -30,7 +30,7 @@ * `lookup`) FK on the child object. */ -import React, { startTransition, useCallback, useEffect, useMemo, useRef, useState } from 'react'; +import React, { startTransition, useCallback, useContext, useEffect, useMemo, useRef, useState } from 'react'; import type { BatchTransactionOperation, DataSource, GridFieldMetadata, I18nLabel } from '@object-ui/types'; import { resolveAffordance, runBatchTransaction } from '@object-ui/core'; import { LineItemsField, lookupAutofillByField, useBooleanValueLabel, type BooleanValueLabel, type GridColumn, type LookupAutofillByField } from '@object-ui/fields'; @@ -48,6 +48,7 @@ import { dataChangeMatches, subscribeDataChanges } from '@object-ui/react'; import { ObjectForm } from './ObjectForm'; import { applyColumnPermissions } from './fieldWriteGate'; import { useUploadGate, UploadGateProvider, UploadInFlightNotice } from './uploadGate'; +import { FormDirtyReportContext } from './formDirtyReport'; import { useFormChromeTranslation } from './formChrome'; import { buildMasterDetailBatch, @@ -1766,6 +1767,41 @@ export const MasterDetailForm: React.FC = ({ })); }, []); + /** + * Whether this document holds input a close would discard, reported to the + * hosting overlay's close guard (`formDirtyReport.ts`): the header form's + * renderer verdict, the open row editor's, or any collection whose lines the + * save would write ({@link linesUnsaved}, the edit save's own row diff — so a + * blank ghost line is not input and a reverted edit reads as saved). + * + * The header and the row editor report through reporters this form provides + * around them, never to the host directly. A save clears the header's + * verdict (a create remounts it; an edit's next keystroke reports again) and + * advances or empties the lines, so a saved document reads as pristine. + */ + const reportUnsaved = useContext(FormDirtyReportContext); + const [headerDirty, setHeaderDirty] = useState(false); + const [rowEditorDirty, setRowEditorDirty] = useState(false); + const linesDirty = useMemo( + () => + entries.some((e) => + linesUnsaved(rowState[e.id], e.config, parentIdKey, childSchemasRef.current[e.config.childObject]), + ), + [entries, rowState, parentIdKey], + ); + // A closed row editor holds no draft: Apply wrote it into the lines, and + // cancel dropped it. Its renderer reports nothing on its way out. + useEffect(() => { + if (!expanded) setRowEditorDirty(false); + }, [expanded]); + const unsavedInput = headerDirty || rowEditorDirty || linesDirty; + useEffect(() => { + reportUnsaved?.(unsavedInput); + }, [reportUnsaved, unsavedInput]); + // Unmounted (the overlay closed, or the host swapped forms): nothing of this + // document is on screen to discard any more. + useEffect(() => () => reportUnsaved?.(false), [reportUnsaved]); + // Header tax-rate field name — the live value is read by // (from the header record and the user's edits) and drives the Subtotal / Tax // / Total stack. @@ -1826,6 +1862,7 @@ export const MasterDetailForm: React.FC = ({ const handleSaved = useCallback( async (parent: any) => { releaseSave(); + setHeaderDirty(false); if (!schema.onSuccess) { toast.success( isEdit @@ -2147,7 +2184,9 @@ export const MasterDetailForm: React.FC = ({
{/* 1) Header fields on top */}
- + + +
{/* 2) Line items + document totals, in a sibling component that owns the @@ -2204,6 +2243,7 @@ export const MasterDetailForm: React.FC = ({ row its id. A disabled fieldset disables every control in the editor, "Apply" included, until the save has settled. */}
+ = ({ } as any} dataSource={dataSource} /> +
)} {/* Single action bar at the bottom — suppressed when the host opts out - (e.g. the Studio screen-preview, which must never persist). */} + (e.g. the Studio screen-preview, which must never persist). + Pinned to the bottom edge of whatever scroll frame hosts this form — + the dialog body, the drawer, the record page — so Save and Cancel + stay in view at any scroll position (objectstack#34599). Sticky + resolves against the nearest scrolling ancestor, so it is a direct + child of this form's root and nothing between it and the host's + scroller may set `overflow`. Sticky stops at the scroller's CONTENT + edge: the `after:` strip paints over the host's bottom padding below + it, so lines never scroll through that gap. Owned here, not by the + host (ADR-0035 Decision §6: the form owns its Save). */} {schema.showSubmit !== false && ( -
+
{/* Why Save is unavailable — above the row so it reads before the dead control (objectui#10166). */} diff --git a/ui/packages/plugin-form/src/ModalForm.tsx b/ui/packages/plugin-form/src/ModalForm.tsx index c3f4baf8592..8e8063040df 100644 --- a/ui/packages/plugin-form/src/ModalForm.tsx +++ b/ui/packages/plugin-form/src/ModalForm.tsx @@ -84,6 +84,7 @@ import { hasInlineFieldSource, noSubmitTargetError } from './submitTarget'; import { useRecordInvalidation } from './recordInvalidation'; import { useUploadGate, UploadGateProvider, UploadInFlightNotice } from './uploadGate'; import { useInitialFieldFocus } from './initialFieldFocus'; +import { FormDirtyReportContext } from './formDirtyReport'; // Localized strings for the unsaved-changes guard and, since objectui#11039, // the form's own chrome (the default submit and cancel labels and the @@ -1183,9 +1184,49 @@ const ModalFormBody: React.FC = ({ ); } + // Radix routes backdrop click, Escape, and the X button all through here, in + // both arms. Closes are intercepted so unsaved input isn't silently + // discarded. + const handleDialogOpenChange = (open: boolean) => { + if (open) { schema.onOpenChange?.(true); return; } + attemptClose(false); + }; + + // Unsaved-changes guard — rendered INSIDE DialogContent so its portal + // inherits the Dialog's Radix layer context (focus scope + dismissable + // layer) through React. As a sibling of it had no such context, so + // the still-open modal swallowed its button clicks and "Keep editing" did + // nothing. Nesting lets Radix stack the two modals correctly: the alert + // becomes the topmost layer and its buttons work. + const discardDialog = ( + + + + {t('form.discardTitle')} + + {t('form.discardMessage')} + + + + { cancelIntentRef.current = false; }}> + {t('form.keepEditing')} + + + {t('form.discard')} + + + + + ); + if (subforms?.length && schema.mode !== 'view') { + // The master-detail form owns its Save bar and pins it to the bottom of + // the body scroller below (objectstack#34599); it reports its unsaved + // input — header, lines, row editor — into this dialog's close guard, so + // the close paths prompt here exactly as they do in the flat arm. Its + // batch save carries no OCC token, so this arm has no conflict dialog. return ( - + = ({ )}
}> + = ({ }} dataSource={dataSource} /> +
+ {discardDialog}
); @@ -1249,15 +1293,7 @@ const ModalFormBody: React.FC = ({ const hasFooter = !loading && !error && (showSubmit || showCancel || showReset); return ( - { - // Radix routes backdrop click, Escape, and the X button all through - // here. Intercept closes so unsaved input isn't silently discarded. - if (open) { schema.onOpenChange?.(true); return; } - attemptClose(false); - }} - > + = ({
)} - {/* Unsaved-changes guard — rendered INSIDE DialogContent so its portal - inherits the Dialog's Radix layer context (focus scope + dismissable - layer) through React. As a sibling of it had no such - context, so the still-open modal swallowed its button clicks and - "Keep editing" did nothing. Nesting lets Radix stack the two modals - correctly: the alert becomes the topmost layer and its buttons work. */} - - - - {t('form.discardTitle')} - - {t('form.discardMessage')} - - - - { cancelIntentRef.current = false; }}> - {t('form.keepEditing')} - - - {t('form.discard')} - - - - + {discardDialog} {/* Same nesting rationale as the discard guard above: as a child of the Dialog content the conflict alert stacks as the topmost Radix layer, so its buttons receive clicks while the modal stays open. */} diff --git a/ui/packages/plugin-form/src/ObjectForm.tsx b/ui/packages/plugin-form/src/ObjectForm.tsx index 59d423a774b..e53de3f1304 100644 --- a/ui/packages/plugin-form/src/ObjectForm.tsx +++ b/ui/packages/plugin-form/src/ObjectForm.tsx @@ -18,6 +18,7 @@ import type { ObjectFormSchema, FormField, FormSchema, DataSource } from '@objec import { SchemaRenderer, useSafeFieldLabel } from '@object-ui/react'; import { pickLocalized, useObjectTranslation, useLocalization, withHomeAmountSource } from '@object-ui/i18n'; import { useRecordInvalidation } from './recordInvalidation'; +import { useReportedDirtyChange } from './formDirtyReport'; import { mapFieldTypeToFormType, buildValidationRules, formatFileSize, fieldHelpText, withFollowedParentObject, withFormObject, PERMISSION_SET_GRANT_COLUMNS } from '@object-ui/fields'; import { isExpressionComputedField } from '@object-ui/core'; import { useIsMobile, toast } from '@object-ui/components'; @@ -814,8 +815,11 @@ const SimpleObjectForm: React.FC<{ schema: LocalizedObjectFormSchema; dataSource // (objectui#10715). Dirtiness is read from the form renderer's existing // `onDirtyChange` channel; nothing new is declared on any schema. const readsRecord = !!schema.recordId && schema.mode !== 'create' && !hasInlineFields; - const { refetch: recordRefetch, onDirtyChange: handleDirtyChange, saved: recordSaved } = + const { refetch: recordRefetch, onDirtyChange: onBusDirtyChange, saved: recordSaved } = useRecordInvalidation(schema.objectName, schema.recordId, readsRecord); + // The same verdict reaches a hosting master-detail form, when one provides a + // reporter (`formDirtyReport.ts`): its close guard counts the header's input. + const handleDirtyChange = useReportedDirtyChange(onBusDirtyChange); // The `recordRefetch` value the fetch effect last ran for — a run that moved // it is a re-read IN PLACE and must not enter the loading branch. const appliedRecordRefetchRef = React.useRef(0); diff --git a/ui/packages/plugin-form/src/TabbedForm.tsx b/ui/packages/plugin-form/src/TabbedForm.tsx index 81fd60cb449..113cb850162 100644 --- a/ui/packages/plugin-form/src/TabbedForm.tsx +++ b/ui/packages/plugin-form/src/TabbedForm.tsx @@ -39,6 +39,7 @@ import { } from './loadFailure'; import { hasInlineFieldSource, noSubmitTargetError } from './submitTarget'; import { useRecordInvalidation } from './recordInvalidation'; +import { useReportedDirtyChange } from './formDirtyReport'; import { useUploadGate, UploadGateProvider, UploadInFlightNotice } from './uploadGate'; import { useFormChromeTranslation } from './formChrome'; @@ -374,8 +375,10 @@ export const TabbedForm: React.FC = ({ // this record, to its object or to `'*'` re-reads the record IN PLACE through // the effect below while the form is pristine, and is held while it is dirty. // Dirtiness is the form renderer's `onDirtyChange`, wired below. - const { refetch: recordRefetch, onDirtyChange: handleDirtyChange, saved: recordSaved } = + const { refetch: recordRefetch, onDirtyChange: onBusDirtyChange, saved: recordSaved } = useRecordInvalidation(schema.objectName, schema.recordId, !!schema.recordId && schema.mode !== 'create'); + // Also reported to a hosting master-detail form (`formDirtyReport.ts`). + const handleDirtyChange = useReportedDirtyChange(onBusDirtyChange); // Fetch initial data for edit/view modes React.useEffect(() => { diff --git a/ui/packages/plugin-form/src/formDirtyReport.ts b/ui/packages/plugin-form/src/formDirtyReport.ts new file mode 100644 index 00000000000..8711e52aea6 --- /dev/null +++ b/ui/packages/plugin-form/src/formDirtyReport.ts @@ -0,0 +1,67 @@ +/** + * ObjectUI + * Copyright (c) 2024-present ObjectStack Inc. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */ + +/** + * formDirtyReport — the package-internal channel a record form's unsaved-input + * verdict travels UP through when its host cannot hand it a callback + * (objectstack#34599). + * + * ## What it carries + * + * `ModalForm` and `DrawerForm` guard a close (backdrop, Escape, the X) and a + * page unload with a "Discard changes?" prompt while the form holds unsaved + * input. Their plain arm hears that from the form renderer's `onDirtyChange`. + * Their master-detail arm renders `MasterDetailForm`, whose unsaved input + * lives in three places no host can see: the header `ObjectForm`'s renderer, + * the line grids' row state, and the open row editor's own `ObjectForm`. + * + * ## The shape + * + * One React context holding a reporter, `(dirty: boolean) => void`. The NEAREST + * provider is the one a form reports to: + * + * - `ModalForm` / `DrawerForm` provide their close guard's setter around the + * master-detail form they host; + * - `MasterDetailForm` reports its combined verdict (header OR lines OR row + * editor) to that one, and provides its OWN reporters around the header + * form and the row editor, so neither reaches the host directly; + * - the record-form layouts the header and the row editor render through + * (`ObjectForm`'s default arm, `TabbedForm`) report the renderer's + * `onDirtyChange` verdict to the nearest provider, beside their bus gate, + * through {@link useReportedDirtyChange}. + * + * With no provider mounted nothing is reported and every form behaves as + * before. The module is not re-exported from the package index: no prop or + * schema key is added to any exported type, so a host outside this package + * cannot depend on it. + * + * A reporter must be referentially stable (a state setter, or a `useCallback` + * on stable inputs): the form renderer resubscribes its dirty watcher whenever + * the `onDirtyChange` it is handed changes identity. + */ +import { createContext, useCallback, useContext } from 'react'; + +export type FormDirtyReporter = (dirty: boolean) => void; + +export const FormDirtyReportContext = createContext(null); + +/** + * The verdict this form reports: `onDirtyChange` (the layout's own handling, + * e.g. the data-invalidation bus gate) composed with the nearest provider's + * reporter, when one is mounted. + */ +export function useReportedDirtyChange(onDirtyChange: FormDirtyReporter): FormDirtyReporter { + const report = useContext(FormDirtyReportContext); + return useCallback( + (dirty: boolean) => { + onDirtyChange(dirty); + report?.(dirty); + }, + [onDirtyChange, report], + ); +} From cc6888256a919627f4035d4045260d7c431e029d Mon Sep 17 00:00:00 2001 From: Claude Date: Tue, 17 Nov 2026 04:00:13 +0000 Subject: [PATCH 2/3] test(plugin-form): pin the master-detail Save bar frame and the subform close guard Claude-Session: https://claude.ai/code/session_01WGufzgwLiKcfujYUug7sPs Co-authored-by: Claude --- .changeset/34599-subform-sticky-save-bar.md | 15 +++ .../plugin-form/src/discardGuard.test.tsx | 120 ++++++++++++++++++ .../plugin-form/src/subformHosts.test.tsx | 80 ++++++++++++ 3 files changed, 215 insertions(+) create mode 100644 .changeset/34599-subform-sticky-save-bar.md diff --git a/.changeset/34599-subform-sticky-save-bar.md b/.changeset/34599-subform-sticky-save-bar.md new file mode 100644 index 00000000000..ca1b73c963c --- /dev/null +++ b/.changeset/34599-subform-sticky-save-bar.md @@ -0,0 +1,15 @@ +--- +'@object-ui/plugin-form': patch +--- + +fix(plugin-form): the master-detail Save bar stays in view, and closing a master-detail dialog with unsaved input asks first + +Clause-②: no +Metadata-protocol: none + +A form with inline sub-tables (`subforms`) drew its Cancel and Save buttons after the last field and the last line, so in a dialog, a drawer or on the record page a long form had to be scrolled to the end before it could be saved. + +- **The action bar is pinned.** `MasterDetailForm` keeps its own Cancel and Save (ADR-0035 Decision §6), and the bar now sticks to the bottom edge of whatever scroll frame hosts the form: the dialog body, the drawer, the record page. The test ids `md-form-cancel` and `md-form-submit` are unchanged. +- **Closing asks before it discards.** The master-detail arm of `ModalForm` closed on Escape, a backdrop click or the X with the typed values and edited lines gone. It now goes through the same "Discard changes?" confirmation, and the same page-unload prompt, as a form without sub-tables. Input counts when it is in the header fields, in the lines (a change the save would write; a blank line does not count) or in the open row editor. `DrawerForm` already routed its close through the guard, and now hears the master-detail form's input too. The explicit Cancel button still closes at once, and a successful save clears the guard. + +Nothing changes in how the form saves (one atomic `/api/v1/batch`), and no prop or type is added to the package's exports. diff --git a/ui/packages/plugin-form/src/discardGuard.test.tsx b/ui/packages/plugin-form/src/discardGuard.test.tsx index 32a3cdf23f9..50bf9c66d3c 100644 --- a/ui/packages/plugin-form/src/discardGuard.test.tsx +++ b/ui/packages/plugin-form/src/discardGuard.test.tsx @@ -17,6 +17,8 @@ import { registerAllFields } from '@object-ui/fields'; import type { DataSource } from '@object-ui/types'; import { ModalForm } from './ModalForm'; import { DrawerForm } from './DrawerForm'; +import { MasterDetailForm } from './MasterDetailForm'; +import { FormDirtyReportContext } from './formDirtyReport'; registerAllFields(); @@ -281,3 +283,121 @@ describe.each(OVERLAY_FORMS)('%s beforeunload guard', (_name, Form) => { expect(fireBeforeUnload().defaultPrevented).toBe(false); }); }); + +/** + * objectstack#34599 — the master-detail arm (`subforms`) of both overlays + * guards its close like the flat arm: input in the header form or in the + * lines prompts on the X; a pristine form, and the explicit Cancel, close at + * once. The master-detail form reports that input through the package-internal + * `FormDirtyReportContext`, and a save clears it. + */ +describe('master-detail overlay unsaved-changes guard (objectstack#34599)', () => { + const mdDs: any = { + getObjectSchema: vi.fn(async (name: string) => + name === 'claim' + ? { name: 'claim', fields: { title: { type: 'text', label: 'Title' } } } + : { name: 'claim_line', fields: { amount: { type: 'number', label: 'Amount' } } }, + ), + find: vi.fn().mockResolvedValue({ data: [] }), + batchTransaction: vi.fn().mockResolvedValue({ results: [{ id: 'c1' }] }), + }; + const subforms = [ + { childObject: 'claim_line', relationshipField: 'claim', title: 'Lines', columns: [{ name: 'amount', label: 'Amount', type: 'number' }] }, + ]; + const mdSchema = (onOpenChange: (open: boolean) => void) => + ({ objectName: 'claim', mode: 'create', title: 'New Claim', open: true, onOpenChange, fields: ['title'], subforms }) as any; + + async function headerInput(): Promise { + await waitFor(() => expect(screen.getByTestId('md-form-submit')).toBeTruthy()); + return waitFor(() => { + const el = document.querySelector('input[name="title"]') as HTMLInputElement | null; + if (!el) throw new Error('header form not ready'); + return el; + }); + } + + it('ModalForm: a pristine master-detail dialog closes on the X with no prompt', async () => { + const onOpenChange = vi.fn(); + render(); + await headerInput(); + + accidentalClose(); + + expect(onOpenChange).toHaveBeenCalledWith(false); + expect(screen.queryByText('Discard changes?')).toBeNull(); + }); + + it('ModalForm: typed header input prompts on the X; "Discard" then closes', async () => { + const onOpenChange = vi.fn(); + render(); + fireEvent.change(await headerInput(), { target: { value: 'Trip to Berlin' } }); + + accidentalClose(); + + await waitFor(() => expect(screen.getByText('Discard changes?')).toBeTruthy()); + expect(onOpenChange).not.toHaveBeenCalled(); + fireEvent.click(screen.getByText('Discard')); + expect(onOpenChange).toHaveBeenCalledWith(false); + }); + + it('ModalForm: an edited line alone prompts on the X', async () => { + const onOpenChange = vi.fn(); + render(); + await headerInput(); + const amount = await waitFor(() => screen.getAllByLabelText('Amount')[0] as HTMLInputElement); + fireEvent.change(amount, { target: { value: '42' } }); + + accidentalClose(); + + await waitFor(() => expect(screen.getByText('Discard changes?')).toBeTruthy()); + expect(onOpenChange).not.toHaveBeenCalled(); + }); + + it('ModalForm: the explicit Cancel closes a dirty master-detail dialog at once', async () => { + const onOpenChange = vi.fn(); + render(); + fireEvent.change(await headerInput(), { target: { value: 'Trip to Berlin' } }); + + fireEvent.click(screen.getByTestId('md-form-cancel')); + + expect(onOpenChange).toHaveBeenCalledWith(false); + expect(screen.queryByText('Discard changes?')).toBeNull(); + }); + + it('ModalForm: a dirty master-detail dialog blocks a page unload', async () => { + render(); + fireEvent.change(await headerInput(), { target: { value: 'Trip to Berlin' } }); + await waitFor(() => expect(fireBeforeUnload().defaultPrevented).toBe(true)); + }); + + it('DrawerForm: typed header input prompts on the X', async () => { + const onOpenChange = vi.fn(); + render(); + fireEvent.change(await headerInput(), { target: { value: 'Trip to Berlin' } }); + + accidentalClose(); + + await waitFor(() => expect(screen.getByText('Discard changes?')).toBeTruthy()); + expect(onOpenChange).not.toHaveBeenCalled(); + }); + + it('MasterDetailForm reports its input to the nearest reporter, and a save clears it', async () => { + const reports: boolean[] = []; + const report = (dirty: boolean) => { reports.push(dirty); }; + render( + + + , + ); + fireEvent.change(await headerInput(), { target: { value: 'Trip to Berlin' } }); + await waitFor(() => expect(reports.at(-1)).toBe(true)); + + fireEvent.click(screen.getByTestId('md-form-submit')); + + await waitFor(() => expect(mdDs.batchTransaction).toHaveBeenCalled()); + await waitFor(() => expect(reports.at(-1)).toBe(false)); + }); +}); diff --git a/ui/packages/plugin-form/src/subformHosts.test.tsx b/ui/packages/plugin-form/src/subformHosts.test.tsx index 015bd53a980..edf01147d19 100644 --- a/ui/packages/plugin-form/src/subformHosts.test.tsx +++ b/ui/packages/plugin-form/src/subformHosts.test.tsx @@ -4,6 +4,7 @@ import React from 'react'; import { registerAllFields } from '@object-ui/fields'; import { ModalForm } from './ModalForm'; import { DrawerForm } from './DrawerForm'; +import { ObjectForm } from './ObjectForm'; // sonner toast is wired to a mounted the tests don't render. const { toastSuccess, toastError } = vi.hoisted(() => ({ toastSuccess: vi.fn(), toastError: vi.fn() })); @@ -76,3 +77,82 @@ describe('ModalForm + DrawerForm host master-detail when subforms are set', () = expect(screen.queryByTestId('md-form-submit')).toBeNull(); }); }); + +/** + * objectstack#34599 — the master-detail Save bar stays in view at any scroll + * position in all three hosts. jsdom does no layout, so what is pinned is the + * structure `position: sticky` depends on: the bar is sticky at the bottom, it + * is a direct child of the form's root (sticky is confined to its parent box), + * and the first ancestor that sets `overflow` is the host's own scroller — any + * overflow box in between would become the sticky frame and the bar would + * scroll away inside it. + */ +describe('master-detail Save bar is pinned to the host scroll frame (objectstack#34599)', () => { + const OVERFLOW = /(^|\s)overflow-(auto|scroll|hidden|y-auto|y-scroll|y-hidden|x-auto|x-hidden)(\s|$)/; + + async function pinnedBar() { + const submit = await waitFor(() => screen.getByTestId('md-form-submit')); + const bar = screen.getByTestId('md-form-actions'); + expect(bar.contains(submit)).toBe(true); + expect(bar.classList.contains('sticky')).toBe(true); + expect(bar.classList.contains('bottom-0')).toBe(true); + // Opaque, so lines scrolling beneath it do not show through. + expect(bar.classList.contains('bg-background')).toBe(true); + return bar; + } + + /** The nearest ancestor of the bar whose classes set an overflow. */ + function firstOverflowAncestor(bar: HTMLElement): HTMLElement | null { + let el = bar.parentElement; + while (el && el !== document.body) { + if (OVERFLOW.test(el.getAttribute('class') ?? '')) return el; + el = el.parentElement; + } + return null; + } + + it('ModalForm: the bar sticks to the dialog body scroller, and the dialog draws no footer of its own', async () => { + render( + , + ); + const bar = await pinnedBar(); + const scroller = firstOverflowAncestor(bar); + expect(scroller?.className).toContain('overflow-y-auto'); + expect(scroller?.className).toContain('flex-1'); + // ADR-0035 Decision §6: the form owns its Save — one Save in the dialog. + expect(screen.queryByTestId('modal-form-footer')).toBeNull(); + expect(screen.getAllByTestId('md-form-submit')).toHaveLength(1); + }); + + it('DrawerForm: the bar sticks to the drawer content, which is the scroller', async () => { + render( + , + ); + const bar = await pinnedBar(); + const scroller = firstOverflowAncestor(bar); + expect(scroller?.getAttribute('role')).toBe('dialog'); + expect(scroller?.className).toContain('overflow-y-auto'); + expect(screen.queryByTestId('drawer-form-footer')).toBeNull(); + }); + + it('ObjectForm page host: nothing between the bar and the page sets an overflow', async () => { + const { container } = render( + , + ); + const bar = await pinnedBar(); + // The record page's own scroller is the frame; inside this component + // there is no overflow box for the bar to stick to instead. + const hit = firstOverflowAncestor(bar); + expect(hit === null || !container.contains(hit)).toBe(true); + expect(bar.parentElement?.parentElement).toBe(container); + }); +}); From c367f82de3aa926499097dbf8117e18cb6bea218 Mon Sep 17 00:00:00 2001 From: Claude Date: Tue, 17 Nov 2026 04:02:34 +0000 Subject: [PATCH 3/3] test(plugin-form): an edit save clears the master-detail form's reported input Claude-Session: https://claude.ai/code/session_01WGufzgwLiKcfujYUug7sPs Co-authored-by: Claude --- .../plugin-form/src/discardGuard.test.tsx | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/ui/packages/plugin-form/src/discardGuard.test.tsx b/ui/packages/plugin-form/src/discardGuard.test.tsx index 50bf9c66d3c..5ed6e8bc901 100644 --- a/ui/packages/plugin-form/src/discardGuard.test.tsx +++ b/ui/packages/plugin-form/src/discardGuard.test.tsx @@ -400,4 +400,34 @@ describe('master-detail overlay unsaved-changes guard (objectstack#34599)', () = await waitFor(() => expect(mdDs.batchTransaction).toHaveBeenCalled()); await waitFor(() => expect(reports.at(-1)).toBe(false)); }); + + it('an edit save clears the reported input, though the header form stays mounted', async () => { + // A create remounts the header for the next entry; an edit keeps it, and + // its renderer still holds the opening record as its baseline. + const editDs: any = { + ...mdDs, + findOne: vi.fn().mockResolvedValue({ id: 'c1', title: 'Trip' }), + batchTransaction: vi.fn().mockResolvedValue({ results: [{ id: 'c1', title: 'Trip to Berlin' }] }), + }; + const reports: boolean[] = []; + const report = (dirty: boolean) => { reports.push(dirty); }; + render( + + + , + ); + const input = await headerInput(); + await waitFor(() => expect(input.value).toBe('Trip')); + fireEvent.change(input, { target: { value: 'Trip to Berlin' } }); + await waitFor(() => expect(reports.at(-1)).toBe(true)); + + fireEvent.click(screen.getByTestId('md-form-submit')); + + await waitFor(() => expect(editDs.batchTransaction).toHaveBeenCalled()); + await waitFor(() => expect(reports.at(-1)).toBe(false)); + expect((document.querySelector('input[name="title"]') as HTMLInputElement).value).toBe('Trip to Berlin'); + }); });