File tree Expand file tree Collapse file tree 1 file changed +11
-0
lines changed Expand file tree Collapse file tree 1 file changed +11
-0
lines changed Original file line number Diff line number Diff line change @@ -14,6 +14,7 @@ class Select implements Control
14
14
protected array $ options = [];
15
15
/** @var string[] $values */
16
16
protected array $ values = [];
17
+ protected string $ placeholder = 'Select an option ' ;
17
18
18
19
protected bool $ disabled = false ;
19
20
protected bool $ readonly = false ;
@@ -90,6 +91,12 @@ public function value(string $value): self
90
91
return $ this ;
91
92
}
92
93
94
+ public function placeholder (string $ placeholder ): self
95
+ {
96
+ $ this ->placeholder = $ placeholder ;
97
+ return $ this ;
98
+ }
99
+
93
100
/**
94
101
* @param array<string, string|string[]|null> $data
95
102
*/
@@ -143,6 +150,10 @@ public function renderDom(\DOMDocument $doc): \DOMElement
143
150
if ($ this ->multiple ) {
144
151
$ select ->setAttribute ('multiple ' , 'multiple ' );
145
152
}
153
+ $ option = $ doc ->createElement ('option ' );
154
+ $ option ->setAttribute ('value ' , '' );
155
+ $ option ->textContent = $ this ->placeholder ;
156
+ $ select ->appendChild ($ option );
146
157
foreach ($ this ->options as $ key => $ value ) {
147
158
$ option = $ doc ->createElement ('option ' );
148
159
$ option ->setAttribute ('value ' , strval ($ key ));
You can’t perform that action at this time.
0 commit comments