-
Notifications
You must be signed in to change notification settings - Fork 535
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use SSR-compatible slot implementation in FormControl (#3149)
* Update slots in FormControl * Rename rest variable * Remove old slots * Fix tests * Create .changeset/cool-ghosts-remember.md
- Loading branch information
Showing
7 changed files
with
168 additions
and
178 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
--- | ||
"@primer/react": patch | ||
--- | ||
|
||
`FormControl` is now SSR-compatible. | ||
|
||
Warning: In this new implementation, `FormControl.Caption`, `FormControl.Label`, `FormControl.LeadingVisual`, and `FormControl.Validation` must be direct children of `FormControl`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,15 @@ | ||
import React from 'react' | ||
import {SxProp} from '../sx' | ||
import InputCaption from '../_InputCaption' | ||
import {SxProp} from '../sx' | ||
import {FormControlContext} from './FormControl' | ||
import {Slot} from './slots' | ||
|
||
const FormControlCaption: React.FC<React.PropsWithChildren<{id?: string} & SxProp>> = ({children, sx, id}) => ( | ||
<Slot name="Caption"> | ||
{({captionId, disabled}: FormControlContext) => ( | ||
<InputCaption id={id || captionId} disabled={disabled} sx={sx}> | ||
{children} | ||
</InputCaption> | ||
)} | ||
</Slot> | ||
) | ||
const FormControlCaption: React.FC<React.PropsWithChildren<{id?: string} & SxProp>> = ({children, sx, id}) => { | ||
const {captionId, disabled} = React.useContext(FormControlContext) | ||
return ( | ||
<InputCaption id={id || captionId || ''} disabled={disabled} sx={sx}> | ||
{children} | ||
</InputCaption> | ||
) | ||
} | ||
|
||
export default FormControlCaption |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.