Skip to content
PHP Ecosystem
Explore

HasAria

API reference › HTML Attribute › Global › HasAria

traitUIAwesome\Html\Attribute\Global\HasAria
Sourcesrc/Global/HasAria.php
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.

MethodDescriptionDefined by
addAriaAttribute()Sets an aria-* attribute.HasAria
ariaAttributes()Sets multiple aria-* attributes.HasAria
removeAriaAttribute()Removes an aria-* attribute.HasAria
public function addAriaAttribute(string|UnitEnum $key, bool|Closure(): mixed|float|int|string|Stringable|UnitEnum|null $value): static

Sets an aria-* attribute.

Parameters

ParameterTypeDescription
$keystring|UnitEnumAria attribute key without the aria- prefix.
$valuebool|Closure(): mixed|float|int|string|Stringable|UnitEnum|nullAria attribute value, or null to remove the attribute.

Returns

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

Throws

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

Sets multiple aria-* attributes.

Parameters

ParameterTypeDescription
$valuesmixed[]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

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

Removes an aria-* attribute.

Parameters

ParameterTypeDescription
$keystring|UnitEnumAria attribute key without the aria- prefix.

Returns

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