# ChoiceGroup
**Also known as:** Radio, RadioButton, RadioGroup, RadioButtonGroup
## Description
ChoiceGroup, also known as Radio or RadioGroup, lets people select a single value from two or more mutually exclusive choices. Reach for it when all the options are worth showing at once (roughly two to seven of them) and the choice matters enough to stay visible; a Dropdown suits longer lists, and a Checkbox suits choices that are not mutually exclusive. It renders native radio inputs, so the browser provides the full keyboard behavior for free: the whole group is a single tab stop that lands on the checked item, and the arrow keys move the selection - wrapping around the ends and following the text direction in Chromium and Firefox, while WebKit keeps them on the order of the markup and stops at the ends. On top of that it adds a group label and helper text, per-item icons, images, prefixes and descriptions, vertical, horizontal and full width layouts, an Outline or Fill variant that turns every item into a selectable card, and templates at every level, all through three interchangeable item APIs.
## Parameters
| Name | Type | Default Value | Description |
| :--- | :--- | :------------ | :---------- |
| AriaLabelledBy | `string?` | null | Id of an element to use as the aria label for the ChoiceGroup. |
| AutoFocus | `bool` | false | Determines if the ChoiceGroup is auto focused on first render, focusing its checked item, or its first enabled item when nothing is checked. Nothing is focused when the ChoiceGroup is read-only or the target item is disabled. |
| AutoReorderOptions | `bool` | false | Keeps the assigned Index of each option in sync with the markup order of the options, even when an option is added, removed, or reordered conditionally after the first render. |
| ChildContent | `RenderFragment?` | null | The content of the ChoiceGroup, a list of BitChoiceGroupOption components. |
| Classes | `BitChoiceGroupClassStyles?` | null | Custom CSS classes for different parts of the BitChoiceGroup. |
| Color | `BitColor?` | null | The general color of the ChoiceGroup. |
| Comparer | `IEqualityComparer<TValue>?` | null | The comparer that decides which item carries the current value, and which item the DefaultValue seeds the selection with. Defaults to EqualityComparer<TValue>.Default; supply one when TValue is a class whose instances are equal by their content rather than by reference. |
| Description | `string?` | null | The description (helper text) of the ChoiceGroup, rendered under its label. The group references it through its aria-describedby, so screen readers announce it along with the name of the group. |
| DescriptionTemplate | `RenderFragment?` | null | Custom RenderFragment for the description (helper text) of the ChoiceGroup. Takes precedence over Description when both are set. |
| FullWidth | `bool` | false | Expands the ChoiceGroup to the full width of its container instead of hugging its widest item. In the horizontal layout the items also share that width equally. |
| Gap | `string?` | null | The gap between the items of the ChoiceGroup. |
| Horizontal | `bool` | false | Renders the items in the ChoiceGroup horizontally. |
| Inline | `bool` | false | Renders the icons and images in a single line with the items in the ChoiceGroup. |
| Items | `IEnumerable<TItem>` | new List<TItem>() | Sets the data source that populates the items of the list. |
| ItemLabelTemplate | `RenderFragment<TItem>?` | | Used to customize the label for the Item Label content. |
| ItemPrefixTemplate | `RenderFragment<TItem>?` | | Used to add a prefix to each item. |
| ItemSuffixTemplate | `RenderFragment<TItem>?` | null | Used to add a suffix to each item, rendered after the content of the item. |
| ItemTemplate | `RenderFragment<TItem>?` | null | Used to customize the label for the Item content. |
| Label | `string?` | null | The label for the ChoiceGroup. |
| LabelPosition | `BitLabelPosition?` | null | The position of the content of each item relative to its radio circle. Defaults to End, which renders the circle first and the content after it. Items rendered as image or icon tiles lay their own content out and ignore this parameter. |
| LabelTemplate | `RenderFragment?` | null | Custom RenderFragment for the label of the ChoiceGroup. |
| Name | `string?` | null | The name shared by the radio inputs of the items, which is what groups them into a single logical radio group. When not set, a unique name is generated for the ChoiceGroup. |
| NameSelectors | `BitChoiceGroupNameSelectors<TItem, TValue>?` | null | Names and selectors of the custom input type properties. |
| NoCircle | `bool` | false | Removes the circle from the start of each item. |
| OnBlur | `EventCallback<TItem>` | | Callback for when an item of the ChoiceGroup loses focus. |
| OnChange | `EventCallback<TValue?>` | | Callback for when the selected value changes. |
| OnClick | `EventCallback<TItem>` | | Callback for when an enabled item is clicked, even the already selected one. |
| OnFocus | `EventCallback<TItem>` | | Callback for when an item of the ChoiceGroup receives focus. |
| Options | `RenderFragment?` | null | Alias of ChildContent. |
| ReadOnly | `bool` | false | Prevents changing the value of the ChoiceGroup while keeping its normal (non-disabled) appearance. |
| Required | `bool` | false | Makes the ChoiceGroup required and adds the required asterisk to its label. |
| Size | `BitSize?` | null | The size of the BitChoiceGroup. |
| StretchItemLabel | `bool` | false | Stretches the label of each item over the full width of its row and spreads its content, which puts the circle at the far edge of the row instead of right beside the item text. Combined with FullWidth and LabelPosition.Start it produces the text-at-the-start, circle-at-the-end list found in settings pages. |
| Styles | `BitChoiceGroupClassStyles?` | null | Custom CSS styles for different parts of the BitChoiceGroup. |
| Variant | `BitVariant?` | null | The visual style of the items: Text (the default) renders a bare radio row, Outline and Fill render each item as a selectable card. |
| DefaultValue | `TValue?` | null | The default value of the input to be used in uncontrolled mode (i.e. when the Value is not bound), typically used alongside the OnChange callback. |
| DisplayName | `string?` | null | Gets or sets the display name for this field. |
| InputHtmlAttributes | `IReadOnlyDictionary<string, object>?` | null | Gets or sets a collection of additional attributes that will be applied to the created element. |
| Name | `string?` | null | Gets or sets the name of the element. Allows access by name from the associated form. |
| NoValidate | `bool` | false | Disables the validation of the input. |
| OnChange | `EventCallback<TValue?>` | | Callback for when the input value changes. |
| ReadOnly | `bool` | false | Makes the input read-only. |
| Required | `bool` | false | Makes the input required. |
| Value | `TValue?` | null | Gets or sets the value of the input. This should be used with two-way binding. |
| AriaLabel | `string?` | null | Gets or sets the accessible label for the component, used by assistive technologies. |
| Class | `string?` | null | Gets or sets the CSS class name(s) to apply to the rendered element. |
| Dir | `BitDir?` | null | Gets or sets the text directionality for the component's content. |
| ForceAnimation | `bool` | false | Gets or sets a value indicating whether the component's animations play at their full duration even when reduced motion is requested. |
| HtmlAttributes | `Dictionary<string, object>` | new Dictionary<string, object>() | Captures additional HTML attributes to be applied to the rendered element, in addition to the component's parameters. |
| Id | `string?` | null | Gets or sets the unique identifier for the component's root element. |
| IsEnabled | `bool` | true | Gets or sets a value indicating whether the component is enabled and can respond to user interaction. |
| Style | `string?` | null | Gets or sets the CSS style string to apply to the rendered element. |
| TabIndex | `string?` | null | Gets or sets the tab order index for the component when navigating with the keyboard. |
| Visibility | `BitVisibility` | BitVisibility.Visible | Gets or sets the visibility state (visible, hidden, or collapsed) of the component. |
## Public Members
| Name | Type | Default Value | Description |
| :--- | :--- | :------------ | :---------- |
| InputElement | `ElementReference` | | The ElementReference of the input element. |
| FocusAsync() | `() => ValueTask` | | Gives focus to the input element. |
| FocusAsync(bool preventScroll) | `(bool preventScroll) => ValueTask` | | Gives focus to the input element. |
| UniqueId | `Guid` | Guid.NewGuid() | Gets the readonly unique identifier for the component's root element, assigned when the component instance is constructed. |
| RootElement | `ElementReference` | | Gets the reference to the root HTML element associated with this component. |
## Enums
### BitColor Enum
| Name | Value | Description |
| :--- | :--- | :---------- |
| Primary | 0 | Primary general color. |
| Secondary | 1 | Secondary general color. |
| Tertiary | 2 | Tertiary general color. |
| Info | 3 | Info general color. |
| Success | 4 | Success general color. |
| Warning | 5 | Warning general color. |
| SevereWarning | 6 | SevereWarning general color. |
| Error | 7 | Error general color. |
| PrimaryBackground | 8 | Primary background color. |
| SecondaryBackground | 9 | Secondary background color. |
| TertiaryBackground | 10 | Tertiary background color. |
| PrimaryForeground | 11 | Primary foreground color. |
| SecondaryForeground | 12 | Secondary foreground color. |
| TertiaryForeground | 13 | Tertiary foreground color. |
| PrimaryBorder | 14 | Primary border color. |
| SecondaryBorder | 15 | Secondary border color. |
| TertiaryBorder | 16 | Tertiary border color. |
### BitLabelPosition Enum
| Name | Value | Description |
| :--- | :--- | :---------- |
| Top | 0 | Renders the content above the radio circle. |
| End | 1 | Renders the content after the radio circle. This is the default. |
| Bottom | 2 | Renders the content below the radio circle. |
| Start | 3 | Renders the content before the radio circle and aligns the items to the end of the group. |
### BitSize Enum
| Name | Value | Description |
| :--- | :--- | :---------- |
| Small | 0 | The small size choice group. |
| Medium | 1 | The medium size choice group. |
| Large | 2 | The large size choice group. |
### BitVariant Enum
| Name | Value | Description |
| :--- | :--- | :---------- |
| Fill | 0 | Each item is a selectable card drawn as a filled surface. |
| Outline | 1 | Each item is a selectable card drawn as a border. |
| Text | 2 | Each item is a bare radio row with no surface of its own. The default. |
### BitVisibility Enum
| Name | Value | Description |
| :--- | :--- | :---------- |
| Visible | 0 | The content of the component is visible. |
| Hidden | 1 | The content of the component is hidden, but the space it takes on the page remains (visibility:hidden). |
| Collapsed | 2 | The component is hidden (display:none). |
### BitDir Enum
| Name | Value | Description |
| :--- | :--- | :---------- |
| Ltr | 0 | Ltr (left to right) is to be used for languages that are written from the left to the right (like English). |
| Rtl | 1 | Rtl (right to left) is to be used for languages that are written from the right to the left (like Arabic). |
| Auto | 2 | Auto lets the user agent decide. It uses a basic algorithm as it parses the characters inside the element until it finds a character with a strong directionality, then applies that directionality to the whole element. |
## Sub Classes
### BitChoiceGroupItem Properties
| Name | Type | Default Value | Description |
| :--- | :--- | :------------ | :---------- |
| AriaLabel | `string?` | null | AriaLabel attribute for the BitChoiceGroup item. |
| Class | `string?` | null | CSS class attribute for the BitChoiceGroup item. |
| Description | `string?` | null | The secondary text to show under the text of the BitChoiceGroup item. |
| Id | `string?` | null | Id attribute of the BitChoiceGroup item. |
| IsEnabled | `bool` | true | Whether the BitChoiceGroup item is enabled. |
| Icon | `BitIconInfo?` | null | The icon to show as content of the BitChoiceGroup item. Takes precedence over IconName when both are set. |
| IconName | `string?` | null | The icon name (built-in Fluent UI) to show as content of the BitChoiceGroup item. |
| ImageSrc | `string?` | null | The image address to show as the content of the BitChoiceGroup item. |
| ImageAlt | `string?` | null | The alt attribute for the image of the BitChoiceGroup item. |
| ImageSize | `BitImageSize?` | null | Provides Width and Height for the image of the BitChoiceGroup item. |
| Prefix | `string?` | null | The text to show as a prefix for the BitChoiceGroup item. |
| SelectedImageSrc | `string?` | null | Provides a new image for the selected state of the image of the BitChoiceGroup item. |
| Style | `string?` | null | CSS style attribute for the BitChoiceGroup item. |
| Suffix | `string?` | null | The text to show as a suffix for the BitChoiceGroup item, rendered after its content. |
| Template | `RenderFragment<BitChoiceGroupItem<TValue>>?` | null | The custom template for the BitChoiceGroup item. |
| Text | `string?` | null | Text to show as the content of BitChoiceGroup item. |
| Title | `string?` | null | The title attribute (the native tooltip) of the BitChoiceGroup item. Supplementary text only: content that has to reach every user belongs in Text (or a template) or in Description, both of which are visible and exposed to assistive technology. AriaLabel is not an alternative: it only replaces the accessible name for assistive technology and is never visible. |
| Value | `TValue?` | null | The value returned when BitChoiceGroup item is checked. |
| Index | `int` | 0 | Index of the BitChoiceGroup item. This property's value is set by the component at render. |
| IsSelected | `bool` | false | Determines if the item is selected. This property's value is assigned by the component. |
### BitChoiceGroupOption Properties
| Name | Type | Default Value | Description |
| :--- | :--- | :------------ | :---------- |
| AriaLabel | `string?` | null | AriaLabel attribute for the BitChoiceGroup option. |
| Class | `string?` | null | CSS class attribute for the BitChoiceGroup option. |
| Description | `string?` | null | The secondary text to show under the text of the BitChoiceGroup option. |
| Id | `string?` | null | Id attribute of the BitChoiceGroup option. |
| IsEnabled | `bool` | true | Whether the BitChoiceGroup option is enabled. |
| Icon | `BitIconInfo?` | null | The icon to show as content of the BitChoiceGroup option. Takes precedence over IconName when both are set. |
| IconName | `string?` | null | The icon name (built-in Fluent UI) to show as content of the BitChoiceGroup option. |
| ImageSrc | `string?` | null | The image address to show as the content of the BitChoiceGroup option. |
| ImageAlt | `string?` | null | The alt attribute for the image of the BitChoiceGroup option. |
| ImageSize | `BitImageSize?` | null | Provides Width and Height for the image of the BitChoiceGroup option. |
| Prefix | `string?` | null | The text to show as a prefix for the BitChoiceGroup option. |
| SelectedImageSrc | `string?` | null | Provides a new image for the selected state of the image of the BitChoiceGroup option. |
| Style | `string?` | null | CSS style attribute for the BitChoiceGroup option. |
| Suffix | `string?` | null | The text to show as a suffix for the BitChoiceGroup option, rendered after its content. |
| Template | `RenderFragment<BitChoiceGroupOption<TValue>>?` | null | The custom template for the BitChoiceGroup option. |
| Text | `string?` | null | Text to show as the content of BitChoiceGroup option. |
| Title | `string?` | null | The title attribute (the native tooltip) of the BitChoiceGroup option. Supplementary text only: content that has to reach every user belongs in Text (or a template) or in Description, both of which are visible and exposed to assistive technology. AriaLabel is not an alternative: it only replaces the accessible name for assistive technology and is never visible. |
| Value | `TValue?` | null | The value returned when BitChoiceGroup option is checked. |
| Index | `int` | 0 | Index of the BitChoiceGroup option. This property's value is set by the component at render. |
| IsSelected | `bool` | false | Determines if the option is selected. This property's value is assigned by the component. |
### BitChoiceGroupNameSelectors<TItem, TValue> Properties
| Name | Type | Default Value | Description |
| :--- | :--- | :------------ | :---------- |
| AriaLabel | `BitNameSelectorPair<TItem, string?>` | new(nameof(BitChoiceGroupItem<TValue>.AriaLabel)) | AriaLabel attribute for the BitChoiceGroup option. |
| Class | `BitNameSelectorPair<TItem, string?>` | new(nameof(BitChoiceGroupItem<TValue>.Class)) | CSS class attribute for the BitChoiceGroup option. |
| Description | `BitNameSelectorPair<TItem, string?>` | new(nameof(BitChoiceGroupItem<TValue>.Description)) | The secondary text to show under the text of the BitChoiceGroup option. |
| Id | `BitNameSelectorPair<TItem, string?>` | new(nameof(BitChoiceGroupItem<TValue>.Id)) | Id attribute of the BitChoiceGroup option. |
| IsEnabled | `BitNameSelectorPair<TItem, bool>` | new(nameof(BitChoiceGroupItem<TValue>.IsEnabled)) | Whether the BitChoiceGroup option is enabled. |
| Icon | `BitNameSelectorPair<TItem, BitIconInfo?>` | new(nameof(BitChoiceGroupItem<TValue>.Icon)) | Icon field name and selector of the custom input class. |
| IconName | `BitNameSelectorPair<TItem, string?>` | new(nameof(BitChoiceGroupItem<TValue>.IconName)) | IconName field name and selector of the custom input class. |
| ImageSrc | `BitNameSelectorPair<TItem, string?>` | new(nameof(BitChoiceGroupItem<TValue>.ImageSrc)) | The image address to show as the content of the BitChoiceGroup option. |
| ImageAlt | `BitNameSelectorPair<TItem, string?>` | new(nameof(BitChoiceGroupItem<TValue>.ImageAlt)) | The alt attribute for the image of the BitChoiceGroup option. |
| ImageSize | `BitNameSelectorPair<TItem, BitImageSize?>` | new(nameof(BitChoiceGroupItem<TValue>.ImageSize)) | Provides Width and Height for the image of the BitChoiceGroup option. |
| Prefix | `BitNameSelectorPair<TItem, string?>` | new(nameof(BitChoiceGroupItem<TValue>.Prefix)) | The text to show as a prefix for the BitChoiceGroup option. |
| SelectedImageSrc | `BitNameSelectorPair<TItem, string?>` | new(nameof(BitChoiceGroupItem<TValue>.SelectedImageSrc)) | Provides a new image for the selected state of the image of the BitChoiceGroup option. |
| Style | `BitNameSelectorPair<TItem, string?>` | new(nameof(BitChoiceGroupItem<TValue>.Style)) | CSS style attribute for the BitChoiceGroup option. |
| Suffix | `BitNameSelectorPair<TItem, string?>` | new(nameof(BitChoiceGroupItem<TValue>.Suffix)) | The text to show as a suffix for the BitChoiceGroup option, rendered after its content. |
| Template | `BitNameSelectorPair<TItem, RenderFragment<TItem>?>` | new(nameof(BitChoiceGroupItem<TValue>.Template)) | Template field name and selector of the custom input class. |
| Text | `BitNameSelectorPair<TItem, string?>` | new(nameof(BitChoiceGroupItem<TValue>.Text)) | Text to show as the content of BitChoiceGroup option. |
| Title | `BitNameSelectorPair<TItem, string?>` | new(nameof(BitChoiceGroupItem<TValue>.Title)) | The title attribute (the native tooltip) of the BitChoiceGroup option. |
| Value | `BitNameSelectorPair<TItem, TValue?>` | new(nameof(BitChoiceGroupItem<TValue>.Value)) | The value returned when BitChoiceGroup option is checked. |
| Index | `string` | nameof(BitChoiceGroupItem<TValue>.Index) | The Index field name of the custom input class. This property's value is set by the component at render. |
| IsSelected | `string` | nameof(BitChoiceGroupItem<TValue>.IsSelected) | The IsSelected field name of the custom input class. This property's value is assigned by the component. |
### BitChoiceGroupClassStyles Properties
| Name | Type | Default Value | Description |
| :--- | :--- | :------------ | :---------- |
| Root | `string?` | null | Custom CSS classes/styles for the root element of the BitChoiceGroup. |
| LabelContainer | `string?` | null | Custom CSS classes/styles for the label container of the BitChoiceGroup. |
| Label | `string?` | null | Custom CSS classes/styles for the label of the BitChoiceGroup. |
| Description | `string?` | null | Custom CSS classes/styles for the description (helper text) of the BitChoiceGroup. |
| Container | `string?` | null | Custom CSS classes/styles for the container of the BitChoiceGroup. |
| ItemChecked | `string?` | null | Custom CSS classes/styles for the checked item of the BitChoiceGroup, applied on top of ItemContainer. |
| ItemDisabled | `string?` | null | Custom CSS classes/styles for a disabled item of the BitChoiceGroup, whether the item itself or the whole group is disabled, applied on top of ItemContainer. |
| ItemContainer | `string?` | null | Custom CSS classes/styles for the container of each item of the BitChoiceGroup. |
| ItemLabel | `string?` | null | Custom CSS classes/styles for the label of each item of the BitChoiceGroup. |
| ItemImageContainer | `string?` | null | Custom CSS classes/styles for the image container of each item of the BitChoiceGroup. |
| ItemImageWrapper | `string?` | null | Custom CSS classes/styles for the image wrapper of each item of the BitChoiceGroup. |
| ItemRadioButton | `string?` | null | Custom CSS classes/styles for the radio button of each item of the BitChoiceGroup. |
| ItemImage | `string?` | null | Custom CSS classes/styles for the image of each item of the BitChoiceGroup. |
| ItemIconWrapper | `string?` | null | Custom CSS classes/styles for the icon wrapper of each item of the BitChoiceGroup. |
| ItemIcon | `string?` | null | Custom CSS classes/styles for the icon of each item of the BitChoiceGroup. |
| ItemPrefix | `string?` | null | Custom CSS classes/styles for the prefix of each item of the BitChoiceGroup. |
| ItemSuffix | `string?` | null | Custom CSS classes/styles for the suffix of each item of the BitChoiceGroup. |
| ItemTextWrapper | `string?` | null | Custom CSS classes/styles for the text wrapper of each item of the BitChoiceGroup. |
| ItemText | `string?` | null | Custom CSS classes/styles for the text of each item of the BitChoiceGroup. |
| ItemDescription | `string?` | null | Custom CSS classes/styles for the description of each item of the BitChoiceGroup. |
### BitIconInfo Properties
| Name | Type | Default Value | Description |
| :--- | :--- | :------------ | :---------- |
| Name | `string?` | null | Gets or sets the name of the icon. |
| BaseClass | `string?` | null | Gets or sets the base CSS class for the icon. For built-in Fluent UI icons, this defaults to "bit-icon". For external icon libraries like FontAwesome, you might set this to "fa" or leave empty. |
| Prefix | `string?` | null | Gets or sets the CSS class prefix used before the icon name. For built-in Fluent UI icons, this defaults to "bit-icon--". For external icon libraries, you might set this to "fa-" or leave empty. |
## CSS Variables
Public CSS custom properties read off the component's root. Set one on `:root` to restyle every instance, on any ancestor to restyle the ones inside it, or on the `Style` of one instance.
| Name | Default Value | Description |
| :--- | :------------ | :---------- |
| `--bit-ChoiceGroup-color` | The Color role's main color | Accent of the checked state: the ring and the dot of the checked circle, and the border of a checked card. |
| `--bit-ChoiceGroup-hover-color` | The Color role's hover color | Accent while an item is hovered (pointer devices only). |
| `--bit-ChoiceGroup-disabled-color` | The Color role's disabled color | Ring and dot of the circle of a disabled item. |
| `--bit-ChoiceGroup-disabled-text-color` | The Color role's disabled text color | Text, description and icon of a disabled item. |
| `--bit-ChoiceGroup-focus-color` | The Color role's focus color | Color of the focus ring drawn around the focused item. |
| `--bit-ChoiceGroup-invalid-color` | --bit-clr-err | Circle and card border while the group is invalid. The focus ring keeps its own error color. |
| `--bit-ChoiceGroup-padding` | spacing(1) | Padding of the group, around the label, the description and the items. |
| `--bit-ChoiceGroup-gap` | Per size and orientation | Space between the items. The Gap parameter sets the same value on one instance and wins over this. |
| `--bit-ChoiceGroup-font-size` | Per size, from the type ramp | Text size of the items. |
| `--bit-ChoiceGroup-label-color` | Inherited | Color of the group label. |
| `--bit-ChoiceGroup-label-font-size` | Inherited | Text size of the group label. |
| `--bit-ChoiceGroup-label-font-weight` | --bit-tpg-fw-semibold | Weight of the group label. |
| `--bit-ChoiceGroup-required-color` | --bit-clr-req | Color of the asterisk Required adds to the label. |
| `--bit-ChoiceGroup-description-color` | --bit-clr-fg-sec | Color of the helper text of the group. |
| `--bit-ChoiceGroup-description-font-size` | Per size, from the type ramp | Text size of the helper text of the group. |
| `--bit-ChoiceGroup-circle-size` | Per size, --bit-siz-sel-* | Diameter of the radio circle. |
| `--bit-ChoiceGroup-circle-color` | --bit-clr-brd-pri | Ring color of an unchecked circle. |
| `--bit-ChoiceGroup-circle-hover-color` | --bit-clr-brd-pri-hover | Ring color of the circle of a hovered unchecked item. |
| `--bit-ChoiceGroup-circle-border-width` | --bit-shp-brd-width | Stroke of the ring of the circle. |
| `--bit-ChoiceGroup-dot-size` | Per size | Diameter of the dot inside a checked circle. |
| `--bit-ChoiceGroup-dot-hover-color` | --bit-clr-fg-sec-hover | The dot a hovered unchecked item previews before it is picked. |
| `--bit-ChoiceGroup-icon-size` | Per size | Size of the icon of an item, both as a tile and inline. |
| `--bit-ChoiceGroup-item-content-gap` | spacing(0.75) | Room between the circle and the content of an item. |
| `--bit-ChoiceGroup-item-min-height` | The circle size plus its air | Smallest height of the row of an item, which is its pointer target. Set it to 44px for a comfortable touch target, which is what an item with no circle and a single line of text needs most. |
| `--bit-ChoiceGroup-item-min-width` | 24px | Smallest width of an item, the other half of its pointer target. The default is the 24px WCAG 2.2 SC 2.5.8 floor, which only a NoCircle item with a very short text ever reaches. |
| `--bit-ChoiceGroup-item-padding` | 0, and per size in the card variants | Padding inside an item. |
| `--bit-ChoiceGroup-item-radius` | --bit-shp-radius-control, --bit-shp-radius-surface for a card | Corner radius of an item; the focus ring follows it. |
| `--bit-ChoiceGroup-item-color` | Inherited | Text color of an item. |
| `--bit-ChoiceGroup-item-checked-color` | Inherited | Text color of the checked item. |
| `--bit-ChoiceGroup-item-background` | Per Color for an icon or image tile, and per variant for a card | Background of the surface an item draws at rest: the icon or image tile, and the card of the Outline and Fill variants. A plain text item draws no surface of its own, and the Inline mode drops the tile. |
| `--bit-ChoiceGroup-item-hover-background` | Per variant | Background of a hovered card. |
| `--bit-ChoiceGroup-item-checked-background` | Per variant | Background of the checked card. |
| `--bit-ChoiceGroup-item-border-color` | Per variant | Border of a card at rest. |
| `--bit-ChoiceGroup-item-hover-border-color` | The Color role's hover color | Border of a hovered card. |
| `--bit-ChoiceGroup-item-checked-border-color` | The Color role's main color | Border of the checked card. |
| `--bit-ChoiceGroup-item-border-width` | --bit-shp-brd-width | Border stroke of a card and of an icon or image tile. |
| `--bit-ChoiceGroup-item-checked-font-weight` | --bit-tpg-fw-bold | Weight of the text of the checked item. |
| `--bit-ChoiceGroup-item-description-color` | --bit-clr-fg-sec | Color of the description of an item. |
| `--bit-ChoiceGroup-item-description-font-size` | Per size, from the type ramp | Text size of the description of an item. |
## Examples
Item
Custom
Option
\n**Basic**:
```razor
```
```csharp
private readonly List> basicItems =
[
new() { Text = "Item A", Value = "A" },
new() { Text = "Item B", Value = "B" },
new() { Text = "Item C", Value = "C" },
new() { Text = "Item D", Value = "D" }
];
```
\n**Disabled & ReadOnly**:
```razor
```
```csharp
private string readOnlyValue = "A";
private readonly List> basicItems =
[
new() { Text = "Item A", Value = "A" },
new() { Text = "Item B", Value = "B" },
new() { Text = "Item C", Value = "C" },
new() { Text = "Item D", Value = "D" }
];
private readonly List> disabledItems =
[
new() { Text = "Item A", Value = "A" },
new() { Text = "Item B", Value = "B" },
new() { Text = "Item C", Value = "C", IsEnabled = false },
new() { Text = "Item D", Value = "D" }
];
```
\n**Images and Icons**:
```razor
```
```csharp
private readonly List> imageItems =
[
new()
{
Text = "Bar",
Value = "Bar",
ImageAlt = "alt for Bar image",
ImageSize = new BitImageSize(32, 32),
ImageSrc= "https://static2.sharepointonline.com/files/fabric/office-ui-fabric-react-assets/choicegroup-bar-unselected.png",
SelectedImageSrc = "https://static2.sharepointonline.com/files/fabric/office-ui-fabric-react-assets/choicegroup-bar-selected.png",
},
new()
{
Text = "Pie",
Value = "Pie",
ImageAlt = "alt for Pie image",
ImageSize = new BitImageSize(32, 32),
ImageSrc= "https://static2.sharepointonline.com/files/fabric/office-ui-fabric-react-assets/choicegroup-pie-unselected.png",
SelectedImageSrc = "https://static2.sharepointonline.com/files/fabric/office-ui-fabric-react-assets/choicegroup-pie-selected.png",
}
];
private readonly List> inlineImageItems =
[
new()
{
Text = "Bar",
Value = "Bar",
ImageAlt = "alt for Bar image",
ImageSize = new BitImageSize(20, 20),
ImageSrc= "https://static2.sharepointonline.com/files/fabric/office-ui-fabric-react-assets/choicegroup-bar-unselected.png",
SelectedImageSrc = "https://static2.sharepointonline.com/files/fabric/office-ui-fabric-react-assets/choicegroup-bar-selected.png",
},
new()
{
Text = "Pie",
Value = "Pie",
ImageAlt = "alt for Pie image",
ImageSize = new BitImageSize(20, 20),
ImageSrc= "https://static2.sharepointonline.com/files/fabric/office-ui-fabric-react-assets/choicegroup-pie-unselected.png",
SelectedImageSrc = "https://static2.sharepointonline.com/files/fabric/office-ui-fabric-react-assets/choicegroup-pie-selected.png",
}
];
private readonly List> iconItems =
[
new() { Text = "Day", Value = "Day", IconName = BitIconName.CalendarDay },
new() { Text = "Week", Value = "Week", IconName = BitIconName.CalendarWeek },
new() { Text = "Month", Value = "Month", IconName = BitIconName.Calendar, IsEnabled = false }
];
```
\n**LabelTemplate**:
```razor
```
```csharp
private readonly List> basicItems =
[
new() { Text = "Item A", Value = "A" },
new() { Text = "Item B", Value = "B" },
new() { Text = "Item C", Value = "C" },
new() { Text = "Item D", Value = "D" }
];
```
\n**Item templates**:
```razor
@(item.Index + 1).
(@item.Value)
@item.Text
```
```csharp
private string itemTemplateValue = "Day";
private string itemTemplateValue2 = "Day";
private string itemLabelTemplateValue = "Day";
private readonly List> basicItems =
[
new() { Text = "Item A", Value = "A" },
new() { Text = "Item B", Value = "B" },
new() { Text = "Item C", Value = "C" },
new() { Text = "Item D", Value = "D" }
];
private readonly List> itemLabelTemplates =
[
new() { Text = "Day", Value = "Day", IconName = BitIconName.CalendarDay },
new() { Text = "Week", Value = "Week", IconName = BitIconName.CalendarWeek },
new() { Text = "Month", Value = "Month", IconName = BitIconName.Calendar }
];
private readonly List> itemTemplateItems =
[
new() { Text = "Day", Value = "Day" },
new() { Text = "Week", Value = "Week" },
new() { Text = "Month", Value = "Month" }
];
private List> itemTemplateItems2 = default!;
protected override void OnInitialized()
{
itemTemplateItems2 = new()
{
new()
{
Text = "Day",
Value = "Day",
Template = (item => @
Submit
```
```csharp
public class ChoiceGroupValidationModel
{
[Required(ErrorMessage = "Pick one")]
public string Value { get; set; }
}
public ChoiceGroupValidationModel validationModel = new();
private void HandleValidSubmit() { }
private void HandleInvalidSubmit() { }
private readonly List> basicItems =
[
new() { Text = "Item A", Value = "A" },
new() { Text = "Item B", Value = "B" },
new() { Text = "Item C", Value = "C" },
new() { Text = "Item D", Value = "D" }
];
```
\n**Item descriptions**:
```razor
```
```csharp
private readonly List> descriptionItems =
[
new() { Text = "Daily", Value = "Daily", Description = "Backs up every night at 2 AM." },
new() { Text = "Weekly", Value = "Weekly", Description = "Backs up every Sunday at 2 AM." },
new() { Text = "Monthly", Value = "Monthly", Description = "Backs up on the first day of each month." }
];
```
\n**Gap**:
```razor
```
```csharp
private readonly List> basicItems =
[
new() { Text = "Item A", Value = "A" },
new() { Text = "Item B", Value = "B" },
new() { Text = "Item C", Value = "C" },
new() { Text = "Item D", Value = "D" }
];
```
\n**Prefix & Suffix**:
```razor
```
```csharp
private readonly List> prefixItems =
[
new() { Text = "Standard", Value = "Standard", Prefix = "$0 - " },
new() { Text = "Express", Value = "Express", Prefix = "$10 - " },
new() { Text = "Overnight", Value = "Overnight", Prefix = "$25 - " }
];
private readonly List> suffixItems =
[
new() { Text = "Standard", Value = "Standard", Suffix = "Free" },
new() { Text = "Express", Value = "Express", Suffix = "$10" },
new() { Text = "Overnight", Value = "Overnight", Suffix = "$25" }
];
```
\n**Events**:
```razor
> basicItems =
[
new() { Text = "Item A", Value = "A" },
new() { Text = "Item B", Value = "B" },
new() { Text = "Item C", Value = "C" },
new() { Text = "Item D", Value = "D" }
];
```
\n**Dynamic items**:
```razor
Add item
Remove item
Reverse items
@(item.Index + 1).
```
```csharp
private int dynamicCounter = 3;
private string? dynamicValue = "1";
private List> dynamicItems =
[
new() { Text = "Item 1", Value = "1" },
new() { Text = "Item 2", Value = "2" },
new() { Text = "Item 3", Value = "3" }
];
private void AddDynamicItem()
{
dynamicCounter++;
dynamicItems = [.. dynamicItems, new BitChoiceGroupItem { Text = $"Item {dynamicCounter}", Value = $"{dynamicCounter}" }];
}
private void RemoveDynamicItem()
{
if (dynamicItems.Count <= 1) return;
dynamicItems = [.. dynamicItems.Take(dynamicItems.Count - 1)];
}
private void ReverseDynamicItems()
{
dynamicItems = [.. Enumerable.Reverse(dynamicItems)];
}
```
\n**Group description**:
```razor
Only the selected environment receives the new build.
```
```csharp
private readonly List> deploymentItems =
[
new() { Text = "Development", Value = "Development" },
new() { Text = "Staging", Value = "Staging" },
new() { Text = "Production", Value = "Production" }
];
```
\n**Item title**:
```razor
```
```csharp
private readonly List> titleItems =
[
new() { Text = "1 h", Value = "1h", Title = "Delivered within one hour of dispatch" },
new() { Text = "24 h", Value = "24h", Title = "Delivered within one business day" },
new() { Text = "72 h", Value = "72h", Title = "Delivered within three business days" }
];
```
\n**Variant**:
```razor
```
```csharp
private readonly List> descriptionItems =
[
new() { Text = "Daily", Value = "Daily", Description = "Backs up every night at 2 AM." },
new() { Text = "Weekly", Value = "Weekly", Description = "Backs up every Sunday at 2 AM." },
new() { Text = "Monthly", Value = "Monthly", Description = "Backs up on the first day of each month." }
];
private readonly List> iconItems =
[
new() { Text = "Day", Value = "Day", IconName = BitIconName.CalendarDay },
new() { Text = "Week", Value = "Week", IconName = BitIconName.CalendarWeek },
new() { Text = "Month", Value = "Month", IconName = BitIconName.Calendar, IsEnabled = false }
];
```
\n**Accessibility**:
```razor
Focus the ChoiceGroup below
```
```csharp
private BitChoiceGroup, string>? focusRef;
private readonly List> sortItems =
[
new() { Text = "Ascending", Value = "Asc" },
new() { Text = "Descending", Value = "Desc" }
];
private readonly List> densityItems =
[
new() { Text = "Compact", Value = "Compact" },
new() { Text = "Cozy", Value = "Cozy" },
new() { Text = "Comfortable", Value = "Comfortable" }
];
private readonly List> ratingItems =
[
new() { Text = "1", Value = "1", AriaLabel = "1 star" },
new() { Text = "2", Value = "2", AriaLabel = "2 stars" },
new() { Text = "3", Value = "3", AriaLabel = "3 stars" },
new() { Text = "4", Value = "4", AriaLabel = "4 stars" },
new() { Text = "5", Value = "5", AriaLabel = "5 stars" }
];
private readonly List> basicItems =
[
new() { Text = "Item A", Value = "A" },
new() { Text = "Item B", Value = "B" },
new() { Text = "Item C", Value = "C" },
new() { Text = "Item D", Value = "D" }
];
```
\n**Cascading parameters**:
```razor
```
```csharp
private readonly BitChoiceGroupParams[] choiceGroupParams =
[
new()
{
Gap = "0.5rem",
FullWidth = true,
Variant = BitVariant.Outline,
}
];
```
\n**Color**:
```razor
```
```csharp
private readonly List> basicItems =
[
new() { Text = "Item A", Value = "A" },
new() { Text = "Item B", Value = "B" },
new() { Text = "Item C", Value = "C" },
new() { Text = "Item D", Value = "D" }
];
```
\n**External Icons**:
```razor
```
```csharp
private readonly List> externalIconItems =
[
new() { Text = "Day", Value = "Day", Icon = BitIconInfo.Fa("solid sun") },
new() { Text = "Week", Value = "Week", Icon = BitIconInfo.Css("fa-solid fa-calendar-week") },
new() { Text = "Month", Value = "Month", Icon = BitIconInfo.Bi("calendar-month") }
];
```
\n**Size**:
```razor
```
```csharp
private readonly List> basicItems =
[
new() { Text = "Item A", Value = "A" },
new() { Text = "Item B", Value = "B" },
new() { Text = "Item C", Value = "C" },
new() { Text = "Item D", Value = "D" }
];
private readonly List> iconItems =
[
new() { Text = "Day", Value = "Day", IconName = BitIconName.CalendarDay },
new() { Text = "Week", Value = "Week", IconName = BitIconName.CalendarWeek },
new() { Text = "Month", Value = "Month", IconName = BitIconName.Calendar, IsEnabled = false }
];
```
\n**Style & Class**:
```razor
```
```csharp
private readonly List> basicItems =
[
new() { Text = "Item A", Value = "A" },
new() { Text = "Item B", Value = "B" },
new() { Text = "Item C", Value = "C" },
new() { Text = "Item D", Value = "D" }
];
private readonly List> itemStyleClassItems =
[
new() { Text = "Item A", Value = "A", Class = "custom-item" },
new() { Text = "Item B", Value = "B", Style = "padding: 8px; border-radius: 20px; border: 1px solid gray;" },
new() { Text = "Item C", Value = "C", Class = "custom-item" },
new() { Text = "Item D", Value = "D", Class = "custom-item" }
];
```
Custom label
@item.Text
@item.Text
)
},
new()
{
Text = "Week",
Value = "Week",
Template = (item => @
@item.Text
)
},
new()
{
Text = "Month",
Value = "Month",
Template = (item => @
@item.Text
)
}
};
}
```
\n**Validation**:
```razor
Changed value: @changedValue
Clicked item: @clickedItem
Focused item: @focusedItem
Blurred item: @blurredItem
```
```csharp
private string? changedValue;
private string? clickedItem;
private string? focusedItem;
private string? blurredItem;
private readonly ListHow dense should the rows be?