feat(portal): add FloatingPortal component
#2150
Draft
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Adds
PortalandFloatingPortalcomponents to enable rendering content outside the normal DOM hierarchy.This addresses z-index stacking context issues and provides a foundation for auto-positioning menus, tooltips, and modals. The
Portalcomponent renders content into a fixed container appended todocument.body, whileFloatingPortalextends this with automatic positioning relative to a reference element using the Floating UI library.TODO:
Eventual usage:
Why?
Currently, "popover" elements (dropdown menus, tooltips, modals, etc) are relatively positioned, meaning that the element is contained within the component in the DOM. This causes z-index issues, where other elements may obstruct menus. Additionally, elements may be cut off if an ancestor component manipulates
overflow: hidden.See issues tagged with "portal": https://github.com/carbon-design-system/carbon-components-svelte/issues?q=is%3Aissue%20state%3Aopen%20label%3Aportal
This is where a portal helps. It's a standard feature of UI, where "popover" elements are "portalled" outside of the root node for the main application. The portalled node is typically a sibling of the app node.
Proposed Changes
PortalandFloatingPortalcomponents.