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

Media query collapsed #135

Open
Qudusayo opened this issue Jan 28, 2023 · 2 comments
Open

Media query collapsed #135

Qudusayo opened this issue Jan 28, 2023 · 2 comments

Comments

@Qudusayo
Copy link

Couldn't find a way to make the dropdown component closed on mobile and open on the desktop without transition.

It works as I expected on mobile, but due to update from useEffect, there's transition on desktop as it's set to open

  const [isExpanded, setisExpanded] = useState<boolean>(false);
  const { getCollapseProps, getToggleProps } = useCollapse({
    isExpanded,
    defaultExpanded: false,
  });

  useEffect(() => {
    if (window.innerWidth > 700) {
      setisExpanded(true);
    }
  }, []);

With this code above, there's a transition on desktop when component mounts

Screen.Recording.2023-01-28.at.08.04.24.mov
@roginfarrer
Copy link
Owner

If you're not server-side rendering, you can skip the useEffect altogether:

const [isExpanded, setisExpanded] = useState<boolean>(window.innerWidth > 700);
const { getCollapseProps, getToggleProps } = useCollapse({isExpanded});

You're also not supposed to use defaultExpanded and isExpanded together, so you should leave out defaultExpanded.

You can also use the hasDisabledAnimation to enable/disable transitions at any point in the hook's lifecycle.

@Qudusayo
Copy link
Author

Qudusayo commented Feb 3, 2023

Can you help with a sample code ?

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

2 participants