shoelace/docs/components/radio-group.md

66 wiersze
1.6 KiB
Markdown
Czysty Zwykły widok Historia

2021-04-09 12:15:33 +00:00
# Radio Group
[component-header:sl-radio-group]
Radio Groups are used to group multiple radios so they function as a single control.
```html preview
2022-03-14 13:05:26 +00:00
<sl-radio-group label="Select an option">
<sl-radio name="option" value="1" checked>Option 1</sl-radio>
<sl-radio name="option" value="2">Option 2</sl-radio>
<sl-radio name="option" value="3">Option 3</sl-radio>
</sl-radio-group>
2021-04-09 12:15:33 +00:00
```
2021-11-04 22:12:47 +00:00
```jsx react
import { SlRadio, SlRadioGroup } from '@shoelace-style/shoelace/dist/react';
const App = () => (
<SlRadioGroup label="Select an option">
2022-03-11 16:40:34 +00:00
<SlRadio name="option" value="1" checked>
2022-03-02 15:10:41 +00:00
Option 1
</SlRadio>
2022-03-11 16:40:34 +00:00
<SlRadio name="option" value="2">
Option 2
</SlRadio>
<SlRadio name="option" value="3">
Option 3
</SlRadio>
2021-11-04 22:12:47 +00:00
</SlRadioGroup>
);
```
2021-04-09 12:15:33 +00:00
## Examples
2021-08-27 13:00:01 +00:00
### Showing the Fieldset
2021-04-09 12:15:33 +00:00
2021-08-27 13:00:01 +00:00
You can show a fieldset and legend that wraps the radio group using the `fieldset` attribute.
2021-04-09 12:15:33 +00:00
```html preview
2021-11-04 22:12:47 +00:00
<sl-radio-group label="Select an option" fieldset>
2022-03-11 16:40:34 +00:00
<sl-radio name="option" value="1" checked>Option 1</sl-radio>
<sl-radio name="option" value="2">Option 2</sl-radio>
<sl-radio name="option" value="3">Option 3</sl-radio>
2021-04-09 12:15:33 +00:00
</sl-radio-group>
```
2021-11-04 22:12:47 +00:00
```jsx react
import { SlRadio, SlRadioGroup } from '@shoelace-style/shoelace/dist/react';
const App = () => (
<SlRadioGroup label="Select an option" fieldset>
2022-03-11 16:40:34 +00:00
<SlRadio name="option" value="1" checked>
2022-03-02 15:10:41 +00:00
Option 1
</SlRadio>
2022-03-11 16:40:34 +00:00
<SlRadio name="option" value="2">
Option 2
</SlRadio>
<SlRadio name="option" value="3">
Option 3
</SlRadio>
2021-11-04 22:12:47 +00:00
</SlRadioGroup>
);
```
2022-03-02 15:10:41 +00:00
2021-04-09 12:15:33 +00:00
[component-metadata:sl-radio-group]