Zubra UI
Code for
GitHub

radio-group

A set of options where one is chosen, on native radio buttons in a <fieldset>: arrow keys move between them, the choice submits under name, and required validates. options is [{ value, label, description? }]; value is two-way. orientation="horizontal" puts them in a row.

Try it: events appear here (valuechange).

Source: radio-group.zb, and its registry item.

Install

Compiled (any project)
npx shadcn@latest add https://zubra-js.github.io/zubra-ui/r/radio-group.jsonpnpm dlx shadcn@latest add https://zubra-js.github.io/zubra-ui/r/radio-group.jsonyarn dlx shadcn@latest add https://zubra-js.github.io/zubra-ui/r/radio-group.jsonbunx --bun shadcn@latest add https://zubra-js.github.io/zubra-ui/r/radio-group.json
One file, no dependencies (3.5 KB gzipped)
npx shadcn@latest add https://zubra-js.github.io/zubra-ui/r/element/radio-group.jsonpnpm dlx shadcn@latest add https://zubra-js.github.io/zubra-ui/r/element/radio-group.jsonyarn dlx shadcn@latest add https://zubra-js.github.io/zubra-ui/r/element/radio-group.jsonbunx --bun shadcn@latest add https://zubra-js.github.io/zubra-ui/r/element/radio-group.json
.zb source (to edit it with Zubra)
npx shadcn@latest add https://zubra-js.github.io/zubra-ui/r/src/radio-group.jsonpnpm dlx shadcn@latest add https://zubra-js.github.io/zubra-ui/r/src/radio-group.jsonyarn dlx shadcn@latest add https://zubra-js.github.io/zubra-ui/r/src/radio-group.jsonbunx --bun shadcn@latest add https://zubra-js.github.io/zubra-ui/r/src/radio-group.json
No build: a script tag, straight from this site
HTML
<link rel="stylesheet" href="https://zubra-js.github.io/zubra-ui/themes/default.css">
<script type="module" src="https://zubra-js.github.io/zubra-ui/cdn/radio-group.js"></script>

The compiled install writes src/components/zubra/radio-group.js and the theme, and adds @zubra/runtime to your dependencies. The one-file install writes the same path as a plain custom element that needs nothing installed (or download it and load it with a <script type="module">); it's smaller on a page with one to three components, the shared runtime with more.

Usage

index.html
<radio-group label="Delivery" name="delivery"></radio-group>

<script type="module">
  import './components/zubra/radio-group.js';

  const element = document.querySelector('radio-group');
  element.value = 'standard';
  element.options = [
    {
      value: 'standard',
      label: 'Standard',
      description: '3–5 working days, free',
    },
    {
      value: 'express',
      label: 'Express',
      description: 'Next working day, $9',
    },
    {
      value: 'pickup',
      label: 'Collect in store',
      description: 'Ready in two hours',
    },
  ];
  element.addEventListener('valuechange', (event) => console.log('valuechange', event.detail));
</script>
Example.jsx
import './components/zubra/radio-group.js';

const value = 'standard';
const options = [
  {
    value: 'standard',
    label: 'Standard',
    description: '3–5 working days, free',
  },
  {
    value: 'express',
    label: 'Express',
    description: 'Next working day, $9',
  },
  {
    value: 'pickup',
    label: 'Collect in store',
    description: 'Ready in two hours',
  },
];

export function RadioGroupExample() {
  return (
    <radio-group
      label="Delivery"
      name="delivery"
      value={value}
      options={options}
      onvaluechange={(event) => console.log('valuechange', event.detail)}
    ></radio-group>
  );
}
Example.vue
<script setup>
import './components/zubra/radio-group.js';
const value = 'standard';
const options = [
  {
    value: 'standard',
    label: 'Standard',
    description: '3–5 working days, free',
  },
  {
    value: 'express',
    label: 'Express',
    description: 'Next working day, $9',
  },
  {
    value: 'pickup',
    label: 'Collect in store',
    description: 'Ready in two hours',
  },
];
const onValuechange = (event) => console.log('valuechange', event.detail);
</script>

<template>
  <radio-group
    label="Delivery"
    name="delivery"
    :value.prop="value"
    :options.prop="options"
    @valuechange="onValuechange"
  ></radio-group>
</template>

<!-- vite.config.js: vue({ template: { compilerOptions: { isCustomElement: (tag) => tag.includes('-') } } }) -->
Example.svelte
<script>
  import './components/zubra/radio-group.js';
  const value = 'standard';
  const options = [
    {
      value: 'standard',
      label: 'Standard',
      description: '3–5 working days, free',
    },
    {
      value: 'express',
      label: 'Express',
      description: 'Next working day, $9',
    },
    {
      value: 'pickup',
      label: 'Collect in store',
      description: 'Ready in two hours',
    },
  ];
</script>

<radio-group
  label="Delivery"
  name="delivery"
  {value}
  {options}
  onvaluechange={(event) => console.log('valuechange', event.detail)}
></radio-group>
example.component.ts
import { Component, CUSTOM_ELEMENTS_SCHEMA } from '@angular/core';
import './components/zubra/radio-group.js';

@Component({
  selector: 'app-radio-group-example',
  schemas: [CUSTOM_ELEMENTS_SCHEMA],
  template: `
    <radio-group
      label="Delivery"
      name="delivery"
      [value]="value"
      [options]="options"
      (valuechange)="onValuechange($event)"
    ></radio-group>
  `,
})
export class RadioGroupExample {
  value = 'standard';

  options = [
    {
      value: 'standard',
      label: 'Standard',
      description: '3–5 working days, free',
    },
    {
      value: 'express',
      label: 'Express',
      description: 'Next working day, $9',
    },
    {
      value: 'pickup',
      label: 'Collect in store',
      description: 'Ready in two hours',
    },
  ];

  onValuechange(event: Event) {
    console.log('valuechange', (event as CustomEvent).detail);
  }
}

API

Properties (each is also an HTML attribute of the same name, unless marked)
PropertyTypeDefault
valuestring""
options
property only
{ value, label, description }[][]
labelstring""
namestring""
orientation"vertical" | "horizontal""vertical"
requiredbooleanfalse
disabledbooleanfalse
Events
EventWhen
valuechangeThe choice changed; detail is the chosen value.

Size

1.3 KB gzipped for the component, plus the runtime, which every Zubra component on a page shares (up to 22.1 KB, all of it). On its own, with the parts of the runtime it uses, it's 17.6 KB.

Theme

Every component reads shadcn/ui's CSS variables, so any shadcn theme works. Pick a look or a colour, or paste a theme's CSS.

Look: colours, fonts, corners and motion

Accent colour