HasAria
API reference › HTML Attribute › Global › HasAria
Used by 4 types
Provides an immutable API for aria-* attributes.
See also: https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Reference/Attributes.
Methods
Section titled “Methods”| Method | Description | Defined by |
|---|---|---|
addAriaAttribute() | Sets an aria-* attribute. | HasAria |
ariaAttributes() | Sets multiple aria-* attributes. | HasAria |
removeAriaAttribute() | Removes an aria-* attribute. | HasAria |
Method details
Section titled “Method details”addAriaAttribute()
Section titled “addAriaAttribute() ”public function addAriaAttribute(string|UnitEnum $key, bool|Closure(): mixed|float|int|string|Stringable|UnitEnum|null $value): staticSets an aria-* attribute.
Parameters
| Parameter | Type | Description |
|---|---|---|
$key | string|UnitEnum | Aria attribute key without the aria- prefix. |
$value | bool|Closure(): mixed|Stringable|UnitEnum| | Aria attribute value, or null to remove the attribute. |
Returns
static: New instance with the updated aria-* attribute.
Throws
InvalidArgumentException: if one or more arguments are invalid, of incorrect type or format.
ariaAttributes()
Section titled “ariaAttributes() ”public function ariaAttributes(mixed[] $values): staticSets 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: if one or more arguments are invalid, of incorrect type or format.
removeAriaAttribute()
Section titled “removeAriaAttribute() ”public function removeAriaAttribute(string|UnitEnum $key): staticRemoves an aria-* attribute.
Parameters
| Parameter | Type | Description |
|---|---|---|
$key | string|UnitEnum | Aria attribute key without the aria- prefix. |
Returns
static: New instance with the specified aria-* attribute removed.