Skip to content

Commit

Permalink
fix(hierarchylist): change defaultselectedid onselect behavior
Browse files Browse the repository at this point in the history
  • Loading branch information
jonguenther committed Dec 7, 2020
1 parent fb9b0f2 commit 1a75985
Showing 1 changed file with 12 additions and 10 deletions.
22 changes: 12 additions & 10 deletions src/components/List/HierarchyList/HierarchyList.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -220,23 +220,25 @@ const HierarchyList = ({
[defaultSelectedId]
);

const handleSelect = (id, parentId = null) => {
const setSelected = (id, parentId = null) => {
if (editingStyle) {
setEditModeSelectedIds(
handleEditModeSelect(items, editModeSelectedIds, id, parentId)
);
} else if (selectedIds.includes(id)) {
setSelectedIds(selectedIds.filter((item) => item !== id));
} else if (hasMultiSelect) {
setSelectedIds([...selectedIds, id]);
} else {
if (hasMultiSelect) {
setSelectedIds([...selectedIds, id]);
} else {
setSelectedIds([id]);
}
setSelectedIds([id]);
}
};

if (onSelect) {
onSelect(id);
}
const handleSelect = (id, parentId = null) => {
setSelected(id, parentId);

if (onSelect) {
onSelect(id);
}
};

Expand All @@ -263,7 +265,7 @@ const HierarchyList = ({

if (!isEqual(selectedIds, [defaultSelectedId])) {
// If the defaultSelectedId prop is updated from the outside, we need to use it
handleSelect(defaultSelectedId);
setSelected(defaultSelectedId);
}
}
},
Expand Down

0 comments on commit 1a75985

Please sign in to comment.