generated from yii-tools/template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
HasAriaControls.php
41 lines (35 loc) · 1.29 KB
/
HasAriaControls.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
41
<?php
declare(strict_types=1);
namespace UIAwesome\Html\Attribute\Aria;
/**
* Is used by widgets that require the aria-controls attribute.
*/
trait HasAriaControls
{
protected bool|string $ariaControls = false;
/**
* Set the aria-controls attribute, which identifies the element(s) whose contents or presence is controlled by the
* current element.
*
* The aria-controls attribute is used in WAI-ARIA to define a relationship between a controller element and
* controlled elements, typically used for accessibility in web applications.
*
* @param bool|string $value IDs of the controlled element(s) separated by spaces. If the value is `true`, the
* value of the id attribute of the element is used. If the value is `false`, the attribute is removed.
*
* @return static A new instance or clone of the current object with the aria-controls attribute set.
*
* @link https://www.w3.org/TR/wai-aria-1.1/#aria-controls
*/
public function ariaControls(bool|string $value = true): static
{
$new = clone $this;
if ($value === true) {
$new->ariaControls = true;
} else {
$new->ariaControls = false;
$new->attributes['aria-controls'] = $value;
}
return $new;
}
}