Skip to content

Commit 9ec1381

Browse files
committed
added optgroup and _optgroup elements
1 parent 4a5c253 commit 9ec1381

2 files changed

Lines changed: 28 additions & 3 deletions

File tree

example.php

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,16 @@
4949
"ferrari" => "Ferrari",
5050
"mercedes" => "Mercedes",
5151
"porsche" => "Porsche",
52-
])
52+
]),
53+
$ui::select([
54+
$ui::_optgroup("Sports Cars", [
55+
"ferrari" => "Ferrari",
56+
"porsche" => "Porsche",
57+
]),
58+
$ui::_optgroup("Sports Cars", [
59+
"mercedes" => "Mercedes",
60+
"bently" => "Bently",
61+
])
62+
]),
5363
])
5464
));

src/UI.php

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -831,12 +831,12 @@ public static function option(string $value, string $text = "", array $props = [
831831
* OptionGroup Tag
832832
*
833833
* @param string $label Optgroup label
834-
* @param string $text Text displayed to the user
834+
* @param string $children Element children
835835
* @param array $props Additional props
836836
*/
837837
public static function optgroup(string $label, array $children = [], array $props = []) {
838838
$props["label"] = $label;
839-
return self::create_element("option", $props, $children);
839+
return self::create_element("optgroup", $props, $children);
840840
}
841841

842842
/**
@@ -974,4 +974,19 @@ public static function _select(array $options, array $props = []) {
974974
}
975975
return self::create_element("select", $props, $els);
976976
}
977+
978+
/**
979+
* custom OptionGroup Tag
980+
*
981+
* @param string $label Optgroup label
982+
* @param string $children Element children
983+
* @param array $props Additional props
984+
*/
985+
public static function _optgroup(string $label, array $children = [], array $props = []) {
986+
return self::optgroup($label, [
987+
self::loop($children, function($value, $key) {
988+
return self::option($key, $value);
989+
})
990+
]);
991+
}
977992
}

0 commit comments

Comments
 (0)