diff --git a/.changeset/treeview-undefined-2.md b/.changeset/treeview-undefined-2.md new file mode 100644 index 000000000..f0fb94916 --- /dev/null +++ b/.changeset/treeview-undefined-2.md @@ -0,0 +1,5 @@ +--- +'react-magma-dom': patch +--- + +fix(TreeView): Fix undefined problem diff --git a/packages/react-magma-dom/src/components/TreeView/useTreeView.ts b/packages/react-magma-dom/src/components/TreeView/useTreeView.ts index 2763badbd..bd9af92d6 100644 --- a/packages/react-magma-dom/src/components/TreeView/useTreeView.ts +++ b/packages/react-magma-dom/src/components/TreeView/useTreeView.ts @@ -161,7 +161,7 @@ export function useTreeView(props: UseTreeViewProps) { }, [items, rawInitialExpandedItems]); const itemToFocus = React.useMemo(() => { - const enabledItems = items.filter(item => !item.isDisabled); + const enabledItems = items.filter(item => !item?.isDisabled); const [firstItem] = enabledItems; if (selectable === TreeViewSelectable.off) { @@ -230,13 +230,13 @@ export function useTreeView(props: UseTreeViewProps) { item => item.itemId === prevItem.itemId ); - if (itemWithUpdatedDisabledState?.isDisabled === prevItem.isDisabled) { + if (itemWithUpdatedDisabledState?.isDisabled === prevItem?.isDisabled) { return prevItem; } return { ...prevItem, - isDisabled: itemWithUpdatedDisabledState.isDisabled, + isDisabled: itemWithUpdatedDisabledState?.isDisabled, }; }); }); diff --git a/packages/react-magma-dom/src/components/TreeView/utils.ts b/packages/react-magma-dom/src/components/TreeView/utils.ts index 050bb2549..5745e9906 100644 --- a/packages/react-magma-dom/src/components/TreeView/utils.ts +++ b/packages/react-magma-dom/src/components/TreeView/utils.ts @@ -204,7 +204,7 @@ const getIsDisabled = ({ const isDisabled = preselectedItem?.isDisabled !== undefined ? preselectedItem?.isDisabled - : props.isDisabled; + : props?.isDisabled; if (selectable === TreeViewSelectable.multi && !checkChildren) { return isDisabled; @@ -281,7 +281,7 @@ const processItemCheckedStatus = ({ }) => { const item = items.find(item => item.itemId === itemId); - if (item.isDisabled && !forceCheckedStatusForDisabled) { + if (item?.isDisabled && !forceCheckedStatusForDisabled) { return items; } @@ -682,7 +682,7 @@ export const toggleAllMulti = ({ } & Pick) => { if (!checkChildren) { return items.map(item => { - if (item.isDisabled) { + if (item?.isDisabled) { return item; }