Skip to content

Radio group API

Cimpress UI exports two radio-related components:

  • RadioGroup: container component that groups related radio buttons together, providing a shared label, optional description, error handling, and state management.
  • Radio: component to display a radio button within a radio group.
import { Radio, RadioGroup } from '@cimpress-ui/react';

This component can be used in a controlled or uncontrolled way.

In the controlled way, this component doesn’t maintain its own internal state, and its value is provided by the parent component. Use the controlled way when you need to be able to change the state of this component in other parts of your application.

In the uncontrolled way, this component maintains its own internal state, and can optionally notify the parent component when its internal state changes. Use the uncontrolled way when you don’t need to change the state of this component in other parts of your application.

Radio cannot be used on its own, and must always be a child of RadioGroup.

RadioGroup is a single tab stop within the page’s tab order. Use the Tab key to navigate to the group, and the arrow keys to navigate between radio buttons within the group.

Radio and RadioGroup require textual labels to remain accessible to assistive technologies. See our accessibility guide for more details.

Radio and radio group can integrate with native HTML forms. See our forms guide to learn how to work with forms.

Renders a single option within RadioGroup.

See radio group usage guidelines.

Ref<HTMLLabelElement>

The ref type for this component.

RadioProps
string

The value of the radio button, used when submitting an HTML form. See MDN.

StringLikeChildren

The label rendered next to the radio.

string

The element's unique identifier. See MDN.

boolean

Use this attribute to "claim" the component tree for exclusive Cimpress UI usage.

string

Sets the CSS className for the element. Only use as a last resort. Use style props instead.

See styling guide.

CSSProperties

Sets the CSS style for the element. Only use as a last resort. Use style props instead.

See styling guide.

string

Defines a string value that labels the current element.

string

Identifies the element (or elements) that labels the current element.

string

Identifies the element (or elements) that describes the object.

string

Identifies the element (or elements) that provide a detailed, extended description for the object.

boolean

Whether the radio button is disabled or not. Shows that a selection exists, but is not available in that circumstance.

boolean

Whether the element should receive focus on render.

StyleProps
Responsive<Spacing | "auto">

The amount of margin applied to all edges of this component.

Responsive<Spacing | "auto">

The amount of margin applied to the left and right edges of this component. Takes priority over margin.

Responsive<Spacing | "auto">

The amount of margin applied to the top and bottom edges of this component. Takes priority over margin.

Responsive<Spacing | "auto">

The amount of margin applied to the top edge of this component. Takes priority over marginY and margin.

Responsive<Spacing | "auto">

The amount of margin applied to the right edge of this component. Takes priority over marginX and margin.

Responsive<Spacing | "auto">

The amount of margin applied to the bottom edge of this component. Takes priority over marginY and margin.

Responsive<Spacing | "auto">

The amount of margin applied to the left edge of this component. Takes priority over marginX and margin.

Allows users to select a single item from a visible list.

See radio group usage guidelines.

Ref<HTMLDivElement>

The ref type for this component.

RadioGroupProps
ReactNode

Radio buttons belonging to the group.

Responsive<Direction>

Determines the direction in which radio buttons will be stacked.

Defaults to 'vertical' .
string

The element's unique identifier. See MDN.

boolean

Use this attribute to "claim" the component tree for exclusive Cimpress UI usage.

string

Sets the CSS className for the element. Only use as a last resort. Use style props instead.

See styling guide.

CSSProperties

Sets the CSS style for the element. Only use as a last resort. Use style props instead.

See styling guide.

string

The content to display as the label.

string

Defines a string value that labels the current element.

string

Identifies the element (or elements) that labels the current element.

string

Identifies the element (or elements) that describes the object.

string

Identifies the element (or elements) that provide a detailed, extended description for the object.

string

The <form> element to associate the input with. The value of this attribute must be the id of a <form> in the same document. See MDN.

string

The name of the input element, used when submitting an HTML form. See MDN.

string

A description for the field. Provides a hint such as specific requirements for what to choose.

FieldError

An error message for the field.

(value: string | null) => string | true | string[] | undefined

A function that returns an error message (or true) if a given value is invalid. Validation errors are displayed to the user when the form is submitted. For real-time validation, use the error prop instead.

boolean

Whether user input is required on the input before form submission.

boolean

Whether the input value is invalid.

boolean

Whether the input is disabled.

boolean

Whether the input can be selected but not changed by the user.

string | null

The current value (controlled).

string | null

The default value (uncontrolled).

(value: string) => void

Handler that is called when the value changes.

StyleProps
Responsive<Spacing | "auto">

The amount of margin applied to all edges of this component.

Responsive<Spacing | "auto">

The amount of margin applied to the left and right edges of this component. Takes priority over margin.

Responsive<Spacing | "auto">

The amount of margin applied to the top and bottom edges of this component. Takes priority over margin.

Responsive<Spacing | "auto">

The amount of margin applied to the top edge of this component. Takes priority over marginY and margin.

Responsive<Spacing | "auto">

The amount of margin applied to the right edge of this component. Takes priority over marginX and margin.

Responsive<Spacing | "auto">

The amount of margin applied to the bottom edge of this component. Takes priority over marginY and margin.

Responsive<Spacing | "auto">

The amount of margin applied to the left edge of this component. Takes priority over marginX and margin.