@@ -80,8 +80,7 @@ const Default = {
80
80
searchPlaceholder : 'Select...' ,
81
81
selection : true ,
82
82
selectionType : 'counter' ,
83
- selectionTypeCounterText : 'item(s) selected' ,
84
- selected : [ ]
83
+ selectionTypeCounterText : 'item(s) selected'
85
84
}
86
85
87
86
const DefaultType = {
@@ -93,8 +92,7 @@ const DefaultType = {
93
92
searchPlaceholder : 'string' ,
94
93
selection : 'boolean' ,
95
94
selectionType : 'string' ,
96
- selectionTypeCounterText : 'string' ,
97
- selected : 'array'
95
+ selectionTypeCounterText : 'string'
98
96
}
99
97
100
98
/**
@@ -107,7 +105,6 @@ class MultiSelect extends BaseComponent {
107
105
constructor ( element , config ) {
108
106
super ( element )
109
107
110
- this . _element = element
111
108
this . _selectionElement = null
112
109
this . _selectionCleanerElement = null
113
110
this . _searchElement = null
@@ -143,10 +140,6 @@ class MultiSelect extends BaseComponent {
143
140
144
141
// Public
145
142
146
- update ( config ) { // public method
147
- this . _getConfig ( config )
148
- }
149
-
150
143
show ( ) {
151
144
EventHandler . trigger ( this . _element , EVENT_SHOW )
152
145
this . _clone . classList . add ( CLASS_NAME_SHOW )
@@ -170,6 +163,21 @@ class MultiSelect extends BaseComponent {
170
163
EventHandler . trigger ( this . _element , EVENT_SEARCH )
171
164
}
172
165
166
+ update ( config ) {
167
+ this . _config = this . _getConfig ( config )
168
+ this . _options = this . _getOptions ( )
169
+ this . _selection = this . _getSelectedOptions ( this . _options )
170
+ this . _clone . remove ( )
171
+ this . _element . innerHTML = ''
172
+ this . _createNativeOptions ( this . _element , this . _options )
173
+ this . _createSelect ( )
174
+ this . _addEventListeners ( )
175
+ }
176
+
177
+ getValue ( ) {
178
+ return this . _selection
179
+ }
180
+
173
181
// Private
174
182
175
183
_addEventListeners ( ) {
@@ -215,20 +223,13 @@ class MultiSelect extends BaseComponent {
215
223
} )
216
224
}
217
225
218
- _getConfig ( config , update ) {
219
- if ( update !== true ) {
220
- config = {
221
- ...this . constructor . Default ,
222
- ...Manipulator . getDataAttributes ( this . _element ) ,
223
- ...config
224
- }
226
+ _getConfig ( config ) {
227
+ config = {
228
+ ...Default ,
229
+ ...Manipulator . getDataAttributes ( this . _element ) ,
230
+ ...config
225
231
}
226
-
227
- typeCheckConfig (
228
- NAME ,
229
- config ,
230
- this . constructor . DefaultType
231
- )
232
+ typeCheckConfig ( NAME , config , DefaultType )
232
233
233
234
return config
234
235
}
@@ -304,7 +305,7 @@ class MultiSelect extends BaseComponent {
304
305
305
306
this . _createNativeOptions ( select , data )
306
307
307
- this . _element . parentNode . replaceChild ( select , this . _element )
308
+ this . _element . replaceWith ( select )
308
309
this . _element = select
309
310
}
310
311
@@ -320,7 +321,7 @@ class MultiSelect extends BaseComponent {
320
321
const opt = document . createElement ( 'OPTION' )
321
322
opt . value = option . value
322
323
if ( option . selected === true ) {
323
- opt . selected = true
324
+ opt . setAttribute ( ' selected' , 'selected' )
324
325
}
325
326
326
327
opt . innerHTML = option . text
@@ -732,9 +733,19 @@ class MultiSelect extends BaseComponent {
732
733
733
734
// Static
734
735
735
- static _multiSelectInterface ( element , config ) {
736
+ static multiSelectInterface ( element , config ) {
736
737
let data = Data . getData ( element , DATA_KEY )
737
- const _config = typeof config === 'object' && config
738
+ let _config = {
739
+ ...Default ,
740
+ ...Manipulator . getDataAttributes ( element )
741
+ }
742
+
743
+ if ( typeof config === 'object' ) {
744
+ _config = {
745
+ ..._config ,
746
+ ...config
747
+ }
748
+ }
738
749
739
750
if ( ! data ) {
740
751
data = new MultiSelect ( element , _config )
@@ -751,25 +762,7 @@ class MultiSelect extends BaseComponent {
751
762
752
763
static jQueryInterface ( config ) {
753
764
return this . each ( function ( ) {
754
- let data = Data . getData ( this , DATA_KEY )
755
-
756
- if ( ! data ) {
757
- data = new MultiSelect ( this )
758
- }
759
-
760
- // eslint-disable-next-line default-case
761
- switch ( config ) {
762
- // case 'update':
763
- // data[config](this, par)
764
- // break
765
- case 'dispose' :
766
- case 'open' :
767
- case 'close' :
768
- case 'search' :
769
- case 'value' :
770
- data [ config ] ( this )
771
- break
772
- }
765
+ MultiSelect . multiSelectInterface ( this , config )
773
766
} )
774
767
}
775
768
@@ -816,11 +809,14 @@ class MultiSelect extends BaseComponent {
816
809
* ------------------------------------------------------------------------
817
810
*/
818
811
EventHandler . on ( window , EVENT_LOAD_DATA_API , ( ) => {
819
- // eslint-disable-next-line unicorn/prefer-spread
820
- Array . from ( document . querySelectorAll ( SELECTOR_SELECT ) ) . forEach ( element => {
821
- MultiSelect . _multiSelectInterface ( element )
822
- } )
812
+ SelectorEngine . find ( SELECTOR_SELECT )
813
+ . forEach ( ms => {
814
+ if ( ms . tabIndex !== - 1 ) {
815
+ MultiSelect . multiSelectInterface ( ms )
816
+ }
817
+ } )
823
818
} )
819
+
824
820
EventHandler . on ( document , EVENT_CLICK_DATA_API , MultiSelect . clearMenus )
825
821
EventHandler . on ( document , EVENT_KEYUP_DATA_API , MultiSelect . clearMenus )
826
822
0 commit comments