@@ -152,7 +152,9 @@ class UI5Element extends HTMLElement {
152
152
}
153
153
154
154
const autoIncrementMap = new Map ( ) ;
155
- const allChildrenUpgraded = domChildren . map ( async child => {
155
+ const slottedChildrenMap = new Map ( ) ;
156
+
157
+ const allChildrenUpgraded = domChildren . map ( async ( child , idx ) => {
156
158
// Determine the type of the child (mainly by the slot attribute)
157
159
const slotName = this . constructor . _getSlotName ( child ) ;
158
160
const slotData = slotsMap [ slotName ] ;
@@ -192,12 +194,22 @@ class UI5Element extends HTMLElement {
192
194
this . _attachChildPropertyUpdated ( child , slotData ) ;
193
195
}
194
196
195
- // Distribute the child in the _state object
196
197
const propertyName = slotData . propertyName || slotName ;
197
- this . _state [ propertyName ] . push ( child ) ;
198
+
199
+ if ( slottedChildrenMap . has ( propertyName ) ) {
200
+ slottedChildrenMap . get ( propertyName ) . push ( { child, idx } ) ;
201
+ } else {
202
+ slottedChildrenMap . set ( propertyName , [ { child, idx } ] ) ;
203
+ }
198
204
} ) ;
199
205
200
206
await Promise . all ( allChildrenUpgraded ) ;
207
+
208
+ // Distribute the child in the _state object, keeping the Light DOM order,
209
+ // not the order elements are defined.
210
+ slottedChildrenMap . forEach ( ( children , slot ) => {
211
+ this . _state [ slot ] = children . sort ( ( a , b ) => a . idx - b . idx ) . map ( _ => _ . child ) ;
212
+ } ) ;
201
213
this . _invalidate ( ) ;
202
214
}
203
215
0 commit comments