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

Unable to pass refs from RichTreeView to slot component #16432

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

Unable to pass refs from RichTreeView to slot component #16432

ccennis opened this issue Feb 2, 2025 · 0 comments
Labels
component: tree view TreeView, TreeItem. This is the name of the generic UI component, not the React module! status: waiting for maintainer These issues haven't been looked at yet by a maintainer

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
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 maintainer These issues haven't been looked at yet by a maintainer
Projects
None yet
Development

No branches or pull requests

2 participants