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
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 ));
You can’t perform that action at this time.
0 commit comments