@@ -21,12 +21,17 @@ const selectedTextID = generateRandomID('select-selected-text-')
21
21
22
22
let element = {}
23
23
let mdcSelect = {}
24
+ let previousOptionsIDsCSV = ' '
24
25
25
26
$: selectedIndex = options .findIndex ((option ) => option .id === selectedID)
26
27
$: dispatch (' change' , options[selectedIndex] || {})
27
28
$: mdcSelect .disabled = disabled
28
29
$: if (options && mdcSelect .layoutOptions ) mdcSelect .layoutOptions ()
29
30
31
+ const getIDsCSV = (options ) => options .map (option => option .id ).join (' ,' )
32
+
33
+ const optionsHaveChanged = (options ) => previousOptionsIDsCSV !== getIDsCSV (options)
34
+
30
35
const recordSelectedID = (event ) => (selectedID = event .detail .value )
31
36
32
37
const isOptionSelected = (option ) => option .id === selectedID
@@ -43,10 +48,11 @@ afterUpdate(() => {
43
48
// This makes sure the index is updated AFTER the select list contains the full list of options.
44
49
mdcSelect .selectedIndex = selectedIndex
45
50
46
- // If options have been provided, give the current processes time to finish
51
+ // If options have been provided or changed , give the current processes time to finish
47
52
// what they're doing, then indicate that this Select is now populated with
48
53
// options. At this point, it's safe for the selectedID to be initialized.
49
- if (options .length > 0 ) {
54
+ if (options .length > 0 && optionsHaveChanged (options)) {
55
+ previousOptionsIDsCSV = getIDsCSV (options)
50
56
setTimeout (() => {
51
57
dispatch (' populated' )
52
58
})
0 commit comments