Prtksxna has uploaded a new change for review. (
https://gerrit.wikimedia.org/r/338314 )
Change subject: DropdownInputWidget: Add support for 'optgroup'
......................................................................
DropdownInputWidget: Add support for 'optgroup'
This isn't really optgroup because the menu items come after the optgroup
instead of inside it (like in HTML). Uses MenuSectionOption.
Bug: T135028
Change-Id: I3fecde5c529f3c8c75e56d881b58026e8496f237
---
M demos/pages/widgets.js
M src/widgets/DropdownInputWidget.js
2 files changed, 41 insertions(+), 4 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/oojs/ui refs/changes/14/338314/1
diff --git a/demos/pages/widgets.js b/demos/pages/widgets.js
index 4b289ad..a2e27d8 100644
--- a/demos/pages/widgets.js
+++ b/demos/pages/widgets.js
@@ -1370,6 +1370,36 @@
new OO.ui.FieldLayout(
new OO.ui.DropdownInputWidget( {
options: [
+ {
+ optgroup:
'Vowels'
+ },
+ {
+ data: 'a',
+ label: 'A'
+ },
+ {
+ optgroup:
'Consonants'
+ },
+ {
+ data: 'b',
+ label: 'B'
+ },
+ {
+ data: 'c',
+ label: 'C'
+ }
+ ],
+ value: 'b',
+ title: 'Select an item'
+ } ),
+ {
+ label: 'DropdownInputWidget
(with optgroup)',
+ align: 'top'
+ }
+ ),
+ new OO.ui.FieldLayout(
+ new OO.ui.DropdownInputWidget( {
+ options: [
{ data: 'sq', label:
'Albanian' },
{ data: 'frp', label:
'Arpitan' },
{ data: 'ba', label:
'Bashkir' },
diff --git a/src/widgets/DropdownInputWidget.js
b/src/widgets/DropdownInputWidget.js
index 3bcd391..3755584 100644
--- a/src/widgets/DropdownInputWidget.js
+++ b/src/widgets/DropdownInputWidget.js
@@ -120,10 +120,17 @@
.clearItems()
.addItems( options.map( function ( opt ) {
var optValue = widget.cleanUpValue( opt.data );
- return new OO.ui.MenuOptionWidget( {
- data: optValue,
- label: opt.label !== undefined ? opt.label :
optValue
- } );
+
+ if ( opt.optgroup === undefined ) {
+ return new OO.ui.MenuOptionWidget( {
+ data: optValue,
+ label: opt.label !== undefined ?
opt.label : optValue
+ } );
+ } else {
+ return new OO.ui.MenuSectionOptionWidget( {
+ label: opt.optgroup
+ } );
+ }
} ) );
// Restore the previous value, or reset to something sensible
--
To view, visit https://gerrit.wikimedia.org/r/338314
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I3fecde5c529f3c8c75e56d881b58026e8496f237
Gerrit-PatchSet: 1
Gerrit-Project: oojs/ui
Gerrit-Branch: master
Gerrit-Owner: Prtksxna <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits