Skip to content

Commit aa36e72

Browse files
committed
update
1 parent 67c3e15 commit aa36e72

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

src/Select.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ class Select implements Control
1414
protected array $options = [];
1515
/** @var string[] $values */
1616
protected array $values = [];
17+
protected string $placeholder = 'Select an option';
1718

1819
protected bool $disabled = false;
1920
protected bool $readonly = false;
@@ -90,6 +91,12 @@ public function value(string $value): self
9091
return $this;
9192
}
9293

94+
public function placeholder(string $placeholder): self
95+
{
96+
$this->placeholder = $placeholder;
97+
return $this;
98+
}
99+
93100
/**
94101
* @param array<string, string|string[]|null> $data
95102
*/
@@ -143,6 +150,10 @@ public function renderDom(\DOMDocument $doc): \DOMElement
143150
if ($this->multiple) {
144151
$select->setAttribute('multiple', 'multiple');
145152
}
153+
$option = $doc->createElement('option');
154+
$option->setAttribute('value', '');
155+
$option->textContent = $this->placeholder;
156+
$select->appendChild($option);
146157
foreach ($this->options as $key => $value) {
147158
$option = $doc->createElement('option');
148159
$option->setAttribute('value', strval($key));

0 commit comments

Comments
 (0)