Repository navigation
|
Hi everyone 👋 I'm working with the new Field components ( The expected hierarchyAs I understand it, the correct order is: The problemI have a page-level // UpdateFeaturePage.tsx
<FieldSet>
<FieldLegend>Edit Feature</FieldLegend>
<FieldDescription>Fill value field</FieldDescription>
<FieldGroup className="lg:grid lg:grid-cols-[1fr_var(--container-xs)]">
{/* This child contains a <form> internally ⬇️ */}
<FeatureValues featureData={featureData} />
<Card>
{/* ... FeatureProperties ... */}
</Card>
</FieldGroup>
</FieldSet>// FeatureValues.tsx
<FieldGroup>
<AddFeatureValue featureData={featureData} />
{/* ... table / empty state ... */}
</FieldGroup>// AddFeatureValue.tsx
<form id="add-value-form" onSubmit={e => e.preventDefault()}>
<FieldGroup>
<form.AppField name="value">
{field => <field.TextField label="Value" />}
</form.AppField>
<Field className="sm:w-max">
<form.AppForm>
<form.SubscribeButton form="add-value-form" label="Add" />
</form.AppForm>
</Field>
</FieldGroup>
</form>This results in a broken hierarchy: What I triedI moved <form id="add-value-form" onSubmit={e => e.preventDefault()}>
<FieldSet>
<FieldGroup>
{/* fields... */}
</FieldGroup>
</FieldSet>
</form>And removed the redundant This works, but I'm not sure if nesting a Questions
Any guidance or examples would be greatly appreciated. Thanks! 🙏 |
Replies: 3 comments
|
that order is not a strict component tree requirement |
|
To answer your three questions directly based on HTML5 specifications and component composition in React: 1. Is orm > FieldSet > FieldGroup > Field a strict hierarchy?No, it is a semantic and accessibility recommendation, not a strict component constraint. Under the hood in shadcn/ui:
The single hard constraint in HTML is that elements cannot be nested inside another . Because your page-level layout does not have an outer , placing a inside a layout container like FieldGroup is completely valid HTML.2. Recommended pattern when a child needs its own formThere are two clean ways to structure this: Approach A: Invert Layout & Form Ownership (Recommended)Use standard layout primitives ( with grid classes) for the page-level two-column layout, and let each functional component own its own and internal :
` sx Edit FeatureManage feature configuration and values
{/* FeatureProperties */}
` sx Approach B: HTML5 orm attribute decouplingIf visual styling requires to wrap the entire container, you can declare outside or at the root, and associate inputs via the native orm="add-value-form" attribute:` sx {/* Inside AddFeatureValue, link inputs directly */} Add `3. Is nesting FieldSet inside FieldGroup valid?Yes, nesting inside or vice-versa is valid HTML5.
The only caveat to keep in mind is Tailwind direct-child spacing: if your parent uses direct child selectors ([&>*] or space-y utilities), adding an unstyled wrapper between elements can break margin collapsing or flex gap alignment unless you apply display: contents: ` sx ... `Approach A (inverting the boundary so each form owns its own FieldSet) is the cleanest, most maintainable, and matches how component libraries design multi-form administrative pages. |
|
Agree the order isn't enforced: none of these components read context from each other. // FieldGroup
"group/field-group @container/field-group flex w-full flex-col gap-7 ... [&>[data-slot=field-group]]:gap-4"
Because of 3 and 4, I'd use a plain |
Agree the order isn't enforced: none of these components read context from each other.
FieldSetis a plain<fieldset>andFieldGroupis a<div>with classes. But some of those classes depend on DOM structure, and that's where a<form>in between changes things. Fromfield.tsx:Spacing of nested groups. A
FieldGroupthat is a direct child of another one getsgap-4instead ofgap-7. With a<form>(or aFieldSet) in between, the selector no longer matches, so the inner group goes back togap-7.display: contentson the form doesn't fix this: it changes layout, but child…