# HasAria

> Provides an immutable API for aria-* attributes.

[API reference](/docs/api/index.md) › [HTML Attribute](/docs/extensions/html-attribute/reference/index.md) › [Global](/docs/extensions/html-attribute/reference/global/index.md) › HasAria

| trait | `UIAwesome\Html\Attribute\Global\HasAria` |
| --- | --- |
| Source | [`src/Global/HasAria.php`](https://github.com/ui-awesome/html-attribute/blob/main/src/Global/HasAria.php#L20) |

Used by 4 types:

- [`UIAwesome\Html\Core\Element\BaseBlock`](/docs/extensions/html-core/reference/element/baseblock/index.md)
- [`UIAwesome\Html\Core\Element\BaseInline`](/docs/extensions/html-core/reference/element/baseinline/index.md)
- [`UIAwesome\Html\Core\Element\BaseInput`](/docs/extensions/html-core/reference/element/baseinput/index.md)
- [`UIAwesome\Html\Core\Element\BaseVoid`](/docs/extensions/html-core/reference/element/basevoid/index.md)

Provides an immutable API for `aria-*` attributes.

See also: <https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Reference/Attributes>.

## Methods

| Method | Description | Defined by |
| --- | --- | --- |
| [`addAriaAttribute()`](#method-addAriaAttribute) | Sets an `aria-*` attribute. | `HasAria` |
| [`ariaAttributes()`](#method-ariaAttributes) | Sets multiple `aria-*` attributes. | `HasAria` |
| [`removeAriaAttribute()`](#method-removeAriaAttribute) | Removes an `aria-*` attribute. | `HasAria` |

## Method details

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

```php
public function addAriaAttribute(string|UnitEnum $key, bool|Closure(): mixed|float|int|string|Stringable|UnitEnum|null $value): static
```

Sets an `aria-*` attribute.

**Parameters**

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

**Returns**

`static`: New instance with the updated `aria-*` attribute.

**Throws**

- [`InvalidArgumentException`](https://www.php.net/manual/en/class.invalidargumentexception.php): if one or more arguments are invalid, of incorrect type or format.

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

```php
public function ariaAttributes(mixed[] $values): static
```

Sets multiple `aria-*` attributes.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$values` | `mixed[]` | Associative array of aria keys and values. Values may be scalar, Stringable, UnitEnum, Closure, or `null` to remove the attribute. |

**Returns**

`static`: New instance with the updated `aria-*` attributes.

**Throws**

- [`InvalidArgumentException`](https://www.php.net/manual/en/class.invalidargumentexception.php): if one or more arguments are invalid, of incorrect type or format.

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

```php
public function removeAriaAttribute(string|UnitEnum $key): static
```

Removes an `aria-*` attribute.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$key` | `string\|`[`UnitEnum`](https://www.php.net/manual/en/class.unitenum.php) | Aria attribute key without the `aria-` prefix. |

**Returns**

`static`: New instance with the specified `aria-*` attribute removed.