> For the complete documentation index, see [llms.txt](https://swift-packages.gitbook.io/materialuikit/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://swift-packages.gitbook.io/materialuikit/components/radio-buttons-group.md).

# Radio Buttons Group

Represents a Material UI styled group of radio buttons for selecting a single option.​

### Overview

Radio button groups are used to display a set of mutually exclusive options where only one can be selected at a time. They help users make a single choice from a predefined list of options.

The `RadioButtonGroup` view provides a Material UI styled set of radio buttons, making it easy to present and select options within a SwiftUI view.&#x20;

To use the `RadioButtonGroup`, initialize it with a collection of items, a key path for unique identification, a binding to track the selected item, and a closure for rendering each item.

### Initializer

Creates a radio button group view with the provided items and a binding to the selected value.

```swift
RadioButtonGroup(
    _ data: Data,
    id: KeyPath<Data.Element, ID>,
    selection: Binding<Data.Element>,
    @ViewBuilder _ content: @escaping (Data.Element) -> Content
)
```

### Parameters

<table><thead><tr><th width="176">Parameter</th><th>Description</th></tr></thead><tbody><tr><td><code>data</code></td><td>A collection of elements to display in the radio-group options.</td></tr><tr><td><code>id</code></td><td>A key path to an <code>ID</code> property on each element to uniquely identify them.</td></tr><tr><td><code>selection</code></td><td>A binding to the currently selected element in the radio-group options.</td></tr><tr><td><code>content</code></td><td>A closure that returns the content view for a given element.</td></tr></tbody></table>

### Example

```swift
@State private var selectedOption: String = "Option 1"
private let options: [String] = ["Option 1", "Option 2", "Option 3"]

var body: some View {
    Collection {
        RadioButtonGroup(options, id: \.self, selection: $selectedOption) { option in
            Text(option)
        }
    }
}
```

<figure><picture><source srcset="/files/BQtv1UZFkzs4ojJaKxHn" media="(prefers-color-scheme: dark)"><img src="https://2931569195-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FHpwjDgYAa64eKF8AGmeE%2Fuploads%2FW50k2TTFo4QemwEnUvRA%2FRadio%20Buttons%20Light.png?alt=media&amp;token=76dcb090-2ce6-497d-8115-95534de2ad9a" alt=""></picture><figcaption></figcaption></figure>

> `RadioButtonGroup` is compatible with custom data models that conform to `Hashable` and `Identifiable` protocols.
