Skip to content

Commit

Permalink
fix: order slots in state as in Light DOM (#874)
Browse files Browse the repository at this point in the history
FIXES: #873

Order slotted children in components state properly, keeping their order in the Light DOM, not the order the children are defined
  • Loading branch information
ilhan007 committed Oct 22, 2019
1 parent 344340c commit b8efea0
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions packages/base/src/UI5Element.js
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,9 @@ class UI5Element extends HTMLElement {
}

const autoIncrementMap = new Map();
const allChildrenUpgraded = domChildren.map(async child => {
const slottedChildrenMap = new Map();

const allChildrenUpgraded = domChildren.map(async (child, idx) => {
// Determine the type of the child (mainly by the slot attribute)
const slotName = this.constructor._getSlotName(child);
const slotData = slotsMap[slotName];
Expand Down Expand Up @@ -192,12 +194,22 @@ class UI5Element extends HTMLElement {
this._attachChildPropertyUpdated(child, slotData);
}

// Distribute the child in the _state object
const propertyName = slotData.propertyName || slotName;
this._state[propertyName].push(child);

if (slottedChildrenMap.has(propertyName)) {
slottedChildrenMap.get(propertyName).push({ child, idx });
} else {
slottedChildrenMap.set(propertyName, [{ child, idx }]);
}
});

await Promise.all(allChildrenUpgraded);

// Distribute the child in the _state object, keeping the Light DOM order,
// not the order elements are defined.
slottedChildrenMap.forEach((children, slot) => {
this._state[slot] = children.sort((a, b) => a.idx - b.idx).map(_ => _.child);
});
this._invalidate();
}

Expand Down

0 comments on commit b8efea0

Please sign in to comment.