Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/tall-wasps-end.md
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
---
'@primer/react': minor
---

Adds new `className` prop to `FormControl` component
12 changes: 10 additions & 2 deletions packages/react/src/FormControl/FormControl.tsx
Original file line numberDiff line numberDiff line change
Expand Up@@ -38,10 +38,11 @@ export type FormControlProps = {
* Vertical layout is used by default, and horizontal layout is used for checkbox and radio inputs.
*/
layout?: 'horizontal' | 'vertical'
className?: string
} & SxProp

const FormControl = React.forwardRef<HTMLDivElement, FormControlProps>(
({children, disabled: disabledProp, layout = 'vertical', id: idProp, required, sx}, ref) => {
({children, disabled: disabledProp, layout = 'vertical', id: idProp, required, sx, className}, ref) => {
const [slots, childrenWithoutSlots] = useSlots(children, {
caption: FormControlCaption,
label: FormControlLabel,
Expand DownExpand Up@@ -124,7 +125,13 @@ const FormControl = React.forwardRef<HTMLDivElement, FormControlProps>(
}}
>
{isChoiceInput || layout === 'horizontal' ? (
<Box ref={ref} display="flex" alignItems={slots.leadingVisual ? 'center' : undefined} sx={sx}>
<Box
ref={ref}
display="flex"
alignItems={slots.leadingVisual ? 'center' : undefined}
sx={sx}
className={className}
>
<Box sx={{'> input': {marginLeft: 0, marginRight: 0}}}>
{React.isValidElement(InputComponent) &&
React.cloneElement(
Expand DownExpand Up@@ -179,6 +186,7 @@ const FormControl = React.forwardRef<HTMLDivElement, FormControlProps>(
flexDirection="column"
alignItems="flex-start"
sx={{...(isLabelHidden ? {'> *:not(label) + *': {marginTop: 1}} : {'> * + *': {marginTop: 1}}), ...sx}}
className={className}
>
{slots.label}
{React.isValidElement(InputComponent) &&
Expand Down