# ChoiceItem

> Defines one value and label rendered by a checkbox or radio list.

[API reference](/docs/api/index.md) › [HTML](/docs/extensions/html/reference/index.md) › [Form](/docs/extensions/html/reference/form/index.md) › ChoiceItem

| final class | `UIAwesome\Html\Form\ChoiceItem` |
| --- | --- |
| Source | [`src/Form/ChoiceItem.php`](https://github.com/ui-awesome/html/blob/main/src/Form/ChoiceItem.php#L22) |

Defines one value and label rendered by a checkbox or radio list.

The item carries no name, id, or checked state: [`AbstractChoiceList`](/docs/extensions/html/reference/form/abstractchoicelist/index.md) derives them from the list and passes them
in on render.

[`CheckboxList`](/docs/extensions/html/reference/form/checkboxlist/index.md) and [`RadioList`](/docs/extensions/html/reference/form/radiolist/index.md) for the lists rendering the items.

## Methods

| Method | Description | Defined by |
| --- | --- | --- |
| [`label()`](#method-label) | Sets the item label. | `ChoiceItem` |
| [`labelAttributes()`](#method-labelAttributes) | Sets attributes applied to the item label. | `ChoiceItem` |
| [`labelClass()`](#method-labelClass) | Adds a CSS class to the item label. | `ChoiceItem` |
| [`tag()`](#method-tag) static | Creates a choice item. | `ChoiceItem` |
| [`value()`](#method-value) | Sets the submitted item value. | `ChoiceItem` |

## Method details

### label() <span id="method-label"></span>

```php
public function label(string|Stringable $value): self
```

Sets the item label.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$value` | `string\|`[`Stringable`](https://www.php.net/manual/en/class.stringable.php) | Label text, encoded on render. |

**Returns**

`self`: New instance with the updated label.

### labelAttributes() <span id="method-labelAttributes"></span>

```php
public function labelAttributes(mixed[] $values): self
```

Sets attributes applied to the item label.

Merges with the attributes already configured, so consecutive calls accumulate.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$values` | `mixed[]` | Label attributes indexed by attribute name. |

**Returns**

`self`: New instance with the updated label attributes.

### labelClass() <span id="method-labelClass"></span>

```php
public function labelClass(string|Stringable|UnitEnum|null $value, bool $override = false): self
```

Adds a CSS class to the item label.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$value` | `string\|`[`Stringable`](https://www.php.net/manual/en/class.stringable.php)`\|`[`UnitEnum`](https://www.php.net/manual/en/class.unitenum.php)`\|null` | Class name, or `null` to remove the attribute. |
| `$override` | `bool` | Whether to replace the existing classes instead of merging them. |

**Returns**

`self`: New instance with the updated label class.

### tag() <span id="method-tag"></span>

```php
public static function tag(): self
```

Creates a choice item.

**Returns**

`self`: New item instance.

### value() <span id="method-value"></span>

```php
public function value(bool|float|int|string|Stringable|UnitEnum|null $value): self
```

Sets the submitted item value.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$value` | `bool\|float\|int\|string\|`[`Stringable`](https://www.php.net/manual/en/class.stringable.php)`\|`[`UnitEnum`](https://www.php.net/manual/en/class.unitenum.php)`\|null` | Submitted value, or `null` to remove the attribute. |

**Returns**

`self`: New instance with the updated value.