setting `enableExpanding` has no effect. #4939
Send to my agentDescribe the bug#
Setting enableExpanding to false has no effect.
Your minimal, reproducible example#
https://stackblitz.com/edit/stackblitz-starters-xwm3zz?file=src%2FApp.tsx
Steps to reproduce#
- Select a row whilst
enableRowSelectionis set to true. Selection state will change. - Set
enableRowSelectionto false. Selection state won't change if you try selecting a row. - Expand a row whilst
enableExpandingis set to true. Expansion state will change. - Set
enableExpandingto false. Expansion state will still change when the user tries to expand a row.
Expected behavior#
If enableExpanding is set to false, rows should not be expandable.
How often does this bug happen?#
Every time
Screenshots or Videos#
No response
Platform#
macOS: Firefox, Edge Fedora: Firefox, Edge
react-table version#
v8.9.3
TypeScript version#
No response
Additional context#
No response
Terms & Code of Conduct#
- I agree to follow this project's Code of Conduct
- I understand that if my bug cannot be reliable reproduced in a debuggable environment, it will probably not be fixed and this issue may even be closed.
Thanks for looking into this. I'm aware of the
getToggleExpandedHandler, but I was having issues with it https://github.com/TanStack/table/issues/4940.In the example I provided in this issue, you can see that I use toggleSelected to toggle selection.
toggleSelecteddoes seem to respect the value ofenableRowSelectionwhilsttoggleExpandeddoes not respect the value ofenableExpanding. The inconsistency is what threw me off I guess.KevinVandy closed this
Sign in to join this conversation.
Hey, I don't know if this is an expected behavior but I checked the code and this is what I found.
So in your case, you used the
toggleExpandedfunction to trigger the expanding function. Indeed this will trigger the expanding behavior because internally, it doesn't checks if the rows can be expanded or not.We also have another function
getToggleExpandedHandlerwhich returns thetoggleExpandedhandler. However, this function internally will check whether the row can be expanded or not. See the example. The checks happen when using the getter function, rather than on the originaltoggleExpandedhandler.Surprisingly, the table API
getToggleAllRowsExpandedHandlerhas no checks at all about whether we can expand it or not.My suggestion is you can use the row API
getCanExpandor the table APIgetCanSomeRowsExpandto conditionally render your expand button/handler.But if this is a real issue/bug I would be glad to fix this and create a PR