# HasRole

> Provides an immutable API for the role attribute.

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

| trait | `UIAwesome\Html\Attribute\Global\HasRole` |
| --- | --- |
| Source | [`src/Global/HasRole.php`](https://github.com/ui-awesome/html-attribute/blob/main/src/Global/HasRole.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 the `role` attribute.

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

## Methods

| Method | Description | Defined by |
| --- | --- | --- |
| [`role()`](#method-role) | Sets the `role` attribute. | `HasRole` |

## Method details

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

```php
public function role(string|Stringable|UnitEnum|null $value): static
```

Sets the `role` attribute.

**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` | ARIA role, or `null` to remove the attribute. |

**Returns**

`static`: New instance with the updated `role` attribute. [`Role`](/docs/extensions/html-attribute/reference/values/role/index.md) for predefined enum values.

**Throws**

- [`InvalidArgumentException`](https://www.php.net/manual/en/class.invalidargumentexception.php): If the value is not valid.