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

Unable to use AutoAnimate in Solid.js project following documentation example #121

Closed
andrew-boyd opened this issue Feb 5, 2023 · 4 comments
Assignees

Comments

@andrew-boyd
Copy link
Member

Discord user sigma is unable to get AutoAnimate working in their solid.js project following our examples in the docs.

reproduction repo here: https://github.com/awojciak/autoanimate-repro

npm install
npm run dev

Example is in ./src/components/Drawer.tsx

@andrew-boyd
Copy link
Member Author

There are two TypeScript issues in the file:

Screenshot 2023-02-05 at 4 33 52 PM

Screenshot 2023-02-05 at 4 33 58 PM

@andrew-boyd
Copy link
Member Author

andrew-boyd commented Feb 5, 2023

Am able to work around this issue with the following. Notably, import { autoAnimate } from '@formkit/auto-animate/solid' presented as an alternative in the docs does not work — there is no named export of autoAnimate from @formkit/auto-animate/solid.

import { createSignal, For, Show } from "solid-js"
import { createAutoAnimateDirective } from "@formkit/auto-animate/solid"
import "./index.css"

export default function Drawer() {
  // Required to prevent TS from removing the directive
  const autoAnimate = createAutoAnimateDirective()

  const menuItems = ["Home", "Settings", "Logout"]
  const [isExpanded, setIsExpanded] = createSignal(true)

  return (
    <div class="parent" use:autoAnimate>
      <Show when={isExpanded()} keyed>
        <ul class="drawer">
          <For each={menuItems}>{(item) => <li class="item">{item}</li>}</For>
        </ul>
      </Show>
      <div class="content">
        <button
          class="button button--alt"
          type="button"
          onClick={() => setIsExpanded((isExpanded) => !isExpanded)}
        >
          Toggle Drawer
        </button>
      </div>
    </div>
  )
}

@rifandani
Copy link

I'm using v1.0.0-beta.6 and yeah the example of usage in the documentation is not working both with createAutoAnimate and createAutoAnimateDirective function as of today.

The createAutoAnimate function is actually accepting AutoAnimateOptions object as it's params, not the parent ref.
It returns a tuple of ref setter and setEnabled setter function -> const [setParent, setEnabled] = createAutoAnimate().
Then, we can use the setParent setter function in ref parent element, but set it like this -> ref={(elem) => setParent(elem)}

@MartinBspheroid
Copy link

I'm using v1.0.0-beta.6 and yeah the example of usage in the documentation is not working both with createAutoAnimate and createAutoAnimateDirective function as of today.

The createAutoAnimate function is actually accepting AutoAnimateOptions object as it's params, not the parent ref. It returns a tuple of ref setter and setEnabled setter function -> const [setParent, setEnabled] = createAutoAnimate(). Then, we can use the setParent setter function in ref parent element, but set it like this -> ref={(elem) => setParent(elem)}

Thanks, this helped me a lot!
Also, thanks, this rocks my socks of so far!

justin-schroeder added a commit that referenced this issue Nov 3, 2023
update solid examples to fix #121
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

4 participants