Skip to content
Source
Sign inSign up
TanStack/table

setting `enableExpanding` has no effect. #4939

Send to my agent
Closedwallpants(GitHub profile, opens in a new tab) opened this issue 2 comments

Describe 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

  1. Select a row whilst enableRowSelection is set to true. Selection state will change.
  2. Set enableRowSelection to false. Selection state won't change if you try selecting a row.
  3. Expand a row whilst enableExpanding is set to true. Expansion state will change.
  4. Set enableExpanding to 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.
  1. 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 toggleExpanded function 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 getToggleExpandedHandler which returns the toggleExpanded handler. 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 original toggleExpanded handler.

     getToggleExpandedHandler: () => {
        const canExpand = row.getCanExpand()
    
        return () => {
          if (!canExpand) return
          row.toggleExpanded()
        }
      },

    Surprisingly, the table API getToggleAllRowsExpandedHandler has no checks at all about whether we can expand it or not.

    My suggestion is you can use the row API getCanExpand or the table API getCanSomeRowsExpand to 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

  2. 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. toggleSelected does seem to respect the value of enableRowSelection whilst toggleExpanded does not respect the value of enableExpanding. The inconsistency is what threw me off I guess.

  3. KevinVandy closed this

Sign in to join this conversation.