RadioGroup

Requires:
@ray-js/ray≥0.5.10

Description

A single-select group composed of multiple Radio components. Use either options or children.

Props

PropertyTypeRequiredDefaultDescription
No-Option list; use either this or children.
childrenany | any[] | stringNo-Child nodes, typically multiple Radio components; use either this or options.
namestringNo-Form field name, used as the key on form submit
disabledbooleanNofalseWhether disabled
No-Triggered when the selection changes.
idstringNo-id
classNamestringNo-className
styleanyNo-style
No-onClick
No-onTouchStart
No-onTouchMove
No-onTouchCancel
No-onTouchEnd
No-onLongPress event callback, no longer trigger click event
slotDeprecatedstringNo-Mini program component slot identifier
↳ This property is only used in base Mini Program components and is not recommended in the React DSL.
No-Long press the trigger

Examples

Basic usage

import React from 'react';
import { RadioGroup, Radio, Label } from '@ray-js/ray';

export default function () {
  const options = [
    { label: 'Apple', value: 'Apple' },
    { label: 'Pear', value: 'Pear' },
  ];

  return (
    <RadioGroup onChange={(e) => console.log('Selected value:', e.detail.value)}>
      {options.map((item) => (
        <Label key={item.value}>
          <Radio value={item.value} />
          {item.label}
        </Label>
      ))}
    </RadioGroup>
  );
}

Driven by options data.

import React from 'react';
import { RadioGroup, View, Text } from '@ray-js/ray';

export default function () {
  return (
    <View style={{ padding: '20px' }}>
      <Text style={{ marginBottom: '10px' }}>Render with options:</Text>
      <RadioGroup
        name="fruit"
        disabled={false}
        options={[
          { label: 'Apple', value: 'apple', checked: true },
          { label: 'Banana', value: 'banana' },
          { label: 'Grape', value: 'grape', disabled: true },
        ]}
        onChange={(e) => console.log('Selected:', e.detail.value)}
      />
    </View>
  );
}