Radio Group
Group of native radios inside a fieldset and legend for picking one of several options.
<div class="grid gap-6">
<x-markas.radio-group
name="plan"
label="Subscription plan"
value="pro"
:options="[
['value' => 'free', 'label' => 'Free', 'description' => 'For personal projects.'],
['value' => 'pro', 'label' => 'Pro', 'description' => 'For small teams of up to 10 people.'],
['value' => 'business', 'label' => 'Business', 'description' => 'For organizations with custom needs.'],
]"
/>
<x-markas.radio-group
name="billing"
label="Billing cycle"
value="monthly"
orientation="horizontal"
:options="[
['value' => 'monthly', 'label' => 'Monthly'],
['value' => 'yearly', 'label' => 'Yearly'],
]"
/>
</div>import { RadioGroup } from "@/components/markas/RadioGroup";
const plan = [
{ value: "free", label: "Free", description: "For personal projects." },
{
value: "pro",
label: "Pro",
description: "For small teams of up to 10 people.",
},
{
value: "business",
label: "Business",
description: "For organizations with custom needs.",
},
];
const billing = [
{ value: "monthly", label: "Monthly" },
{ value: "yearly", label: "Yearly" },
];
export default function RadioGroupExample() {
return (
<div className="grid gap-6">
<RadioGroup
name="plan"
label="Subscription plan"
defaultValue="pro"
options={plan}
/>
<RadioGroup
name="billing"
label="Billing cycle"
defaultValue="monthly"
orientation="horizontal"
options={billing}
/>
</div>
);
}<script setup lang="ts">
import { ref } from "vue";
import RadioGroup from "@/components/markas/RadioGroup.vue";
const planOptions = [
{ value: "free", label: "Free", description: "For personal projects." },
{
value: "pro",
label: "Pro",
description: "For small teams of up to 10 people.",
},
{
value: "business",
label: "Business",
description: "For organizations with custom needs.",
},
];
const billingOptions = [
{ value: "monthly", label: "Monthly" },
{ value: "yearly", label: "Yearly" },
];
const plan = ref("pro");
const billing = ref("monthly");
</script>
<template>
<div class="grid gap-6">
<RadioGroup
v-model="plan"
name="plan"
label="Subscription plan"
:options="planOptions"
/>
<RadioGroup
v-model="billing"
name="billing"
label="Billing cycle"
orientation="horizontal"
:options="billingOptions"
/>
</div>
</template><script lang="ts">
import RadioGroup from "$lib/components/markas/RadioGroup.svelte";
const plan = [
{
value: "free",
label: "Free",
description: "For personal projects.",
},
{
value: "pro",
label: "Pro",
description: "For small teams of up to 10 people.",
},
{
value: "business",
label: "Business",
description: "For organizations with custom needs.",
},
];
const billing = [
{
value: "monthly",
label: "Monthly",
},
{
value: "yearly",
label: "Yearly",
},
];
</script>
<div class="grid gap-6">
<RadioGroup
name="plan"
label="Subscription plan"
value="pro"
options={plan}
/>
<RadioGroup
name="billing"
label="Billing cycle"
value="monthly"
orientation="horizontal"
options={billing}
/>
</div>---
import RadioGroup from "@/components/markas/RadioGroup.astro";
const plan = [
{
value: "free",
label: "Free",
description: "For personal projects."
},
{
value: "pro",
label: "Pro",
description: "For small teams of up to 10 people."
},
{
value: "business",
label: "Business",
description: "For organizations with custom needs."
}
];
const billing = [
{
value: "monthly",
label: "Monthly"
},
{
value: "yearly",
label: "Yearly"
}
];
---
<div class="grid gap-6">
<RadioGroup
name="plan"
label="Subscription plan"
value="pro"
options={plan}
/>
<RadioGroup
name="billing"
label="Billing cycle"
value="monthly"
orientation="horizontal"
options={billing}
/>
</div>import { Component } from "@angular/core";
import { RadioGroup } from "./markas/radio-group.component";
@Component({
selector: "markas-example",
imports: [RadioGroup],
template: `
<div class="grid gap-6">
<markas-radio-group
name="plan"
label="Subscription plan"
value="pro"
[options]="plan"
/>
<markas-radio-group
name="billing"
label="Billing cycle"
value="monthly"
orientation="horizontal"
[options]="billing"
/>
</div>
`,
})
export default class RadioGroupFixture {
protected readonly plan = [
{
value: "free",
label: "Free",
description: "For personal projects.",
},
{
value: "pro",
label: "Pro",
description: "For small teams of up to 10 people.",
},
{
value: "business",
label: "Business",
description: "For organizations with custom needs.",
},
];
protected readonly billing = [
{
value: "monthly",
label: "Monthly",
},
{
value: "yearly",
label: "Yearly",
},
];
}Examples
Horizontal
<div class="grid gap-6">
<x-markas.radio-group
name="theme"
label="Theme"
value="system"
orientation="horizontal"
:options="[
['value' => 'light', 'label' => 'Light'],
['value' => 'dark', 'label' => 'Dark'],
['value' => 'system', 'label' => 'System'],
]"
/>
<x-markas.radio-group
name="size"
label="Size"
value="m"
orientation="horizontal"
:options="[
['value' => 's', 'label' => 'Small'],
['value' => 'm', 'label' => 'Medium'],
['value' => 'l', 'label' => 'Large'],
['value' => 'xl', 'label' => 'Extra large'],
]"
/>
</div>import { RadioGroup } from "@/components/markas/RadioGroup";
const themes = [
{ value: "light", label: "Light" },
{ value: "dark", label: "Dark" },
{ value: "system", label: "System" },
];
const sizes = [
{ value: "s", label: "Small" },
{ value: "m", label: "Medium" },
{ value: "l", label: "Large" },
{ value: "xl", label: "Extra large" },
];
export default function Example() {
return (
<div className="grid gap-6">
<RadioGroup
name="theme"
label="Theme"
defaultValue="system"
orientation="horizontal"
options={themes}
/>
<RadioGroup
name="size"
label="Size"
defaultValue="m"
orientation="horizontal"
options={sizes}
/>
</div>
);
}<script setup lang="ts">
import { ref } from "vue";
import RadioGroup from "@/components/markas/RadioGroup.vue";
const themes = [
{ value: "light", label: "Light" },
{ value: "dark", label: "Dark" },
{ value: "system", label: "System" },
];
const sizes = [
{ value: "s", label: "Small" },
{ value: "m", label: "Medium" },
{ value: "l", label: "Large" },
{ value: "xl", label: "Extra large" },
];
const theme = ref("system");
const size = ref("m");
</script>
<template>
<div class="grid gap-6">
<RadioGroup
v-model="theme"
name="theme"
label="Theme"
orientation="horizontal"
:options="themes"
/>
<RadioGroup
v-model="size"
name="size"
label="Size"
orientation="horizontal"
:options="sizes"
/>
</div>
</template><script lang="ts">
import RadioGroup from "$lib/components/markas/RadioGroup.svelte";
const themes = [
{
value: "light",
label: "Light",
},
{
value: "dark",
label: "Dark",
},
{
value: "system",
label: "System",
},
];
const sizes = [
{
value: "s",
label: "Small",
},
{
value: "m",
label: "Medium",
},
{
value: "l",
label: "Large",
},
{
value: "xl",
label: "Extra large",
},
];
</script>
<div class="grid gap-6">
<RadioGroup
name="theme"
label="Theme"
value="system"
orientation="horizontal"
options={themes}
/>
<RadioGroup
name="size"
label="Size"
value="m"
orientation="horizontal"
options={sizes}
/>
</div>---
import RadioGroup from "@/components/markas/RadioGroup.astro";
const themes = [
{
value: "light",
label: "Light"
},
{
value: "dark",
label: "Dark"
},
{
value: "system",
label: "System"
}
];
const sizes = [
{
value: "s",
label: "Small"
},
{
value: "m",
label: "Medium"
},
{
value: "l",
label: "Large"
},
{
value: "xl",
label: "Extra large"
}
];
---
<div class="grid gap-6">
<RadioGroup
name="theme"
label="Theme"
value="system"
orientation="horizontal"
options={themes}
/>
<RadioGroup
name="size"
label="Size"
value="m"
orientation="horizontal"
options={sizes}
/>
</div>import { Component } from "@angular/core";
import { RadioGroup } from "./markas/radio-group.component";
@Component({
selector: "markas-example",
imports: [RadioGroup],
template: `
<div class="grid gap-6">
<markas-radio-group
name="theme"
label="Theme"
value="system"
orientation="horizontal"
[options]="themes"
/>
<markas-radio-group
name="size"
label="Size"
value="m"
orientation="horizontal"
[options]="sizes"
/>
</div>
`,
})
export default class RadioGroupHorizontalExample {
protected readonly themes = [
{
value: "light",
label: "Light",
},
{
value: "dark",
label: "Dark",
},
{
value: "system",
label: "System",
},
];
protected readonly sizes = [
{
value: "s",
label: "Small",
},
{
value: "m",
label: "Medium",
},
{
value: "l",
label: "Large",
},
{
value: "xl",
label: "Extra large",
},
];
}With descriptions
<x-markas.radio-group
name="shipping"
label="Shipping method"
value="express"
:options="[
['value' => 'standard', 'label' => 'Standard', 'description' => 'Arrives in 4 to 6 business days. Free.'],
['value' => 'express', 'label' => 'Express', 'description' => 'Arrives in 1 to 2 business days. $12.'],
['value' => 'pickup', 'label' => 'Store pickup', 'description' => 'Ready for pickup tomorrow at 10:00.'],
]"
/>import { RadioGroup } from "@/components/markas/RadioGroup";
const shipping = [
{
value: "standard",
label: "Standard",
description: "Arrives in 4 to 6 business days. Free.",
},
{
value: "express",
label: "Express",
description: "Arrives in 1 to 2 business days. $12.",
},
{
value: "pickup",
label: "Store pickup",
description: "Ready for pickup tomorrow at 10:00.",
},
];
export default function Example() {
return (
<RadioGroup
name="shipping"
label="Shipping method"
defaultValue="express"
options={shipping}
/>
);
}<script setup lang="ts">
import { ref } from "vue";
import RadioGroup from "@/components/markas/RadioGroup.vue";
const options = [
{
value: "standard",
label: "Standard",
description: "Arrives in 4 to 6 business days. Free.",
},
{
value: "express",
label: "Express",
description: "Arrives in 1 to 2 business days. $12.",
},
{
value: "pickup",
label: "Store pickup",
description: "Ready for pickup tomorrow at 10:00.",
},
];
const shipping = ref("express");
</script>
<template>
<RadioGroup
v-model="shipping"
name="shipping"
label="Shipping method"
:options="options"
/>
</template><script lang="ts">
import RadioGroup from "$lib/components/markas/RadioGroup.svelte";
const shipping = [
{
value: "standard",
label: "Standard",
description: "Arrives in 4 to 6 business days. Free.",
},
{
value: "express",
label: "Express",
description: "Arrives in 1 to 2 business days. $12.",
},
{
value: "pickup",
label: "Store pickup",
description: "Ready for pickup tomorrow at 10:00.",
},
];
</script>
<RadioGroup
name="shipping"
label="Shipping method"
value="express"
options={shipping}
/>---
import RadioGroup from "@/components/markas/RadioGroup.astro";
const shipping = [
{
value: "standard",
label: "Standard",
description: "Arrives in 4 to 6 business days. Free."
},
{
value: "express",
label: "Express",
description: "Arrives in 1 to 2 business days. $12."
},
{
value: "pickup",
label: "Store pickup",
description: "Ready for pickup tomorrow at 10:00."
}
];
---
<RadioGroup
name="shipping"
label="Shipping method"
value="express"
options={shipping}
/>import { Component } from "@angular/core";
import { RadioGroup } from "./markas/radio-group.component";
@Component({
selector: "markas-example",
imports: [RadioGroup],
template: `
<markas-radio-group
name="shipping"
label="Shipping method"
value="express"
[options]="shipping"
/>
`,
})
export default class RadioGroupDescriptionsExample {
protected readonly shipping = [
{
value: "standard",
label: "Standard",
description: "Arrives in 4 to 6 business days. Free.",
},
{
value: "express",
label: "Express",
description: "Arrives in 1 to 2 business days. $12.",
},
{
value: "pickup",
label: "Store pickup",
description: "Ready for pickup tomorrow at 10:00.",
},
];
}Cards
<x-markas.radio-group
name="plan"
label="Plan"
value="team"
class="*:*:rounded-lg *:*:border *:*:border-line *:*:bg-surface *:*:p-4 *:*:transition-colors *:*:duration-150 *:*:ease-out *:*:has-checked:border-primary *:*:has-checked:bg-primary-soft *:*:motion-reduce:transition-none"
:options="[
['value' => 'starter', 'label' => 'Starter', 'description' => '1 project and 2 GB storage. Free forever.'],
['value' => 'team', 'label' => 'Team', 'description' => 'Unlimited projects and 100 GB storage. $29 per month.'],
['value' => 'enterprise', 'label' => 'Enterprise', 'description' => 'SSO, audit logs, and a dedicated manager.'],
]"
/>import { RadioGroup } from "@/components/markas/RadioGroup";
const cards =
"*:*:rounded-lg *:*:border *:*:border-line *:*:bg-surface *:*:p-4 *:*:transition-colors *:*:duration-150 *:*:ease-out *:*:has-checked:border-primary *:*:has-checked:bg-primary-soft *:*:motion-reduce:transition-none";
const plans = [
{
value: "starter",
label: "Starter",
description: "1 project and 2 GB storage. Free forever.",
},
{
value: "team",
label: "Team",
description: "Unlimited projects and 100 GB storage. $29 per month.",
},
{
value: "enterprise",
label: "Enterprise",
description: "SSO, audit logs, and a dedicated manager.",
},
];
export default function Example() {
return (
<RadioGroup
name="plan"
label="Plan"
defaultValue="team"
className={cards}
options={plans}
/>
);
}<script setup lang="ts">
import { ref } from "vue";
import RadioGroup from "@/components/markas/RadioGroup.vue";
const cards =
"*:*:rounded-lg *:*:border *:*:border-line *:*:bg-surface *:*:p-4 *:*:transition-colors *:*:duration-150 *:*:ease-out *:*:has-checked:border-primary *:*:has-checked:bg-primary-soft *:*:motion-reduce:transition-none";
const plans = [
{
value: "starter",
label: "Starter",
description: "1 project and 2 GB storage. Free forever.",
},
{
value: "team",
label: "Team",
description: "Unlimited projects and 100 GB storage. $29 per month.",
},
{
value: "enterprise",
label: "Enterprise",
description: "SSO, audit logs, and a dedicated manager.",
},
];
const plan = ref("team");
</script>
<template>
<RadioGroup
v-model="plan"
name="plan"
label="Plan"
:class="cards"
:options="plans"
/>
</template><script lang="ts">
import RadioGroup from "$lib/components/markas/RadioGroup.svelte";
const cards =
"*:*:rounded-lg *:*:border *:*:border-line *:*:bg-surface *:*:p-4 *:*:transition-colors *:*:duration-150 *:*:ease-out *:*:has-checked:border-primary *:*:has-checked:bg-primary-soft *:*:motion-reduce:transition-none";
const plans = [
{
value: "starter",
label: "Starter",
description: "1 project and 2 GB storage. Free forever.",
},
{
value: "team",
label: "Team",
description: "Unlimited projects and 100 GB storage. $29 per month.",
},
{
value: "enterprise",
label: "Enterprise",
description: "SSO, audit logs, and a dedicated manager.",
},
];
</script>
<RadioGroup
name="plan"
label="Plan"
value="team"
class={cards}
options={plans}
/>---
import RadioGroup from "@/components/markas/RadioGroup.astro";
const cards = "*:*:rounded-lg *:*:border *:*:border-line *:*:bg-surface *:*:p-4 *:*:transition-colors *:*:duration-150 *:*:ease-out *:*:has-checked:border-primary *:*:has-checked:bg-primary-soft *:*:motion-reduce:transition-none";
const plans = [
{
value: "starter",
label: "Starter",
description: "1 project and 2 GB storage. Free forever."
},
{
value: "team",
label: "Team",
description: "Unlimited projects and 100 GB storage. $29 per month."
},
{
value: "enterprise",
label: "Enterprise",
description: "SSO, audit logs, and a dedicated manager."
}
];
---
<RadioGroup
name="plan"
label="Plan"
value="team"
class={cards}
options={plans}
/>import { Component } from "@angular/core";
import { RadioGroup } from "./markas/radio-group.component";
@Component({
selector: "markas-example",
imports: [RadioGroup],
template: `
<markas-radio-group
name="plan"
label="Plan"
value="team"
[class]="cards"
[options]="plans"
/>
`,
})
export default class RadioGroupCardsExample {
protected readonly cards =
"*:*:rounded-lg *:*:border *:*:border-line *:*:bg-surface *:*:p-4 *:*:transition-colors *:*:duration-150 *:*:ease-out *:*:has-checked:border-primary *:*:has-checked:bg-primary-soft *:*:motion-reduce:transition-none";
protected readonly plans = [
{
value: "starter",
label: "Starter",
description: "1 project and 2 GB storage. Free forever.",
},
{
value: "team",
label: "Team",
description: "Unlimited projects and 100 GB storage. $29 per month.",
},
{
value: "enterprise",
label: "Enterprise",
description: "SSO, audit logs, and a dedicated manager.",
},
];
}Disabled
Verify your bank account to change the payout schedule.
Verify your bank account to change the payout schedule.
Verify your bank account to change the payout schedule.
Verify your bank account to change the payout schedule.
Verify your bank account to change the payout schedule.
<div class="grid gap-3">
<x-markas.radio-group
name="payout"
label="Payout schedule"
value="weekly"
disabled
:options="[
['value' => 'daily', 'label' => 'Daily'],
['value' => 'weekly', 'label' => 'Weekly'],
['value' => 'monthly', 'label' => 'Monthly'],
]"
/>
<p class="text-sm text-muted">Verify your bank account to change the payout schedule.</p>
</div>import { RadioGroup } from "@/components/markas/RadioGroup";
const schedules = [
{ value: "daily", label: "Daily" },
{ value: "weekly", label: "Weekly" },
{ value: "monthly", label: "Monthly" },
];
export default function Example() {
return (
<div className="grid gap-3">
<RadioGroup
name="payout"
label="Payout schedule"
defaultValue="weekly"
disabled
options={schedules}
/>
<p className="text-sm text-muted">
Verify your bank account to change the payout schedule.
</p>
</div>
);
}<script setup lang="ts">
import { ref } from "vue";
import RadioGroup from "@/components/markas/RadioGroup.vue";
const schedules = [
{ value: "daily", label: "Daily" },
{ value: "weekly", label: "Weekly" },
{ value: "monthly", label: "Monthly" },
];
const payout = ref("weekly");
</script>
<template>
<div class="grid gap-3">
<RadioGroup
v-model="payout"
name="payout"
label="Payout schedule"
disabled
:options="schedules"
/>
<p class="text-sm text-muted">
Verify your bank account to change the payout schedule.
</p>
</div>
</template><script lang="ts">
import RadioGroup from "$lib/components/markas/RadioGroup.svelte";
const schedules = [
{
value: "daily",
label: "Daily",
},
{
value: "weekly",
label: "Weekly",
},
{
value: "monthly",
label: "Monthly",
},
];
</script>
<div class="grid gap-3">
<RadioGroup
name="payout"
label="Payout schedule"
value="weekly"
disabled
options={schedules}
/>
<p class="text-sm text-muted">
Verify your bank account to change the payout schedule.
</p>
</div>---
import RadioGroup from "@/components/markas/RadioGroup.astro";
const schedules = [
{
value: "daily",
label: "Daily"
},
{
value: "weekly",
label: "Weekly"
},
{
value: "monthly",
label: "Monthly"
}
];
---
<div class="grid gap-3">
<RadioGroup
name="payout"
label="Payout schedule"
value="weekly"
disabled
options={schedules}
/>
<p class="text-sm text-muted">
Verify your bank account to change the payout schedule.
</p>
</div>import { Component } from "@angular/core";
import { RadioGroup } from "./markas/radio-group.component";
@Component({
selector: "markas-example",
imports: [RadioGroup],
template: `
<div class="grid gap-3">
<markas-radio-group
name="payout"
label="Payout schedule"
value="weekly"
disabled
[options]="schedules"
/>
<p class="text-sm text-muted">
Verify your bank account to change the payout schedule.
</p>
</div>
`,
})
export default class RadioGroupDisabledExample {
protected readonly schedules = [
{
value: "daily",
label: "Daily",
},
{
value: "weekly",
label: "Weekly",
},
{
value: "monthly",
label: "Monthly",
},
];
}In a card
<form class="grid gap-6 rounded-lg border border-line bg-surface p-6">
<div class="grid gap-1">
<p class="text-base font-semibold text-ink">Digest emails</p>
<p class="text-sm text-muted">A summary of activity in projects you follow.</p>
</div>
<x-markas.radio-group
name="digest"
label="Frequency"
value="weekly"
:options="[
['value' => 'daily', 'label' => 'Daily', 'description' => 'Every morning at 08:00.'],
['value' => 'weekly', 'label' => 'Weekly', 'description' => 'Every Monday morning.'],
['value' => 'never', 'label' => 'Never', 'description' => 'Only important account notices.'],
]"
/>
<div class="flex justify-end gap-2">
<x-markas.button variant="secondary">Cancel</x-markas.button>
<x-markas.button type="submit">Save</x-markas.button>
</div>
</form>import { Button } from "@/components/markas/Button";
import { RadioGroup } from "@/components/markas/RadioGroup";
const frequencies = [
{ value: "daily", label: "Daily", description: "Every morning at 08:00." },
{ value: "weekly", label: "Weekly", description: "Every Monday morning." },
{
value: "never",
label: "Never",
description: "Only important account notices.",
},
];
export default function Example() {
return (
<form className="grid gap-6 rounded-lg border border-line bg-surface p-6">
<div className="grid gap-1">
<p className="text-base font-semibold text-ink">Digest emails</p>
<p className="text-sm text-muted">
A summary of activity in projects you follow.
</p>
</div>
<RadioGroup
name="digest"
label="Frequency"
defaultValue="weekly"
options={frequencies}
/>
<div className="flex justify-end gap-2">
<Button variant="secondary">Cancel</Button>
<Button type="submit">Save</Button>
</div>
</form>
);
}<script setup lang="ts">
import { ref } from "vue";
import Button from "@/components/markas/Button.vue";
import RadioGroup from "@/components/markas/RadioGroup.vue";
const frequencies = [
{ value: "daily", label: "Daily", description: "Every morning at 08:00." },
{ value: "weekly", label: "Weekly", description: "Every Monday morning." },
{
value: "never",
label: "Never",
description: "Only important account notices.",
},
];
const digest = ref("weekly");
</script>
<template>
<form class="grid gap-6 rounded-lg border border-line bg-surface p-6">
<div class="grid gap-1">
<p class="text-base font-semibold text-ink">Digest emails</p>
<p class="text-sm text-muted">
A summary of activity in projects you follow.
</p>
</div>
<RadioGroup
v-model="digest"
name="digest"
label="Frequency"
:options="frequencies"
/>
<div class="flex justify-end gap-2">
<Button variant="secondary">Cancel</Button>
<Button type="submit">Save</Button>
</div>
</form>
</template><script lang="ts">
import Button from "$lib/components/markas/Button.svelte";
import RadioGroup from "$lib/components/markas/RadioGroup.svelte";
const frequencies = [
{
value: "daily",
label: "Daily",
description: "Every morning at 08:00.",
},
{
value: "weekly",
label: "Weekly",
description: "Every Monday morning.",
},
{
value: "never",
label: "Never",
description: "Only important account notices.",
},
];
</script>
<form class="grid gap-6 rounded-lg border border-line bg-surface p-6">
<div class="grid gap-1">
<p class="text-base font-semibold text-ink">Digest emails</p>
<p class="text-sm text-muted">
A summary of activity in projects you follow.
</p>
</div>
<RadioGroup
name="digest"
label="Frequency"
value="weekly"
options={frequencies}
/>
<div class="flex justify-end gap-2">
<Button variant="secondary">Cancel</Button>
<Button type="submit">Save</Button>
</div>
</form>---
import Button from "@/components/markas/Button.astro";
import RadioGroup from "@/components/markas/RadioGroup.astro";
const frequencies = [
{
value: "daily",
label: "Daily",
description: "Every morning at 08:00."
},
{
value: "weekly",
label: "Weekly",
description: "Every Monday morning."
},
{
value: "never",
label: "Never",
description: "Only important account notices."
}
];
---
<form class="grid gap-6 rounded-lg border border-line bg-surface p-6">
<div class="grid gap-1">
<p class="text-base font-semibold text-ink">Digest emails</p>
<p class="text-sm text-muted">
A summary of activity in projects you follow.
</p>
</div>
<RadioGroup
name="digest"
label="Frequency"
value="weekly"
options={frequencies}
/>
<div class="flex justify-end gap-2">
<Button variant="secondary">Cancel</Button>
<Button type="submit">Save</Button>
</div>
</form>import { Component } from "@angular/core";
import { Button } from "./markas/button.component";
import { RadioGroup } from "./markas/radio-group.component";
@Component({
selector: "markas-example",
imports: [Button, RadioGroup],
template: `
<form class="grid gap-6 rounded-lg border border-line bg-surface p-6">
<div class="grid gap-1">
<p class="text-base font-semibold text-ink">Digest emails</p>
<p class="text-sm text-muted">
A summary of activity in projects you follow.
</p>
</div>
<markas-radio-group
name="digest"
label="Frequency"
value="weekly"
[options]="frequencies"
/>
<div class="flex justify-end gap-2">
<button markas-button variant="secondary">Cancel</button>
<button markas-button type="submit">Save</button>
</div>
</form>
`,
})
export default class RadioGroupInCardExample {
protected readonly frequencies = [
{
value: "daily",
label: "Daily",
description: "Every morning at 08:00.",
},
{
value: "weekly",
label: "Weekly",
description: "Every Monday morning.",
},
{
value: "never",
label: "Never",
description: "Only important account notices.",
},
];
}Installation
npx markasui@latest add radio-grouppnpm dlx markasui@latest add radio-groupyarn dlx markasui@latest add radio-groupbunx --bun markasui@latest add radio-group- Make sure Tailwind CSS v4 and markas.css are installed. See Installation.
- Copy the component source below to
resources/views/components/markas/radio-group.blade.php.
resources/views/components/markas/radio-group.blade.php
@props([
'name',
'label' => null,
'options' => [],
'value' => null,
'orientation' => 'vertical',
])
@php
$root = 'min-w-0';
$legendClass = 'mb-3 text-sm font-medium text-ink';
$orientations = [
'vertical' => 'grid gap-3',
'horizontal' => 'flex flex-wrap gap-x-6 gap-y-3',
];
$item = 'flex items-start gap-3 has-disabled:cursor-not-allowed has-disabled:opacity-50';
$control = 'relative mt-0.5 flex size-4 shrink-0';
$radio = 'peer size-4 shrink-0 cursor-pointer appearance-none rounded-full border border-faint bg-surface transition-colors duration-150 ease-out checked:border-primary checked:bg-primary focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-primary disabled:cursor-not-allowed motion-reduce:transition-none';
$dot = 'pointer-events-none absolute inset-1 rounded-full bg-on-primary opacity-0 peer-checked:opacity-100';
$text = 'grid gap-0.5';
$labelClass = 'text-sm font-medium text-ink';
$descriptionClass = 'text-sm text-muted';
// Same id on every render, so Livewire's morph (which matches elements by id) keeps the element. Pass `id` to set it.
$idKey = 'markas-radio-group|'.(isset($this) && $this instanceof \Livewire\Component ? $this->getId() : '').'|'.($attributes->get('wire:key') ?? $attributes->whereStartsWith('wire:model')->first() ?? $name).'|';
for ($idIndex = 0; $__env->hasRenderedOnce($idKey.$idIndex); $idIndex++);
$__env->markAsRenderedOnce($idKey.$idIndex);
$id = $attributes->get('id') ?? 'markas-radio-group-'.hash('xxh32', $idKey.$idIndex);
// wire:model and x-model go on every radio, the rest on the fieldset.
$model = $attributes->whereStartsWith(['wire:model', 'x-model']);
@endphp
<fieldset {{ $attributes->whereDoesntStartWith(['wire:model', 'x-model'])->merge(['id' => $id])->class([$root]) }}>
@if ($label)
<legend class="{{ $legendClass }}">{{ $label }}</legend>
@endif
<div class="{{ $orientations[$orientation] }}">
@foreach ($options as $option)
@php
$optionId = $id.'-'.$option['value'];
$description = $option['description'] ?? null;
@endphp
<div class="{{ $item }}">
<span class="{{ $control }}">
<input
type="radio"
id="{{ $optionId }}"
name="{{ $name }}"
value="{{ $option['value'] }}"
@checked((string) $option['value'] === (string) $value)
@if ($description) aria-describedby="{{ $optionId }}-description" @endif
class="{{ $radio }}"
{{ $model }}
/>
<span class="{{ $dot }}" aria-hidden="true"></span>
</span>
<div class="{{ $text }}">
<label for="{{ $optionId }}" class="{{ $labelClass }}">{{ $option['label'] }}</label>
@if ($description)
<p id="{{ $optionId }}-description" class="{{ $descriptionClass }}">{{ $description }}</p>
@endif
</div>
</div>
@endforeach
</div>
</fieldset>- Make sure Tailwind CSS v4 and markas.css are installed. See Installation.
- Copy the component source below to
src/components/markas/RadioGroup.tsx.
src/components/markas/RadioGroup.tsx
"use client";
import { useId, type ComponentProps, type ReactNode } from "react";
const root = "min-w-0";
const legendClass = "mb-3 text-sm font-medium text-ink";
const orientations = {
vertical: "grid gap-3",
horizontal: "flex flex-wrap gap-x-6 gap-y-3",
};
const item =
"flex items-start gap-3 has-disabled:cursor-not-allowed has-disabled:opacity-50";
const control = "relative mt-0.5 flex size-4 shrink-0";
const radio =
"peer size-4 shrink-0 cursor-pointer appearance-none rounded-full border border-faint bg-surface transition-colors duration-150 ease-out checked:border-primary checked:bg-primary focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-primary disabled:cursor-not-allowed motion-reduce:transition-none";
const dot =
"pointer-events-none absolute inset-1 rounded-full bg-on-primary opacity-0 peer-checked:opacity-100";
const text = "grid gap-0.5";
const labelClass = "text-sm font-medium text-ink";
const descriptionClass = "text-sm text-muted";
const cx = (...c: (string | false | null | undefined)[]) =>
c.filter(Boolean).join(" ");
export type RadioOption = {
value: string;
label: ReactNode;
description?: ReactNode;
};
export type RadioGroupProps = Omit<
ComponentProps<"fieldset">,
"defaultValue"
> & {
name: string;
options: RadioOption[];
label?: ReactNode;
value?: string;
defaultValue?: string;
orientation?: keyof typeof orientations;
onValueChange?: (value: string) => void;
};
export function RadioGroup({
name,
options,
label,
value,
defaultValue,
orientation = "vertical",
onValueChange,
id,
className,
...props
}: RadioGroupProps) {
const generatedId = useId();
const groupId = id ?? generatedId;
const controlled = value !== undefined;
return (
<fieldset id={groupId} className={cx(root, className)} {...props}>
{label && <legend className={legendClass}>{label}</legend>}
<div className={orientations[orientation]}>
{options.map((option) => {
const optionId = `${groupId}-${option.value}`;
return (
<div key={option.value} className={item}>
<span className={control}>
<input
type="radio"
id={optionId}
name={name}
value={option.value}
checked={controlled ? option.value === value : undefined}
defaultChecked={
controlled ? undefined : option.value === defaultValue
}
aria-describedby={
option.description ? `${optionId}-description` : undefined
}
onChange={() => onValueChange?.(option.value)}
className={radio}
/>
<span className={dot} aria-hidden="true" />
</span>
<div className={text}>
<label htmlFor={optionId} className={labelClass}>
{option.label}
</label>
{option.description && (
<p
id={`${optionId}-description`}
className={descriptionClass}
>
{option.description}
</p>
)}
</div>
</div>
);
})}
</div>
</fieldset>
);
}- Make sure Tailwind CSS v4 and markas.css are installed. See Installation.
- Copy the component source below to
src/components/markas/RadioGroup.vue.
src/components/markas/RadioGroup.vue
<script setup lang="ts">
import { computed, useId } from "vue";
export type RadioOption = {
value: string;
label: string;
description?: string;
};
const props = withDefaults(
defineProps<{
name: string;
options: RadioOption[];
label?: string;
orientation?: "vertical" | "horizontal";
id?: string;
}>(),
{ label: undefined, id: undefined, orientation: "vertical" },
);
const model = defineModel<string>();
const root = "min-w-0";
const legendClass = "mb-3 text-sm font-medium text-ink";
const orientations = {
vertical: "grid gap-3",
horizontal: "flex flex-wrap gap-x-6 gap-y-3",
};
const item =
"flex items-start gap-3 has-disabled:cursor-not-allowed has-disabled:opacity-50";
const control = "relative mt-0.5 flex size-4 shrink-0";
const radio =
"peer size-4 shrink-0 cursor-pointer appearance-none rounded-full border border-faint bg-surface transition-colors duration-150 ease-out checked:border-primary checked:bg-primary focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-primary disabled:cursor-not-allowed motion-reduce:transition-none";
const dot =
"pointer-events-none absolute inset-1 rounded-full bg-on-primary opacity-0 peer-checked:opacity-100";
const text = "grid gap-0.5";
const labelClass = "text-sm font-medium text-ink";
const descriptionClass = "text-sm text-muted";
const generatedId = useId();
const groupId = computed(() => props.id ?? generatedId);
</script>
<template>
<fieldset :id="groupId" :class="root">
<legend v-if="props.label" :class="legendClass">{{ props.label }}</legend>
<div :class="orientations[props.orientation]">
<div v-for="option in props.options" :key="option.value" :class="item">
<span :class="control">
<input
:id="`${groupId}-${option.value}`"
v-model="model"
type="radio"
:name="props.name"
:value="option.value"
:aria-describedby="
option.description
? `${groupId}-${option.value}-description`
: undefined
"
:class="radio"
/>
<span :class="dot" aria-hidden="true" />
</span>
<div :class="text">
<label :for="`${groupId}-${option.value}`" :class="labelClass">{{
option.label
}}</label>
<p
v-if="option.description"
:id="`${groupId}-${option.value}-description`"
:class="descriptionClass"
>
{{ option.description }}
</p>
</div>
</div>
</div>
</fieldset>
</template>- Make sure Tailwind CSS v4 and markas.css are installed. See Installation.
- Copy the component source below to
src/lib/components/markas/RadioGroup.svelte.
src/lib/components/markas/RadioGroup.svelte
<script lang="ts">
import type { HTMLFieldsetAttributes } from "svelte/elements";
const root = "min-w-0";
const legendClass = "mb-3 text-sm font-medium text-ink";
const orientations = {
vertical: "grid gap-3",
horizontal: "flex flex-wrap gap-x-6 gap-y-3",
};
const item =
"flex items-start gap-3 has-disabled:cursor-not-allowed has-disabled:opacity-50";
const control = "relative mt-0.5 flex size-4 shrink-0";
const radio =
"peer size-4 shrink-0 cursor-pointer appearance-none rounded-full border border-faint bg-surface transition-colors duration-150 ease-out checked:border-primary checked:bg-primary focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-primary disabled:cursor-not-allowed motion-reduce:transition-none";
const dot =
"pointer-events-none absolute inset-1 rounded-full bg-on-primary opacity-0 peer-checked:opacity-100";
const text = "grid gap-0.5";
const labelClass = "text-sm font-medium text-ink";
const descriptionClass = "text-sm text-muted";
type RadioOption = {
value: string;
label: string;
description?: string;
};
type Props = HTMLFieldsetAttributes & {
name: string;
options: RadioOption[];
label?: string;
/** Selected option, bindable with bind:value. */
value?: string;
orientation?: keyof typeof orientations;
};
let {
name,
options,
label,
value = $bindable(),
orientation = "vertical",
id,
class: className,
...rest
}: Props = $props();
const generatedId = $props.id();
const groupId = $derived(id ?? generatedId);
</script>
<fieldset id={groupId} class={[root, className]} {...rest}>
{#if label}
<legend class={legendClass}>{label}</legend>
{/if}
<div class={orientations[orientation]}>
{#each options as option (option.value)}
{@const optionId = `${groupId}-${option.value}`}
<div class={item}>
<span class={control}>
<input
type="radio"
id={optionId}
{name}
value={option.value}
bind:group={value}
aria-describedby={option.description
? `${optionId}-description`
: undefined}
class={radio}
/>
<span class={dot} aria-hidden="true"></span>
</span>
<div class={text}>
<label for={optionId} class={labelClass}>{option.label}</label>
{#if option.description}
<p id={`${optionId}-description`} class={descriptionClass}>
{option.description}
</p>
{/if}
</div>
</div>
{/each}
</div>
</fieldset>- Make sure Tailwind CSS v4 and markas.css are installed. See Installation.
- Copy the component source below to
src/components/markas/RadioGroup.astro.
src/components/markas/RadioGroup.astro
---
import type { HTMLAttributes } from "astro/types";
const root = "min-w-0";
const legendClass = "mb-3 text-sm font-medium text-ink";
const orientations = {
vertical: "grid gap-3",
horizontal: "flex flex-wrap gap-x-6 gap-y-3",
};
const item =
"flex items-start gap-3 has-disabled:cursor-not-allowed has-disabled:opacity-50";
const control = "relative mt-0.5 flex size-4 shrink-0";
const radio =
"peer size-4 shrink-0 cursor-pointer appearance-none rounded-full border border-faint bg-surface transition-colors duration-150 ease-out checked:border-primary checked:bg-primary focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-primary disabled:cursor-not-allowed motion-reduce:transition-none";
const dot =
"pointer-events-none absolute inset-1 rounded-full bg-on-primary opacity-0 peer-checked:opacity-100";
const text = "grid gap-0.5";
const labelClass = "text-sm font-medium text-ink";
const descriptionClass = "text-sm text-muted";
type RadioOption = {
value: string;
label: string;
description?: string;
};
type Props = HTMLAttributes<"fieldset"> & {
name: string;
options: RadioOption[];
label?: string;
value?: string;
orientation?: keyof typeof orientations;
};
const {
name,
options,
label,
value,
orientation = "vertical",
id,
class: className,
...rest
} = Astro.props;
const groupId = id ?? `markas-radio-group-${crypto.randomUUID().slice(0, 8)}`;
---
<fieldset id={groupId} class:list={[root, className]} {...rest}>
{label && <legend class={legendClass}>{label}</legend>}
<div class={orientations[orientation]}>
{
options.map((option) => {
const optionId = `${groupId}-${option.value}`;
return (
<div class={item}>
<span class={control}>
<input
type="radio"
id={optionId}
name={name}
value={option.value}
checked={option.value === value}
aria-describedby={
option.description ? `${optionId}-description` : undefined
}
class={radio}
/>
<span class={dot} aria-hidden="true" />
</span>
<div class={text}>
<label for={optionId} class={labelClass}>
{option.label}
</label>
{option.description && (
<p id={`${optionId}-description`} class={descriptionClass}>
{option.description}
</p>
)}
</div>
</div>
);
})
}
</div>
</fieldset>- Make sure Tailwind CSS v4 and markas.css are installed. See Installation.
- Copy the component source below to
src/app/markas/radio-group.component.ts.
src/app/markas/radio-group.component.ts
import {
booleanAttribute,
ChangeDetectionStrategy,
Component,
computed,
input,
model,
} from "@angular/core";
const root = "min-w-0";
const legendClass = "mb-3 text-sm font-medium text-ink";
const orientations = {
vertical: "grid gap-3",
horizontal: "flex flex-wrap gap-x-6 gap-y-3",
};
const item =
"flex items-start gap-3 has-disabled:cursor-not-allowed has-disabled:opacity-50";
const control = "relative mt-0.5 flex size-4 shrink-0";
const radio =
"peer size-4 shrink-0 cursor-pointer appearance-none rounded-full border border-faint bg-surface transition-colors duration-150 ease-out checked:border-primary checked:bg-primary focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-primary disabled:cursor-not-allowed motion-reduce:transition-none";
const dot =
"pointer-events-none absolute inset-1 rounded-full bg-on-primary opacity-0 peer-checked:opacity-100";
const text = "grid gap-0.5";
const labelClass = "text-sm font-medium text-ink";
const descriptionClass = "text-sm text-muted";
export type RadioOption = {
value: string;
label: string;
description?: string;
};
let nextId = 0;
/**
* Host stays out of layout (display: contents). id, disabled, and class move to the fieldset,
* so the host attributes are cleared.
*/
@Component({
selector: "markas-radio-group",
changeDetection: ChangeDetectionStrategy.OnPush,
host: {
class: "contents",
"[attr.id]": "null",
"[attr.name]": "null",
"[attr.label]": "null",
"[attr.disabled]": "null",
},
template: `
<fieldset [id]="groupId()" [class]="rootClass()" [disabled]="disabled()">
@if (label()) {
<legend [class]="legendClass">{{ label() }}</legend>
}
<div [class]="orientations[orientation()]">
@for (option of options(); track option.value) {
@let optionId = groupId() + "-" + option.value;
<div [class]="item">
<span [class]="control">
<input
type="radio"
[id]="optionId"
[name]="name()"
[value]="option.value"
[checked]="option.value === value()"
[attr.aria-describedby]="
option.description ? optionId + '-description' : null
"
[class]="radio"
(change)="value.set(option.value)"
/>
<span [class]="dot" aria-hidden="true"></span>
</span>
<div [class]="text">
<label [for]="optionId" [class]="labelClass">{{
option.label
}}</label>
@if (option.description) {
<p [id]="optionId + '-description'" [class]="descriptionClass">
{{ option.description }}
</p>
}
</div>
</div>
}
</div>
</fieldset>
`,
})
export class RadioGroup {
readonly name = input.required<string>();
readonly options = input.required<RadioOption[]>();
readonly label = input<string>();
readonly orientation = input<keyof typeof orientations>("vertical");
readonly id = input<string>();
readonly disabled = input(false, { transform: booleanAttribute });
readonly userClass = input("", { alias: "class" });
/** Selected option, two-way bindable with [(value)]. */
readonly value = model<string>();
protected readonly legendClass = legendClass;
protected readonly orientations = orientations;
protected readonly item = item;
protected readonly control = control;
protected readonly radio = radio;
protected readonly dot = dot;
protected readonly text = text;
protected readonly labelClass = labelClass;
protected readonly descriptionClass = descriptionClass;
private readonly generatedId = `markas-radio-group-${nextId++}`;
protected readonly groupId = computed(() => this.id() ?? this.generatedId);
protected readonly rootClass = computed(() =>
[root, this.userClass()].filter(Boolean).join(" "),
);
}Usage
<x-markas.radio-group
name="plan"
label="Subscription plan"
:value="old('plan', 'pro')"
:options="[
['value' => 'free', 'label' => 'Free', 'description' => 'For personal projects.'],
['value' => 'pro', 'label' => 'Pro'],
]"
/>Livewire
<x-markas.radio-group name="plan" wire:model.live="plan" :options="$plans" />wire:model (and x-model) is copied to every radio, so Livewire reads the checked value. Other attributes stay on the fieldset.
import { RadioGroup } from "@/components/markas/RadioGroup";
<RadioGroup
name="plan"
label="Subscription plan"
defaultValue="pro"
onValueChange={(value) => console.log(value)}
options={[
{ value: "free", label: "Free", description: "For personal projects." },
{ value: "pro", label: "Pro" },
]}
/>;<script setup lang="ts">
import { ref } from "vue";
import RadioGroup from "@/components/markas/RadioGroup.vue";
const plan = ref("pro");
</script>
<template>
<RadioGroup
v-model="plan"
name="plan"
label="Subscription plan"
:options="[
{ value: 'free', label: 'Free', description: 'For personal projects.' },
{ value: 'pro', label: 'Pro' },
]"
/>
</template><script lang="ts">
import RadioGroup from "$lib/components/markas/RadioGroup.svelte";
let plan = $state("pro");
</script>
<RadioGroup
bind:value={plan}
name="plan"
label="Subscription plan"
options={[
{ value: "free", label: "Free", description: "For personal projects." },
{ value: "pro", label: "Pro" },
]}
/>---
import RadioGroup from "@/components/markas/RadioGroup.astro";
---
<RadioGroup
name="plan"
label="Subscription plan"
value="pro"
options={[
{ value: "free", label: "Free", description: "For personal projects." },
{ value: "pro", label: "Pro" },
]}
/>No client script: the options are native radios.
import { Component, signal } from "@angular/core";
import { RadioGroup } from "./markas/radio-group.component";
@Component({
selector: "app-billing",
imports: [RadioGroup],
template: `
<markas-radio-group
[(value)]="plan"
name="plan"
label="Subscription plan"
[options]="plans"
/>
`,
})
export class Billing {
readonly plan = signal<string | undefined>("pro");
readonly plans = [
{ value: "free", label: "Free", description: "For personal projects." },
{ value: "pro", label: "Pro" },
];
}- Extra attributes (
class,disabled,aria-*) fall through to the<fieldset>.disabledon the fieldset disables every radio at once. - Option values are used in ids, so stick to lowercase letters, digits, hyphens, or underscores.
- Use
orientation="horizontal"for short options laid out in a row. - The component has no built-in text. Translate
labeland each option’slabelanddescriptiondirectly.
Props
| Name | Type | Default | Description |
|---|---|---|---|
name | string | required | The name attribute shared by every radio in the group. |
options | { value, label, description? }[] | [] | List of options. The value is also used as part of the id. |
label | string | - | Group title, rendered as the legend. |
value / defaultValue / v-model / bind:value | string | - | Selected option. Blade and Astro use value, React value or defaultValue, Vue v-model, Svelte bind:value, Angular value or [(value)]. |
onValueChange | (value: string) => void | - | React only. Called with the value of the newly selected option. |
orientation | "vertical" | "horizontal" | vertical | Option layout: stacked or in a row. |
id | string | auto | Fieldset id, also the prefix of each radio id. Generated when empty. |
Accessibility
- Uses fieldset and legend, so the group title is announced when focus enters a radio.
- Native radios: Tab moves to the selected option, arrow keys change the selection.
- Option descriptions are linked to their radio through aria-describedby.
Related components
More form components with the same classes in every framework.
- ButtonButton with primary, secondary, ghost, and danger variants.
- CheckboxNative checkbox with an optional label and description, custom styled without JavaScript.
- ComboboxText input with a filtered suggestion list in a popover, following the WAI-ARIA Combobox pattern with list autocomplete.
- InputText field with a label, hint, and error message wired up through ARIA.
- Input OTPOne-time code input split into single-digit boxes, with auto advance, paste support, and one hidden field for form submit.
- LabelForm label with consistent styling and optional required or optional markers that screen readers announce correctly.