Skip to content

Radio

<loomi-radio> — a themeable radio button. Give radios in a group the same name and they become mutually exclusive (coordinated across the same DOM root, since native radio grouping doesn’t cross shadow boundaries). Form-associated.

Terminal window
npm install @loomidev/radio lit
import "@loomidev/radio";
<loomi-radio name="tnc"></loomi-radio>

Radios are most useful in groups — give each radio in the group the same name to make them mutually exclusive.

<loomi-radio label="Action" name="genre" value="action"></loomi-radio>
<loomi-radio label="Comedy" name="genre" value="comedy"></loomi-radio>
<loomi-radio label="Drama" name="genre" value="drama"></loomi-radio>
<loomi-radio label="Thriller" name="genre" value="thriller"></loomi-radio>

Check one by default with checked:

<loomi-radio label="I am checked by default" name="check_me" checked></loomi-radio>

Radios can also be disabled:

<loomi-radio label="I am disabled" disabled></loomi-radio>

Any loomi color works: primary secondary info success error warning gray success warning error primary.

<loomi-radio color="error" checked label="Red"></loomi-radio>
<loomi-radio color="yellow" label="Yellow"></loomi-radio>
<loomi-radio color="success" label="Green"></loomi-radio>
<loomi-radio color="error" label="Error"></loomi-radio>
<loomi-radio color="warning" label="Warning"></loomi-radio>
<loomi-radio color="success" label="Success"></loomi-radio>
<loomi-radio color="warning" label="Orange"></loomi-radio>
<loomi-radio color="success" label="Violet"></loomi-radio>
<loomi-radio color="primary" label="Indigo"></loomi-radio>
<loomi-radio color="error" label="Fuchsia"></loomi-radio>

Give every radio in a group a value so the right one is submitted under the shared name when the form is submitted.

<loomi-radio name="notify_me" value="1" label="Send me weekly newsletters"></loomi-radio>

For the library-wide baseline, see Foundations — Accessibility.

For the shared container and viewport rules, see Foundations — Responsive behavior.

For theme activation, token overrides, and contrast guidance, see Foundations — Dark mode.

AttributeDefaultDescription
name(blank)Group name; submitted with the form.
value(blank)Submitted value when selected.
label(blank)Label text (or use the default slot).
checkedfalseChecked state. (boolean, reflected)
disabledfalseDisable the radio. (boolean)
colorprimaryActive color (any loomi color).
no-clearingfalseRemove the default bottom margin. (boolean)
SlotDescription
(default)Content placed inside the component.
EventDescription
changeFired when the value is committed or changed.
<loomi-radio
label="I agree to the terms and conditions"
color="error"
name="tnc"
value="yes"
></loomi-radio>

<loomi-radio> is a standard custom element, so the browser can use it in plain HTML, Blade, React, Vue, Angular, Svelte, Astro, and most other frameworks. The important beginner rule is: install the package, import it once before the tag is rendered, then write the Loomi tag in your template.

Run install commands from the app where you want to use this component. That means the folder that contains that app’s package.json. Do not run these install commands from packages/radio unless you are editing LoomiUI itself.

Terminal window
cd /path/to/your-app
npm install @loomidev/radio lit

If you are contributing to LoomiUI itself, first move to the top-level components folder. That is where the main package.json for all packages lives, and pnpm --filter ... commands should be run from there:

Terminal window
cd /path/to/your-copy-of-loomiui/components
pnpm --filter @loomidev/radio build
pnpm --filter @loomidev/radio typecheck

Use the CDN version for prototypes, documentation pages, or a quick reproduction. The import map tells the browser where to find Lit, which Loomi components use internally.

<script type="importmap">
{ "imports": { "lit": "https://esm.sh/lit@3.3.3", "lit/": "https://esm.sh/lit@3.3.3/" } }
</script>
<script type="module" src="https://esm.sh/@loomidev/radio"></script>
<loomi-radio name="frequency" value="monthly" label="Monthly" checked></loomi-radio>

In Vite, Webpack, Parcel, Rollup, or a framework build pipeline, install the package and import it once in your main app JavaScript file. After that, you can use the Loomi tag anywhere in your app.

import "@loomidev/radio";

Because this is a form-capable component, give it a name when it should submit with a native <form>. Read its value with new FormData(form).get("the-name") just like you would for a built-in input.

Run the install command from your Laravel project root, then import the component in resources/js/app.js. If your project uses Laravel Vite, npm run dev and npm run build should also be run from the Laravel project root.

Terminal window
cd /path/to/your-laravel-app
npm install @loomidev/radio lit
npm run dev
resources/js/app.js
import "@loomidev/radio";
<loomi-radio name="frequency" value="monthly" label="Monthly" checked></loomi-radio>

React can render Loomi tags directly. If you are on React 18, or if you need to pass arrays, objects, or functions, use a ref and assign those values after the component mounts.

import "@loomidev/radio";
export function LoomiExample() {
return (
<loomi-radio name="frequency" value="monthly" label="Monthly" checked></loomi-radio>
);
}

If TypeScript does not recognize the Loomi tag in JSX, add it to your app’s JSX type declarations.

Import the package in the component that uses it, or once in your main Vue file. Vue templates can use Loomi tags directly. For arrays, objects, or functions, pass the value as a JavaScript property instead of as plain text.

<script setup>
import "@loomidev/radio";
</script>
<template>
<loomi-radio name="frequency" value="monthly" label="Monthly" checked></loomi-radio>
</template>

If Vue warns that the tag is an unknown component, configure compilerOptions.isCustomElement for tags that start with loomi- in your Vite or Vue config.

Import the package once and tell Angular to allow custom HTML tags with CUSTOM_ELEMENTS_SCHEMA. For NgModule apps, add the schema to the module instead of the standalone component.

app.component.ts
import { CUSTOM_ELEMENTS_SCHEMA, Component } from "@angular/core";
import "@loomidev/radio";
@Component({
selector: "app-root",
standalone: true,
schemas: [CUSTOM_ELEMENTS_SCHEMA],
template: `
<loomi-radio name="frequency" value="monthly" label="Monthly" checked></loomi-radio>
`,
})
export class AppComponent {}

Svelte can import the package inside a component script. Astro can import it in the frontmatter of the page or layout where the tag appears.

<script>
import "@loomidev/radio";
</script>
<loomi-radio name="frequency" value="monthly" label="Monthly" checked></loomi-radio>
---
import "@loomidev/radio";
---
<loomi-radio name="frequency" value="monthly" label="Monthly" checked></loomi-radio>

Frameworks such as Next.js, Nuxt, SvelteKit, and Astro sometimes render HTML on the server before browser-only code runs. If your framework complains, move the Loomi import to client-side code. In Next.js, that usually means a component with "use client"; in Nuxt, it often means a .client.ts plugin.

  • @loomidev/core
  • @loomidev/theme