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: Custom filter broken due to overwritten props in useImperativeHandle hook. #3107

Closed
edwinkong opened this issue Jul 26, 2022 · 1 comment · Fixed by #3108
Closed

Tree: Custom filter broken due to overwritten props in useImperativeHandle hook. #3107

edwinkong opened this issue Jul 26, 2022 · 1 comment · Fixed by #3108
Assignees
Labels
Type: Bug Issue contains a defect related to a specific component.
Milestone

Comments

@edwinkong
Copy link

Describe the bug

The filter prop of Tree component overwrites the filter function in the useImperativeHandle hook, breaking the custom filtering function.
In https://github.com/primefaces/primereact/blob/master/components/lib/tree/Tree.js, line 297

    React.useImperativeHandle(ref, () => ({
        filter,
        getElement: () => elementRef.current,
        ...props
    }));

Reproducer

https://codesandbox.io/embed/primereact-test-forked-dggjdr?fontsize=14&hidenavigation=1&theme=dark

PrimeReact version

8.3.0

React version

18.x

Language

ALL

Build / Runtime

Create React App (CRA)

Browser(s)

No response

Steps to reproduce the behavior

No response

Expected behavior

No response

@edwinkong edwinkong added Status: Needs Triage Issue will be reviewed by Core Team and a relevant label will be added as soon as possible Type: Bug Issue contains a defect related to a specific component. labels Jul 26, 2022
@melloware melloware self-assigned this Jul 26, 2022
@melloware melloware removed the Status: Needs Triage Issue will be reviewed by Core Team and a relevant label will be added as soon as possible label Jul 26, 2022
@melloware melloware added this to the 9.0.0 milestone Jul 26, 2022
melloware added a commit to melloware/primereact that referenced this issue Jul 26, 2022
@melloware
Copy link
Member

melloware commented Jul 26, 2022

great catch submitted PR wherr the ...props are first and all methods are second so properties won't clobber methods. Please review!

React.useImperativeHandle(ref, () => ({
        ...props,
        filter,
        getElement: () => elementRef.current
    }));

@melloware melloware changed the title Custom Filter Broken in Tree Component due to overwritten props in useImperativeHandle hook. Tree: Custom filter broken due to overwritten props in useImperativeHandle hook. Jul 26, 2022
melloware added a commit to melloware/primereact that referenced this issue Jul 26, 2022
melloware added a commit to melloware/primereact that referenced this issue Jul 26, 2022
@mertsincan mertsincan modified the milestones: 9.0.0, 8.4.0 Aug 22, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Bug Issue contains a defect related to a specific component.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants