11/*
2- * Copyright (c) 2022 Brandon Jordan
2+ * Copyright (c) 2023 Brandon Jordan
33 */
44
55import { Element } from '../element.js' ;
66
77export function Dropdown ( options ) {
8- return new DropdownGroup ( options ) ;
8+ return new DropdownGroup ( options ) ;
99}
1010
1111class DropdownGroup extends Element {
12- constructor ( options ) {
13- const select = document . createElement ( 'select' ) ;
14- for ( let option in options ) {
15- if ( options [ option ] . constructor === Object ) {
16- const optgroup = document . createElement ( 'optgroup' ) ;
17- optgroup . label = option ;
18- for ( let groupOption in options [ option ] ) {
19- const optionTag = document . createElement ( 'option' ) ;
20- optionTag . value = groupOption ;
21- optionTag . innerText = options [ option ] [ groupOption ] ;
22- optgroup . appendChild ( optionTag ) ;
23- }
24- select . appendChild ( optgroup ) ;
25- } else {
26- const optionTag = document . createElement ( 'option' ) ;
27- optionTag . value = option ;
28- optionTag . innerText = options [ option ] ;
29- select . appendChild ( optionTag ) ;
30- }
31- }
32- super ( select ) ;
33- this . element = select ;
34- }
12+ constructor ( options ) {
13+ const select = document . createElement ( 'select' ) ;
14+ for ( let option in options ) {
15+ if ( options [ option ] . constructor === Object ) {
16+ const optgroup = document . createElement ( 'optgroup' ) ;
17+ optgroup . label = option ;
18+ for ( let groupOption in options [ option ] ) {
19+ const optionTag = document . createElement ( 'option' ) ;
20+ optionTag . value = groupOption ;
21+ optionTag . innerText = options [ option ] [ groupOption ] ;
22+ optgroup . appendChild ( optionTag ) ;
23+ }
24+ select . appendChild ( optgroup ) ;
25+ } else {
26+ const optionTag = document . createElement ( 'option' ) ;
27+ optionTag . value = option ;
28+ optionTag . innerText = options [ option ] ;
29+ select . appendChild ( optionTag ) ;
30+ }
31+ }
32+ super ( select ) ;
33+ this . element = select ;
34+ }
3535}
0 commit comments