Skip to content

Commit

Permalink
[TreeView] Remove instance existence checks (#12066)
Browse files Browse the repository at this point in the history
  • Loading branch information
flaviendelangle authored Feb 15, 2024
1 parent eba5169 commit a534543
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
4 changes: 2 additions & 2 deletions packages/x-tree-view/src/TreeItem/useTreeItemState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export function useTreeItemState(nodeId: string) {
const disabled = instance.isNodeDisabled(nodeId);

const handleExpansion = (event: React.MouseEvent<HTMLDivElement>) => {
if (instance && !disabled) {
if (!disabled) {
if (!focused) {
instance.focusNode(event, nodeId);
}
Expand All @@ -30,7 +30,7 @@ export function useTreeItemState(nodeId: string) {
};

const handleSelection = (event: React.MouseEvent<HTMLDivElement>) => {
if (instance && !disabled) {
if (!disabled) {
if (!focused) {
instance.focusNode(event, nodeId);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ const useTreeViewJSXNodesItemPlugin: TreeViewItemPlugin = ({ props, ref }) => {

React.useEffect(() => {
// On the first render a node's index will be -1. We want to wait for the real index.
if (instance && index !== -1) {
if (index !== -1) {
instance.insertJSXNode({
id: nodeId,
idAttribute: id,
Expand All @@ -113,7 +113,7 @@ const useTreeViewJSXNodesItemPlugin: TreeViewItemPlugin = ({ props, ref }) => {
}, [instance, parentId, index, nodeId, expandable, disabled, id]);

React.useEffect(() => {
if (instance && label) {
if (label) {
return instance.mapFirstCharFromJSX(
nodeId,
(contentRef.current?.textContent ?? '').substring(0, 1).toLowerCase(),
Expand Down

0 comments on commit a534543

Please sign in to comment.