generated from yii-tools/template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
HasAriaDescribedBy.php
40 lines (34 loc) · 1.21 KB
/
HasAriaDescribedBy.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
<?php
declare(strict_types=1);
namespace UIAwesome\Html\Attribute\Aria;
/**
* Is used by widgets that require the aria-describedby attribute.
*/
trait HasAriaDescribedBy
{
protected bool|string $ariaDescribedBy = false;
/**
* Set the aria-describedby attribute, which identifies the element(s) that describes the current element.
*
* The aria-describedby attribute is used in WAI-ARIA to provide a relationship between an element and its
* descriptive elements. This helps screen readers and other assistive technologies provide additional context
* about the element.
*
* @param bool|string $value IDs of the descriptive element(s) separated by spaces.
*
* @return static A new instance or clone of the current object with the aria-describedby attribute set.
*
* @link https://www.w3.org/TR/wai-aria-1.1/#aria-describedby
*/
public function ariaDescribedBy(bool|string $value = true): static
{
$new = clone $this;
if ($value === true) {
$new->ariaDescribedBy = true;
} else {
$new->ariaDescribedBy = false;
$new->attributes['aria-describedby'] = $value;
}
return $new;
}
}