Skip to content

Conversation

@Han5991
Copy link
Contributor

@Han5991 Han5991 commented May 2, 2025

Question: Is it safe to remove display: none from Collapse hidden styles?

Context

I am considering removing display: none from the hidden styles in the Collapse component, and relying only on height: 0 and overflow: hidden to hide content when collapsed.

Why consider this change?

  • Using display: none causes issues with nested Collapses and prevents child animations from triggering correctly when the parent is reopened.
  • Removing display: none allows for smoother transitions, better support for nested Collapses, and more consistent state updates for children.

Accessibility Considerations

  • With display: none, content is removed from the accessibility tree, which is sometimes desirable, but it also prevents focus management and dynamic content updates.
  • Using height: 0 and overflow: hidden keeps the content in the DOM and accessibility tree. To address focus issues, we can blur any focused element inside a collapsed Collapse and use aria-hidden or tabIndex for additional control.

My Question

Are there any strong reasons or edge cases where we should keep display: none in Collapse, rather than just using height: 0 and overflow: hidden?

  • Are there known accessibility or performance issues with this approach?
  • Do you see any downsides to removing display: none for the sake of animation and nested Collapse support?

I would appreciate any feedback or concerns before proceeding with this change.

fix: #6447
@rtivital
If there are any concerns about accessibility or specific use-cases that require display: none, please let me know!

@rtivital
Copy link
Member

rtivital commented May 3, 2025

display: none prevents elements inside the Collapse with hidden state from being focused. If display: none is removed, focused must be handled by other means, for example, by setting inert attribute on the root element of the hidden Collapse.

@rtivital rtivital changed the base branch from master to v7 May 5, 2025 15:29
@rtivital
Copy link
Member

rtivital commented May 5, 2025

Please remove last commit, this PR must point to v7 branch, it should not merge master changes in

- add NestedCollapseWithControl story
- improve inert attribute handling
@Han5991 Han5991 force-pushed the feature/fix-collapse-hidden-sections-animate-incorrectly branch from 513186f to 3a87a48 Compare May 5, 2025 22:46
@rtivital rtivital merged commit 53d3b34 into mantinedev:v7 May 8, 2025
1 check passed
@rtivital
Copy link
Member

rtivital commented May 8, 2025

Thanks!

@Han5991 Han5991 deleted the feature/fix-collapse-hidden-sections-animate-incorrectly branch June 22, 2025 10:00
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

Successfully merging this pull request may close these issues.

Animated children of collapsed or hidden sections animate incorrectly

2 participants