JollyUI
  1. Docs
  2. components
  3. RadioGroup

RadioGroup

A RadioGroup allows users to select a single option from a list of mutually exclusive options.

Radio groups can be built in HTML with the <fieldset> and <input> elements, however these can be difficult to style. RadioGroup and Radio help achieve accessible radio groups that can be styled as needed.

Favorite pet

Installation

npx @sly-cli/sly add jolly-ui radio-group

Composed Components

A RadioGroup uses the following components, which may also be used standalone or reused in other components.

Label

A label provides context for an element.

Reusable Wrapper - Example

If you will use a RadioGroup in multiple places in your app, you can wrap all of the pieces into a reusable component. This way, the DOM structure, styling code, and other logic are defined in a single place and reused everywhere to ensure consistency.

The installed file includes a reusable wrapper JollyRadioGroup. This wrapper serves as an excellent starting point for use throughout your codebase.

Component radiogroup-reusable not found in registry.

The JollyRadioGroup component extends the props of React Aria RadioGroup and adds:

PropTypeDefaultDescription
labelstring | undefinedundefinedLabel for the radio group
descriptionstring | undefinedundefinedDescription text for the radio group
errorMessagestring | ((validation: AriaValidationResult) => string) | undefinedundefinedError message to display or function to generate it

You can copy this wrapper and create variations as needed for different use cases in your application. This approach promotes consistency while still allowing for flexibility in implementation.

Examples

Basic

Favorite pet

Validation

Favorite pet

Description

Favorite avatarPlease select an avatar.

Orientation

Favorite avatar

Disabled

The entire RadioGroup can be disabled with the isDisabled prop.

Favorite sport

To disable an individual radio, pass isDisabled to the Radio instead.

Favorite sport

Read-only

Favorite avatar