Skip to content

[Collapsible] POC using grid-template-* properties as open/close animation target #1770

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

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

mj12albert
Copy link
Member

@mj12albert mj12albert commented Apr 23, 2025

Demo: https://deploy-preview-1770--base-ui.netlify.app/experiments/collapsible2/transitions

API

The anatomy remains the same, except Collapsible.Panel must render an extra div around its children

CSS transitions:

.Panel {
  display: grid;
  grid-template-rows: 1fr;

  transition: all var(--duration);

  &[data-starting-style],
  &[data-ending-style] {
    opacity: 0;
    grid-template-rows: 0fr;
  }
}

CSS animations:

@keyframes slide-down {
  from {
    grid-template-rows: 0fr;
  }

  to {
    grid-template-rows: 1fr;
  }
}

@keyframes slide-up {
  from {
    grid-template-rows: 1fr;
  }

  to {
    grid-template-rows: 0fr;
  }
}

.Panel {
  display: grid;

  &[data-open] {
    animation: slide-down var(--duration) ease-out;
  }

  &[data-closed] {
    animation: slide-up var(--duration) ease-in;
  }
}

👍

  • Don't need to manage resizing when using CSS transitions

👎

  • When transitioning, the size of the panel isn't 1:1 with the actual layout. Notice the size of the gap between the two collapsibles as it transitions:
collapsible2.mov

When transitioning height it looks like this:

collapsible1.mov

Ariakit has the same issue: https://codesandbox.io/p/sandbox/hungry-goldwasser-mktxk5

@mj12albert mj12albert added component: collapsible This is the name of the generic UI component, not the React module! proof of concept Studying and/or experimenting with a to be validated approach labels Apr 23, 2025
Copy link

netlify bot commented Apr 23, 2025

Deploy Preview for base-ui ready!

Name Link
🔨 Latest commit f88b9b5
🔍 Latest deploy log https://app.netlify.com/sites/base-ui/deploys/6808fd59f518ca0008e103d9
😎 Deploy Preview https://deploy-preview-1770--base-ui.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@mj12albert mj12albert force-pushed the poc/grid-collapsible branch from 8aa1399 to f88b9b5 Compare April 23, 2025 14:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component: collapsible This is the name of the generic UI component, not the React module! proof of concept Studying and/or experimenting with a to be validated approach
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant