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

Doesn't work when collapsible element is a span #26

Open
danascheider opened this issue Jul 18, 2021 · 0 comments
Open

Doesn't work when collapsible element is a span #26

danascheider opened this issue Jul 18, 2021 · 0 comments

Comments

@danascheider
Copy link

danascheider commented Jul 18, 2021

Hello lovely maintainers! I've noticed what might be a little bug (or maybe intended behaviour?), described below, and I wondered if you'd be interested in a PR to add documentation for this. It took me some time to figure out how to fix my slide toggle and if you'd accept a docs PR I'd love to spare someone else the trouble.

My question for you is, is this either intended behaviour or a bug you're aware of, and if so, what are the boundaries - which tags are allowed for the collapsible elements and which aren't? No worries if you don't know - I'm happy to poke around a bit in a sandbox and find out.

The Issue

I've noticed an issue where the following code (using a span as the collapsible element) causes the collapsible element to just appear and disappear instantaneously, and not slide, when the trigger is clicked:

const ToggleComponent = () => {
  const [toggleEvent, setToggleEvent] = useState(0)

  const toggle = () => setToggleEvent(Date.now)

  return(
    <>
      <h3 onClick={toggle}>Toggle</h3>
      <SlideToggle toggleEvent={toggleEvent}>
        {({ setCollapsibleElement }) => (
          {/* this span breaks things */}
          <span ref={setCollapsibleElement}>
            <p>Toggle content</p>
          </span>
        )}
      </SlideToggle>
    </>
  )
}

When I switch the container element to a div, it works:

<>
  <h3 onClick={toggle}>Toggle</h3>
  <SlideToggle toggleEvent={toggleEvent}>
    {({ setCollapsibleElement }) => (
      {/* changing the span to a div fixes it */}
      <div ref={setCollapsibleElement}>
        <p>Toggle content</p>
      </div>
    )}
  </SlideToggle>
</>

If this is a bug I'm afraid I can't promise I have the expertise to fix it (although I'd be happy to if it turns out to be something straightforward), but in either case I'm happy to add some docs :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant