@@ -33,9 +33,10 @@ import {
3333 AlertDialogDescription ,
3434 AlertDialogAction ,
3535 AlertDialogCancel ,
36+ RecordTopBarButton ,
3637 toast ,
3738} from '@object-ui/components' ;
38- import { Loader2 } from 'lucide-react' ;
39+ import { Loader2 , Maximize2 , Minimize2 } from 'lucide-react' ;
3940import { MasterDetailForm } from './MasterDetailForm' ;
4041import { SchemaRenderer , useSafeFieldLabel , usePreviewMode } from '@object-ui/react' ;
4142import { createSafeTranslation , useLocalization } from '@object-ui/i18n' ;
@@ -86,6 +87,7 @@ import { useRecordInvalidation } from './recordInvalidation';
8687import { useUploadGate , UploadGateProvider , UploadInFlightNotice } from './uploadGate' ;
8788import { useInitialFieldFocus } from './initialFieldFocus' ;
8889import { FormDirtyReportContext } from './formDirtyReport' ;
90+ import { useModalFormMaximized } from './modalMaximize' ;
8991
9092// Localized strings for the unsaved-changes guard and, since objectui#11039,
9193// the form's own chrome (the default submit and cancel labels and the
@@ -116,6 +118,10 @@ const useDiscardTranslation = createSafeTranslation(
116118 // The heading of the fields no declared field group claims
117119 // (`deriveFieldGroupSections`' trailing bucket).
118120 'common.ungroupedSection' : 'Other' ,
121+ // The header's maximize / restore switch: the record drawer's own pair of
122+ // keys and labels (objectstack-ai/objectstack#34604).
123+ 'detail.maximize' : 'Maximize' ,
124+ 'detail.restoreSize' : 'Restore size' ,
119125 } ,
120126 'form.discardTitle' ,
121127) ;
@@ -511,13 +517,20 @@ const ModalFormBody: React.FC<ModalFormProps> = ({
511517 // undeclared grid is at least `DIALOG_DEFAULT_COLUMNS` wide whatever the
512518 // size, so the size reads that floor and never the count it then bounds
513519 // (objectstack-ai/objectstack#34607).
520+ // The header's maximize switch (objectstack-ai/objectstack#34604):
521+ // maximized, the dialog is `full` whatever its authored or inferred size,
522+ // and every reader of the size below — the width class and the undeclared
523+ // column count — reads that effective size.
524+ const { maximized, toggleMaximized } = useModalFormMaximized ( schema . objectName ) ;
525+
514526 const effectiveModalSize = useMemo ( ( ) => {
527+ if ( maximized ) return 'full' ;
515528 if ( schema . modalSize ) return schema . modalSize ;
516529 const columns = effectiveSections ?. length
517530 ? sectionedFormColumns ( schema . columns , effectiveSections . map ( ( s ) => s . columns ) , DIALOG_DEFAULT_COLUMNS )
518531 : ( clampColumns ( schema . columns ) ?? DIALOG_DEFAULT_COLUMNS ) ;
519532 return inferModalSize ( Math . min ( columns , inferColumns ( layoutFieldCount ) ) ) ;
520- } , [ schema . modalSize , schema . columns , effectiveSections , layoutFieldCount ] ) ;
533+ } , [ maximized , schema . modalSize , schema . columns , effectiveSections , layoutFieldCount ] ) ;
521534
522535 // The count an undeclared form or section draws in THIS dialog
523536 // (objectstack-ai/objectstack#34607): from the field count, bounded by the
@@ -535,6 +548,13 @@ const ModalFormBody: React.FC<ModalFormProps> = ({
535548 } , [ formFields , objectSchema , flatColumns , schema . mode , effectiveSections ] ) ;
536549
537550 const sizeClass = modalSizeClasses [ effectiveModalSize ] || modalSizeClasses . default ;
551+ // The content's height: a phone sheet is always the whole screen; from `sm`
552+ // up the dialog grows with its body to a `90vh` cap, and maximized it fills
553+ // `95dvh` — the height counterpart of the `full` size's `95vw` — so its body
554+ // scroller, not the page, scrolls a long form.
555+ const heightClass = maximized
556+ ? 'h-[100dvh] sm:h-[95dvh] sm:max-h-[95dvh]'
557+ : 'h-[100dvh] sm:h-auto sm:max-h-[90vh]' ;
538558
539559 // Fetch object schema
540560 useEffect ( ( ) => {
@@ -1219,6 +1239,26 @@ const ModalFormBody: React.FC<ModalFormProps> = ({
12191239 attemptClose ( false ) ;
12201240 } ;
12211241
1242+ // The header's maximize / restore switch (objectstack-ai/objectstack#34604):
1243+ // the record drawer's control — its `RecordTopBarButton`, its lucide pair at
1244+ // its size, its labels — drawn just before the dialog's close (X), in both
1245+ // arms. The last child of the content, so it sits after the form in the tab
1246+ // order and right before the X, as the drawer orders them. From `sm` up
1247+ // only: the phone sheet already fills the screen. Toggling changes the
1248+ // content's classes and nothing else, so the form below stays mounted.
1249+ const maximizeButton = (
1250+ < RecordTopBarButton
1251+ label = { maximized ? t ( 'detail.restoreSize' ) : t ( 'detail.maximize' ) }
1252+ onClick = { toggleMaximized }
1253+ data-testid = "modal-form-maximize"
1254+ className = { cn ( 'absolute top-2.5 hidden sm:inline-flex' , showCloseButton ? 'right-9' : 'right-3' ) }
1255+ >
1256+ { maximized ? < Minimize2 className = "h-3.5 w-3.5" /> : < Maximize2 className = "h-3.5 w-3.5" /> }
1257+ </ RecordTopBarButton >
1258+ ) ;
1259+ // The header keeps its title clear of the switch and the X from `sm` up.
1260+ const headerClass = 'shrink-0 px-4 pt-4 sm:px-6 sm:pt-6 sm:pr-20 pb-2 border-b' ;
1261+
12221262 // Unsaved-changes guard — rendered INSIDE DialogContent so its portal
12231263 // inherits the Dialog's Radix layer context (focus scope + dismissable
12241264 // layer) through React. As a sibling of <Dialog> it had no such context, so
@@ -1258,10 +1298,11 @@ const ModalFormBody: React.FC<ModalFormProps> = ({
12581298 showCloseButton = { showCloseButton }
12591299 onOpenAutoFocus = { initialFieldFocus . onOpenAutoFocus }
12601300 onCloseAutoFocus = { initialFieldFocus . onCloseAutoFocus }
1261- className = { cn ( sizeClass , 'flex flex-col h-[100dvh] sm:h-auto sm:max-h-[90vh] overflow-hidden p-0' , className , schema . className ) }
1301+ className = { cn ( sizeClass , 'flex flex-col overflow-hidden p-0' , heightClass , className , schema . className ) }
1302+ data-maximized = { maximized ? '' : undefined }
12621303 >
12631304 { ( schema . title || schema . description ) && (
1264- < DialogHeader className = "shrink-0 px-4 pt-4 sm:px-6 sm:pt-6 pb-2 border-b" >
1305+ < DialogHeader className = { headerClass } >
12651306 { schema . title && < DialogTitle > { schema . title } </ DialogTitle > }
12661307 { schema . description ? (
12671308 < DialogDescription > { schema . description } </ DialogDescription >
@@ -1312,6 +1353,7 @@ const ModalFormBody: React.FC<ModalFormProps> = ({
13121353 </ Suspense >
13131354 </ div >
13141355 { discardDialog }
1356+ { maximizeButton }
13151357 </ MobileDialogContent >
13161358 </ Dialog >
13171359 ) ;
@@ -1325,10 +1367,11 @@ const ModalFormBody: React.FC<ModalFormProps> = ({
13251367 showCloseButton = { showCloseButton }
13261368 onOpenAutoFocus = { initialFieldFocus . onOpenAutoFocus }
13271369 onCloseAutoFocus = { initialFieldFocus . onCloseAutoFocus }
1328- className = { cn ( sizeClass , 'flex flex-col h-[100dvh] sm:h-auto sm:max-h-[90vh] overflow-hidden p-0' , className , schema . className ) }
1370+ className = { cn ( sizeClass , 'flex flex-col overflow-hidden p-0' , heightClass , className , schema . className ) }
1371+ data-maximized = { maximized ? '' : undefined }
13291372 >
13301373 { ( schema . title || schema . description ) && (
1331- < DialogHeader className = "shrink-0 px-4 pt-4 sm:px-6 sm:pt-6 pb-2 border-b" >
1374+ < DialogHeader className = { headerClass } >
13321375 { schema . title && < DialogTitle > { schema . title } </ DialogTitle > }
13331376 { schema . description ? (
13341377 < DialogDescription > { schema . description } </ DialogDescription >
@@ -1406,6 +1449,7 @@ const ModalFormBody: React.FC<ModalFormProps> = ({
14061449 the Dialog content the conflict alert stacks as the topmost Radix
14071450 layer, so its buttons receive clicks while the modal stays open. */ }
14081451 { conflictDialog }
1452+ { maximizeButton }
14091453 </ MobileDialogContent >
14101454 </ Dialog >
14111455 ) ;
0 commit comments