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 and TreePicker reference #1994

Closed
picasik opened this issue Oct 13, 2021 · 3 comments · Fixed by #2178
Closed

Tree and TreePicker reference #1994

picasik opened this issue Oct 13, 2021 · 3 comments · Fixed by #2178
Labels
type: Not an issue Issues that are not actually an issue, e.g. questions. Prefer using discussions.

Comments

@picasik
Copy link

picasik commented Oct 13, 2021

What version of rsuite are you using?

5.0.1

What version of React are you using?

16.13.1

What browser are you using?

Chrome, Firefox

Describe the Bug

<Tree ref={reference}...
reference return node, in rsuite 4.10.2 reference returns TreePicker object

Expected Behavior

reference returns TreePicker object

To Reproduce

v5 - https://codesandbox.io/s/dazzling-parm-924j0?file=/src/App.js
v4 - https://codesandbox.io/s/wispy-cloud-yvhg5?file=/src/App.js

@simonguo
Copy link
Member

Hi @picasik
We have improved the Refs to TreePicker and Tree instances in v5.

TreePicker provides open, close and updatePosition methods like other pickers, which is also to satisfy the compromise in certain scenarios. And Tree as a data display component does not require additional methods. We recommend that you directly use the props provided by the component to use it. Don't overuse Refs

@SevenOutman
Copy link
Member

@simonguo I think we can provide an innerRef prop for passing out the imperative methods on those components which have this ref breaking change. What do you think?

@simonguo
Copy link
Member

@SevenOutman Using innerRef is a solution. If the purpose of innerRef is to get the root element of the component DOM, it can actually be obtained directly through the root property.

rsuite/src/Picker/utils.ts

Lines 571 to 584 in da95b6d

useImperativeHandle(ref, () => ({
get root() {
return rootRef?.current ? rootRef?.current : triggerRef.current?.root;
},
get overlay() {
return overlayRef.current;
},
get target() {
return targetRef?.current;
},
updatePosition: handleUpdatePosition,
open: handleOpen,
close: handleClose
}));

@SevenOutman SevenOutman added the type: Not an issue Issues that are not actually an issue, e.g. questions. Prefer using discussions. label Nov 28, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: Not an issue Issues that are not actually an issue, e.g. questions. Prefer using discussions.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants