Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[tree view] Unable to pass refs from RichTreeView to slot component #16432

Open
ccennis opened this issue Feb 2, 2025 · 3 comments
Open

[tree view] Unable to pass refs from RichTreeView to slot component #16432

ccennis opened this issue Feb 2, 2025 · 3 comments
Labels
component: tree view TreeView, TreeItem. This is the name of the generic UI component, not the React module! status: waiting for author Issue with insufficient information

Comments

@ccennis
Copy link

ccennis commented Feb 2, 2025

I have been sawing at this for ages, and I cannot figure out what I am doing wrong. I want to drag and drop these items within my DragTreeItem component but I cannot seem to pass a non-null ref via slotProps.

const getItemRef = (itemId) => {
    if (!itemRefs.current[itemId]) {
      itemRefs.current[itemId] = React.createRef();
    }
    return itemRefs.current[itemId];
  };
return (
    <>
      <Box sx={{ width: '100%', display: 'flex', flexDirection: 'column' }}>
        {treeData && treeData.length > 0 && (
          <Box
            sx={{
              borderBottom: '1px solid #ddd',
              paddingY: '10px',
            }}>
            <RichTreeView
              apiRef={apiRef}
              items={treeData}
              sx={{
                width: '100%',
                height: 'fit-content',
                flexGrow: 1,
                overflowY: 'auto',
              }}
              slots={{ item: DragTreeItem }}
              slotProps={{
                item: (itemProps) => ({
                  ...itemProps,
                  ref: getItemRef(itemProps.itemId),
                  handleCreateCollection,
                  onItemDrop,
                  disabled: false,
                }),
              }}
            />
          </Box>
        )}
      </Box>
    </>
  );

I have attempted to pass the function, the ref itself, and even tried to get the DomElement from the apiRef.

const DragTreeItem = React.forwardRef(function DragTreeItem(props, ref) {
  const {
    itemId,
    label,
    disabled = false,
    children,
    handleCreateCollection,
    onItemDrop,
    ...other
  } = props;

  React.useEffect(() => {
    if (ref && ref.current) {
      console.log(`DragTreeItem received DOM ref for ${itemId}:`, ref.current);
    } else {
      console.warn(`Ref is NULL for item ${itemId}`);
    }
  }, [ref, itemId]);

The logs always show that this ref is NULL and I cannot get my atlassian draggable variable to set. Is there a way to pass a ref correctly to a slotted component?

@github-actions github-actions bot added the status: waiting for maintainer These issues haven't been looked at yet by a maintainer label Feb 2, 2025
@zannager zannager added the component: tree view TreeView, TreeItem. This is the name of the generic UI component, not the React module! label Feb 3, 2025
@michelengelen michelengelen changed the title Unable to pass refs from RichTreeView to slot component [tree view] Unable to pass refs from RichTreeView to slot component Feb 7, 2025
@michelengelen
Copy link
Member

Hey @ccennis ... sry for the late reply.
Could you try and create a minimal reproduction in live code and tell us what you are trying to achieve in detail? I It does not have to be working, but at least something we can have a look at!
Thanks!

@michelengelen michelengelen added status: waiting for author Issue with insufficient information and removed status: waiting for maintainer These issues haven't been looked at yet by a maintainer labels Feb 7, 2025
@ccennis
Copy link
Author

ccennis commented Feb 7, 2025

Hey @ccennis ... sry for the late reply. Could you try and create a minimal reproduction in live code and tell us what you are trying to achieve in detail? I It does not have to be working, but at least something we can have a look at! Thanks!

i'm just an idiot and I should have used the paid RichTreeViewPro -- i was hoping to pass more via item slots but eventually gave up

@github-actions github-actions bot added status: waiting for maintainer These issues haven't been looked at yet by a maintainer and removed status: waiting for author Issue with insufficient information labels Feb 7, 2025
@michelengelen
Copy link
Member

Hey @ccennis ... sry for the late reply. Could you try and create a minimal reproduction in live code and tell us what you are trying to achieve in detail? I It does not have to be working, but at least something we can have a look at! Thanks!

i'm just an idiot and I should have used the paid RichTreeViewPro -- i was hoping to pass more via item slots but eventually gave up

Ahm, ok ... is this resolved for you now or do you need some help with it? 🤔

@michelengelen michelengelen added status: waiting for author Issue with insufficient information and removed status: waiting for maintainer These issues haven't been looked at yet by a maintainer labels Feb 10, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component: tree view TreeView, TreeItem. This is the name of the generic UI component, not the React module! status: waiting for author Issue with insufficient information
Projects
None yet
Development

No branches or pull requests

3 participants