Skip to content

[Collapsible][Accordion] Recalculate panel dimensions on layout resize #1704

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

Merged
merged 5 commits into from
Apr 16, 2025

Conversation

atomiks
Copy link
Contributor

@atomiks atomiks commented Apr 11, 2025

Closes #1458

@atomiks atomiks added component: collapsible This is the name of the generic UI component, not the React module! component: accordion This is the name of the generic UI component, not the React module! labels Apr 11, 2025
Copy link

netlify bot commented Apr 11, 2025

Deploy Preview for base-ui ready!

Name Link
🔨 Latest commit f931822
🔍 Latest deploy log https://app.netlify.com/sites/base-ui/deploys/67ff8d3a1a545b0009e92180
😎 Deploy Preview https://deploy-preview-1704--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.

@atomiks atomiks marked this pull request as ready for review April 11, 2025 11:10
@atomiks atomiks changed the title [Collapsible][Accordion] Resize panel on window resize [Collapsible][Accordion] Recalculate panel dimensions on layout resize Apr 14, 2025
@atomiks atomiks force-pushed the collapsible-accordion-resize branch from 4098859 to 33f5610 Compare April 14, 2025 01:13
}

const win = ownerWindow(panel);
win.addEventListener('resize', handleWindowResize);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Testing this a bit and it works well, just wondering is it not enough to only use ResizeObserver?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In this case the ResizeObserver fires when transitioning the height, which is why I added if (panel.getAnimations().length > 0) { to prevent its logic from running, but when resizing the window, I don't want any animations to occur so the resizing is 1:1 with layout.

For this purpose we can't reuse the ResizeObserver since we want regular transitions to work when opening/closing

@atomiks atomiks merged commit cfd2827 into mui:master Apr 16, 2025
22 checks passed
@atomiks atomiks deleted the collapsible-accordion-resize branch April 16, 2025 11:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component: accordion This is the name of the generic UI component, not the React module! component: collapsible This is the name of the generic UI component, not the React module!
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[accordion][collapsible] With CSS transitions the panel does not resize when content size changes
2 participants