Skip to content

feat(fieldset): align with Fusion DS#7964

Merged
nuria1110 merged 1 commit into
masterfrom
fieldset-audit
Jun 8, 2026
Merged

feat(fieldset): align with Fusion DS#7964
nuria1110 merged 1 commit into
masterfrom
fieldset-audit

Conversation

@nuria1110

Copy link
Copy Markdown
Contributor

Proposed behaviour

Aligns Fieldset to Fusion DS and applies fusion-tokens.

  • Adds size prop to support "small", "medium" and "large" sizes.
  • Adds legendHint prop to support hint text:
image
  • Adds orientation prop to support "horizontal" and "vertical" layouts:
image image
  • Adds error and warning props to support validation:
image image
  • Adds labelWeight prop to support "regular" and "bold" child input labels for all Carbon inputs:
image

Current behaviour

Fieldset is not aligned to Fusion DS.

Checklist

  • Commits follow our style guide
  • Related issues linked in commit messages if required
  • Screenshots are included in the PR if useful
  • All themes are supported if required
  • Unit tests added or updated if required
  • Playwright automation tests added or updated if required
  • Storybook added or updated if required
  • Translations added or updated (including creating or amending translation keys table in storybook) if required
  • Typescript d.ts file added or updated if required
  • Related docs have been updated if required

QA

  • Tested in provided StackBlitz sandbox/Storybook
  • Add new Playwright test coverage if required
  • Carbon implementation matches Design System/designs
  • UI Tests GitHub check reviewed if required

Additional context

Testing instructions

onClick={() => contentEditorRef.current?.focus()}
isRequired={required}
labelId={`${namespace}-label`}
isLarge={actualSize === "large"}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nitpick: you've used actualSize === "large" twice you could make this into a const further up. Not a huge deal though.

@nuria1110 nuria1110 May 26, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nitpick: you've used required || fieldsetRequired twice you could make this into a const further up. Not a huge deal though.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can't really see where else I've used it in this file?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry this comment should have been about !!error || fieldsetErrorbeing used twice

>
<Input
aria-invalid={!!error}
aria-invalid={!!error || fieldsetError}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nitpick: you've used error or !!error || fieldsetError twice-ish you could make this into a const further up. Not a huge deal though.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll leave this as is since this component currently in progress.

id={uniqueId}
name={uniqueName}
aria-invalid={!!error}
aria-invalid={!!error || !!fieldsetError}

@tomdavies73 tomdavies73 May 19, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

question: do we need to use a className here? Could we not just target the label element directly like so:

label { }

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we don't need this we can likely remove the className that has been added in both label component files (modern & legacy)

Comment thread src/components/date/date.component.tsx Outdated
ref={wrapperRef}
role="presentation"
size={size}
size={fieldsetSize || size}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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>`

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

question: Instead of this styled component, could we potentially use the new RequiredFieldsIndicator? No problem if it is not viable

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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";

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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`;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nitpick: could make error || warning into a const above like hasError

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not too sure if I think this is necessary since it wouldn't be reused anywhere else.

{children}
</FieldsetContext.Provider>
</StyledFieldsetContent>
{!validationMessagePositionTop && validationMessage()}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

praise: I like the way you've done this

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 Fieldset markup + styling to support size, legendHint, orientation, validation messaging, and labelWeight.
  • Introduces FieldsetContext and updates multiple inputs (Textbox/Textarea/TextEditor/Date/Checkbox + internal CheckableInput) to consume Fieldset-provided required, 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.

Comment thread src/components/fieldset/fieldset.pw.tsx Outdated
Comment on lines +54 to +58
test(`should pass accessibility tests with warning validation`, async ({
mount,
page,
}) => {
await mount(<FieldsetComponent error="error message" />);
Comment thread src/components/textarea/textarea.component.tsx Outdated

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'", () => {
Comment on lines 96 to 115
{(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>
)}
@mihai-albu-sage mihai-albu-sage self-requested a review May 26, 2026 18:02
tomdavies73
tomdavies73 previously approved these changes May 28, 2026
@nuria1110 nuria1110 marked this pull request as ready for review May 28, 2026 09:50
@nuria1110 nuria1110 requested review from a team as code owners May 28, 2026 09:50
@designerlisa

Copy link
Copy Markdown

@nuria1110 Great work overall, looking good! 👍

A few small things to flag:

  1. the label-to-input gap inside Fieldset (green color gap) looks like it's currently inheriting from TextInput's gap, but per the Figma spec it should use a fixed 4px across all sizes.
image
  1. Also, per the Figma spec, the error/warning message should sit below the input box.

@nuria1110 nuria1110 marked this pull request as draft June 2, 2026 13:25
@nuria1110 nuria1110 dismissed stale reviews from mihai-albu-sage and tomdavies73 via be61c6e June 2, 2026 13:25
@nuria1110 nuria1110 marked this pull request as ready for review June 2, 2026 13:34
@designerlisa

Copy link
Copy Markdown

@nuria1110 Thanks for the fixing, looking good! Gap confirmed fixed ✅

@nuria1110 nuria1110 merged commit aead984 into master Jun 8, 2026
29 checks passed
@nuria1110 nuria1110 deleted the fieldset-audit branch June 8, 2026 10:30
@carbonci

carbonci commented Jun 8, 2026

Copy link
Copy Markdown
Collaborator

🎉 This PR is included in version 159.9.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Development

Successfully merging this pull request may close these issues.

8 participants