Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Support className prop in FormControl.Caption component #5726

Merged
merged 3 commits into from
Mar 5, 2025

Conversation

smockle
Copy link
Member

@smockle smockle commented Feb 28, 2025

What does this PR add?

This PR adds a className prop to FormControl.Caption. Related components—e.g. FormControl and FormControl.Label—already have a className prop.

Does FormControl.Caption need a className prop?

Yes! There are basically 3 options for styling FormControl.Caption:

  1. Option 1: Wrap FormControl.Caption in a <div>, and style the <div>. This option is a non-starter, because GitHub uses eslint(primer-react/direct-slot-children) to enforce that FormControl.Caption is a direct child of FormControl.

  2. Option 2: Style FormControl.Caption using sx. This option is a non-starter, because sx is deprecated.

  3. Option 3: Style FormControl.Caption using className. This option is not possible today, because FormControl.Caption is missing a className prop, but this is otherwise the best way to style FormControl.Caption, ergo this PR.

Why do you want to style FormControl.Caption anyways?

The image below gives an example of the kinds of styles that might be applied—in it, a FormControl.Label is positioned atop FormControl.Caption, and these (together) are displayed beside a control:

Screenshot of FormControl grid layout

With sx, that layout can be accomplished like this:

<FormControl sx={{display: 'grid', gap: '0 10px'}}>
    <FormControl.Label sx={{gridColumn: 1, gridRow: 1}}>Increase contrast</FormControl.Label>
    <FormControl.Caption sx={{gridColumn: 1, gridRow: 2}}>
        Enable high contrast for a single theme or for both light and dark mode
    </FormControl.Caption>
    <ActionMenu>
        <ActionMenu.Button sx={{gridColumn: 3, gridRow: '1 / span 2'}} />
        {/* … */}
    </ActionMenu>
</FormControl>

I’d like to accomplish the same layout, using className in place of sx. This PR makes that possible.

Changelog

New

  • Added className prop to FormControl.Caption component

Rollout strategy

  • Patch release
  • Minor release
  • Major release; if selected, include a written rollout or migration plan
  • None; if selected, include a brief description as to why

Testing & Reviewing

Do other components have className-related tests or previews?

Merge checklist

Sorry, something went wrong.

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
@smockle smockle requested a review from a team as a code owner February 28, 2025 20:42
@smockle smockle requested a review from jonrohan February 28, 2025 20:42
Copy link

changeset-bot bot commented Feb 28, 2025

🦋 Changeset detected

Latest commit: 0c0fbcd

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@primer/react Minor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@github-actions github-actions bot added staff Author is a staff member integration-tests: recommended This change needs to be tested for breaking changes. See https://arc.net/l/quote/tdmpakpm labels Feb 28, 2025
Copy link
Contributor

👋 Hi, this pull request contains changes to the source code that github/github depends on. If you are GitHub staff, we recommend testing these changes with github/github using the integration workflow. Thanks!

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
Copy link
Contributor

github-actions bot commented Feb 28, 2025

size-limit report 📦

Path Size
packages/react/dist/browser.esm.js 105.94 KB (+0.01% 🔺)
packages/react/dist/browser.umd.js 106.3 KB (-0.09% 🔽)

@github-actions github-actions bot requested a deployment to storybook-preview-5726 February 28, 2025 20:51 Abandoned
@github-actions github-actions bot temporarily deployed to storybook-preview-5726 February 28, 2025 21:04 Inactive
Copy link
Member

@joshblack joshblack left a comment

Choose a reason for hiding this comment

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

Looks great! Just left a comment for the changeset, I think this would fall under minor for us since this is adding functionality.

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
Co-authored-by: Josh Black <joshblack@github.com>
@joshblack joshblack added this pull request to the merge queue Mar 5, 2025
Merged via the queue into main with commit 2646c12 Mar 5, 2025
44 checks passed
@joshblack joshblack deleted the smockle/FormControlCaption-className-prop branch March 5, 2025 18:57
@primer primer bot mentioned this pull request Mar 5, 2025
hectahertz pushed a commit that referenced this pull request Mar 20, 2025

Unverified

This commit is not signed, but one or more authors requires that any commit attributed to them is signed.
)

Co-authored-by: Josh Black <joshblack@github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
integration-tests: recommended This change needs to be tested for breaking changes. See https://arc.net/l/quote/tdmpakpm staff Author is a staff member
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants