Back to Twenty

Radio

packages/twenty-docs/twenty-ui/input/radio.mdx

2.2.02.6 KB
Original Source
<Frame> </Frame>

Used when users may only choose one option from a series of options.

<Tabs> <Tab title="Usage">
jsx
import { Radio } from "twenty-ui/display";

export const MyComponent = () => {

  const handleRadioChange = (event) => {
    console.log("Radio button changed:", event.target.checked);
  };

  const handleCheckedChange = (checked) => {
    console.log("Checked state changed:", checked);
  };


  return (
    <Radio
      checked={true}
      value="Option 1"
      onChange={handleRadioChange}
      onCheckedChange={handleCheckedChange}
      size="large"
      disabled={false}
      labelPosition="right"
    />
  );
};

</Tab> <Tab title="Props">
PropsTypeDescription
styleReact.CSS propertiesAdditional inline styles for the component
classNamestringOptional CSS class for additional styling
checkedbooleanIndicates whether the radio button is checked
valuestringThe label or text associated with the radio button
onChangefunctionThe function called when the selected radio button is changed
onCheckedChangefunctionThe function called when the checked state of the radio button changes
sizestringThe size of the radio button. Options include: large and small
disabledbooleanIf true, the radio button is disabled and not clickable
labelPositionstringThe position of the label text relative to the radio button. Has two options: left and right
</Tab> </Tabs>

Radio Group

Groups together related radio buttons.

<Tabs> <Tab title="Usage">
jsx
import React, { useState } from "react";
import { Radio, RadioGroup } from "twenty-ui/display";

export const MyComponent = () => {

  const [selectedValue, setSelectedValue] = useState("Option 1");

  const handleChange = (event) => {
    setSelectedValue(event.target.value);
  };
  
  return (
    <RadioGroup value={selectedValue} onChange={handleChange}>
      <Radio value="Option 1" />
      <Radio value="Option 2" />
      <Radio value="Option 3" />
    </RadioGroup>
  );
};

</Tab> <Tab title="Props">
PropsTypeDescription
valuestringThe value of the currently selected radio button
onChangefunctionThe callback function triggered when the radio button is changed
onValueChangefunctionThe callback function triggered when the selected value in the group changes.
childrenReact.ReactNodeAllows you to pass React components (such as Radio) as children to the Radio Group
</Tab> </Tabs>