Radio components are used to select one of multiple options. Because they have no useful purpose on their own, they are only intended to be used within a RadioGroup wrapper component.
As mentioned above, a single radio button isn’t very useful – but here’s one anyway. The default color is --ui-focus.
<script>
import { Radio } from '$lib/ui';
</script>
<Radio label="Your only option" /> Not normally used because the RadioGroup value prop will set which Radio is checked (and overrides this property).
<Radio label="Your choice is made" checked /> A label prop let’s you define a string to be used as the radio label.
<Radio label="Choose wisely" /> Labels normally appear to the right of the radio. Use the leadingLabel prop instead to place it on the left.
<Radio leadingLabel="No going back" /> Default is true but can also be assigned a Boolean value like disabled={user.isSignedIn}.
<Radio label="Not an option" disabled /> This is the value that will be assigned to the RadioGroup’s value value when checked.
<Radio label="Spam me" value="spamMe" /> Since the label prop can only be a String, you can use the label slot instead to pass in a more complex label.
<Radio>
<span slot="label">
<PizzaIcon /> Pizza
</span>
</Radio> Use the leadingLabel slot to pass in a more complex leading label that precedes the radio.
<Radio>
<span slot="leadingLabel">
<PizzaIcon /> Pizza
</span>
</Radio> | Name | Type | Default | Description |
|---|---|---|---|
label | String | Text label appears trailing the radio | |
leadingLabel | String | Text label appears leading the radio | |
checked | Boolean | false | Normally used with bind:checked directive. Not needed within a RadioGroup |
disabled | Boolean | false | |
class | String | CSS classes declared in global scope can be applied to the outermost element | |
... | Additional props will be passed through to the HTML element enabling support for things
like on:click, etc |
| Name | Type | Default | Description |
|---|---|---|---|
--ui-radio-small-font-size | Numeric | --ui-small-font-size, 0.875rem | Font size for radio label |
--ui-radio-gap | Numeric | 0.5rem | Font size for radio label |
--ui-radio-border-width | Numeric | --ui-border-width, 1px | Border width |
--ui-radio-border-color | Color | --ui-border-color, --ui-midtone, #94a3b8 | Border color |
--ui-radio-background | Color | --ui-focus, #3b82f6 | Background color of checked radio |
| Name | Description |
|---|---|
label | Content to be used for label after radio (supercedes label property) |
labelLeading | Content to be used for label preceding radio (supercedes leadingLabel property) |