-
Notifications
You must be signed in to change notification settings - Fork 80
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
docs: README for RadioButtonField component (#844)
- Loading branch information
1 parent
affba8b
commit bebd00d
Showing
3 changed files
with
74 additions
and
18 deletions.
There are no files selected for viewing
2 changes: 1 addition & 1 deletion
2
packages/forma-36-react-components/src/components/CheckboxField/README.mdx
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
71 changes: 71 additions & 0 deletions
71
packages/forma-36-react-components/src/components/RadioButtonField/README.mdx
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,71 @@ | ||
Use RadioButtonField to give users the possibility to select only one option from a number of choices. It contains a radio input with its label. If needed the component can display an error message and hint message. For a multiple-choice, please consider using [ChecboxField component](https://f36.contentful.com/components/checkbox-field/). | ||
|
||
## Table of contents | ||
|
||
- [How to use RadioButtonField](#how-to-use-radioButtonField) | ||
- [Code examples](#component-variations) | ||
- [Content recommendations](#content-recommendations) | ||
- [Accessibility](#accessibility) | ||
|
||
## How to use RadioButtonField | ||
|
||
- RadioButtonField should be used in a group. Please include at least two or more choices for users | ||
- Options provided for users should be mutually exclusive. | ||
- Make sure choices don’t overlap. Avoid patterns like: 1990-2000, 2000-2010. | ||
- Be explicit about the action that will follow if the radio button is selected | ||
|
||
## Code examples | ||
|
||
Basic usage | ||
|
||
```jsx | ||
// import {RadioButtonField} from '@contentful/forma-36-react-components'; | ||
|
||
<RadioButtonField labelText="Label text" id="randomId" /> | ||
``` | ||
|
||
Example with 2 options with helper text displayed | ||
|
||
```jsx | ||
// import {RadioButtonField} from '@contentful/forma-36-react-components'; | ||
|
||
function RadioButtonFieldExample() { | ||
const [activeOption, setActiveOption] = React.useState('yes'); | ||
|
||
return ( | ||
<Flex flexDirection="column"> | ||
<RadioButtonField | ||
name="radio option 1" | ||
id="randomId1" | ||
value="yes" | ||
checked={activeOption === 'yes'} | ||
onChange={(e) => { | ||
setActiveOption(e.target.value); | ||
}} | ||
labelText="Radio button checked" | ||
helpText="Helper text displayed below" | ||
/> | ||
<RadioButtonField | ||
name="radio option 2" | ||
id="randomId2" | ||
value="no" | ||
checked={activeOption === 'no'} | ||
onChange={(e) => { | ||
setActiveOption(e.target.value); | ||
}} | ||
labelText="Second option" | ||
helpText="Helper text displayed below" | ||
/> | ||
</Flex> | ||
); | ||
} | ||
``` | ||
|
||
## Content recommendations | ||
|
||
- Labels should be concise and provide context. | ||
- Use sentence-style capitalization (only the first word in a phrase and any proper nouns capitalized) | ||
|
||
## Accessibility | ||
|
||
- Radio buttons should have a clear and concise label. |
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