-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCombo.php
45 lines (35 loc) · 922 Bytes
/
Combo.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
42
43
44
45
<?php declare(strict_types=1);
namespace DynamicComponents\Controls;
class Combo extends \UI\Controls\Combo
{
/** @var int */
private $maxIndex = -1;
/** @var callable|null */
private $onSelected;
public function __construct(?callable $onSelected = null)
{
$this->onSelected = $onSelected;
}
public function append(string $text): void
{
parent::append($text);
$this->maxIndex++;
}
public function setOnSelected(callable $onSelected): void
{
$this->onSelected = $onSelected;
}
public function setSelected(int $index): void
{
if ($index < -1 || ($index > $this->maxIndex && $index !== 0)) {
$index = -1;
}
parent::setSelected($index);
}
protected function onSelected(): void
{
if ($onSelected = $this->onSelected) {
$onSelected($this);
}
}
}