feat(fieldset): align with Fusion DS#7964
Conversation
| onClick={() => contentEditorRef.current?.focus()} | ||
| isRequired={required} | ||
| labelId={`${namespace}-label`} | ||
| isLarge={actualSize === "large"} |
There was a problem hiding this comment.
nitpick: you've used actualSize === "large" twice you could make this into a const further up. Not a huge deal though.
There was a problem hiding this comment.
The label and hintText components need to be updated to the newer versions so I might leave this as is since this will likely have to be removed later on.
| required={required} | ||
| error={!!error} | ||
| required={required || fieldsetRequired} | ||
| error={!!error || fieldsetError} |
There was a problem hiding this comment.
nitpick: you've used required || fieldsetRequired twice you could make this into a const further up. Not a huge deal though.
There was a problem hiding this comment.
Can't really see where else I've used it in this file?
There was a problem hiding this comment.
Sorry this comment should have been about !!error || fieldsetErrorbeing used twice
| > | ||
| <Input | ||
| aria-invalid={!!error} | ||
| aria-invalid={!!error || fieldsetError} |
There was a problem hiding this comment.
nitpick: you've used error or !!error || fieldsetError twice-ish you could make this into a const further up. Not a huge deal though.
There was a problem hiding this comment.
I'll leave this as is since this component currently in progress.
| id={uniqueId} | ||
| name={uniqueName} | ||
| aria-invalid={!!error} | ||
| aria-invalid={!!error || !!fieldsetError} |
There was a problem hiding this comment.
nitpick: you've used error or !!error || fieldsetError twice you could make this into a const further up. Not a huge deal though.
| flex-wrap: wrap; | ||
| `} | ||
|
|
||
| .label { |
There was a problem hiding this comment.
question: do we need to use a className here? Could we not just target the label element directly like so:
label { }
There was a problem hiding this comment.
If we don't need this we can likely remove the className that has been added in both label component files (modern & legacy)
| ref={wrapperRef} | ||
| role="presentation" | ||
| size={size} | ||
| size={fieldsetSize || size} |
There was a problem hiding this comment.
nitpick: you've used fieldsetSize|| size twice you could make this into a const further up. Not a huge deal though.
| $size: "small" | "medium" | "large"; | ||
| }; | ||
|
|
||
| export const StyledLegend = styled.legend<StyledLegendProps>` |
There was a problem hiding this comment.
question: Instead of this styled component, could we potentially use the new RequiredFieldsIndicator? No problem if it is not viable
There was a problem hiding this comment.
Mainly did this to update the font, colour etc but we could look into replacing the ::after to apply the asterisk, would prefer to do this separately since this could be done to all components but will leave as is for now for consistency.
| }; | ||
|
|
||
| export type StyledFieldsetProps = { | ||
| $size: "small" | "medium" | "large"; |
There was a problem hiding this comment.
suggestion: I see we've redefined $size: "small" | "medium" | "large a fair bit in this file, could we make this into a shared type to avoid repetition?
| const uniqueId = id || internalId.current; | ||
|
|
||
| const legendHintId = legendHint ? `${uniqueId}-hint` : undefined; | ||
| const validationId = (error || warning) && `${uniqueId}-validation-message`; |
There was a problem hiding this comment.
nitpick: could make error || warning into a const above like hasError
There was a problem hiding this comment.
Not too sure if I think this is necessary since it wouldn't be reused anywhere else.
| {children} | ||
| </FieldsetContext.Provider> | ||
| </StyledFieldsetContent> | ||
| {!validationMessagePositionTop && validationMessage()} |
There was a problem hiding this comment.
praise: I like the way you've done this
There was a problem hiding this comment.
Pull request overview
Aligns the public Fieldset component with Fusion DS by introducing new layout/validation/typography capabilities, plus a new FieldsetContext to cascade size/required/error state into descendant Carbon inputs.
Changes:
- Reworks
Fieldsetmarkup + styling to supportsize,legendHint,orientation, validation messaging, andlabelWeight. - Introduces
FieldsetContextand updates multiple inputs (Textbox/Textarea/TextEditor/Date/Checkbox + internal CheckableInput) to consume Fieldset-providedrequired, sizing, and/or error state. - Updates docs, Storybook stories, and Jest/Playwright coverage for the new behavior.
Reviewed changes
Copilot reviewed 16 out of 16 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| src/components/textbox/internal/next/text-input.component.tsx | Consumes FieldsetContext for size/required/error to align textbox behavior inside fieldsets. |
| src/components/textarea/textarea.component.tsx | Consumes FieldsetContext for required/error propagation. |
| src/components/text-editor/text-editor.component.tsx | Consumes FieldsetContext for size/required/error propagation into the editor. |
| src/components/fieldset/fieldset.test.tsx | Expands Jest coverage for new Fieldset props/behaviors. |
| src/components/fieldset/fieldset.style.ts | Replaces legacy styles with token-driven Fusion-aligned styles (size/orientation/label weight). |
| src/components/fieldset/fieldset.stories.tsx | Updates stories to demonstrate new props and Fusion-aligned behavior. |
| src/components/fieldset/fieldset.pw.tsx | Updates Playwright accessibility coverage for the updated Fieldset. |
| src/components/fieldset/fieldset.mdx | Updates documentation and examples to reflect the new API and behavior. |
| src/components/fieldset/fieldset.component.tsx | Rebuilds Fieldset implementation, adds new props, validation rendering, and provides FieldsetContext. |
| src/components/fieldset/fieldset-test.stories.tsx | Updates Storybook test stories to cover new prop combinations and child variations. |
| src/components/fieldset/components.test-pw.tsx | Simplifies the Playwright mounting wrapper component used by a11y tests. |
| src/components/fieldset/internal/fieldset.context.ts | Adds FieldsetContext used to cascade size/required/error state. |
| src/components/date/date.component.tsx | Consumes FieldsetContext size to align DateInput sizing in a Fieldset. |
| src/components/checkbox/checkbox.component.tsx | Consumes FieldsetContext size/error for checkbox visuals/validation inside a Fieldset. |
| src/internal/checkable-input/checkable-input.component.tsx | Consumes FieldsetContext required to apply required semantics to checkable inputs inside Fieldset. |
| skills/carbon-react/components/fieldset.md | Regenerated skills docs reflecting the new Fieldset API. |
| test(`should pass accessibility tests with warning validation`, async ({ | ||
| mount, | ||
| page, | ||
| }) => { | ||
| await mount(<FieldsetComponent error="error message" />); |
|
|
||
| test("Fieldset Legend adds an asterisk after the text when the field is mandatory", () => { | ||
| // coverage | ||
| test("should render render with expected styles when `orientation` is 'horizontal'", () => { |
| {(legend || legendHint) && ( | ||
| <div> | ||
| {legend && ( | ||
| <StyledLegend | ||
| $isRequired={required} | ||
| data-element="legend" | ||
| data-role="legend" | ||
| $size={size} | ||
| > | ||
| {legend} | ||
| </StyledLegend> | ||
| )} | ||
|
|
||
| {legendHint && ( | ||
| <HintText id={legendHintId} size={size}> | ||
| {legendHint} | ||
| </HintText> | ||
| )} | ||
| </div> | ||
| )} |
|
@nuria1110 Great work overall, looking good! 👍 A few small things to flag:
|
be61c6e
|
@nuria1110 Thanks for the fixing, looking good! Gap confirmed fixed ✅ |
|
🎉 This PR is included in version 159.9.0 🎉 The release is available on: Your semantic-release bot 📦🚀 |

Proposed behaviour
Aligns
Fieldsetto Fusion DS and applies fusion-tokens.sizeprop to support"small","medium"and"large"sizes.legendHintprop to support hint text:orientationprop to support"horizontal"and"vertical"layouts:errorandwarningprops to support validation:labelWeightprop to support"regular"and"bold"child input labels for all Carbon inputs:Current behaviour
Fieldsetis not aligned to Fusion DS.Checklist
d.tsfile added or updated if requiredQA
Additional context
Testing instructions