Floating UI
Usage
Floating UI is a low-level primitive for building custom popover-style surfaces such as rich pickers, menus, inspectors, or inline tools, with automatic positioning relative to a trigger element. Use it when higher-level components such as Action Menu do not fit the custom floating interaction you need.
import { MtFloatingUi } from "@shopware-ag/meteor-component-library";
Examples
Multiple anchors
Use detached mode together with anchorElement to share one floating surface across multiple triggers. The floating panel repositions itself to each anchor as the user hovers, and a short close delay keeps it reachable when the cursor travels from trigger to panel.
API reference
Props
| Prop | Type | Default |
|---|---|---|
is-opened * | boolean | |
floating-ui-options | Partial<{ placement?: Placement | undefined; strategy?: Strategy | undefined; middleware?: (false | { name: string; options?: any; fn: (state: { placement: Placement; middlewareData: MiddlewareData; x: number; y: number; initialPlacement: Placement; strategy: Strategy; rects: ElementRects; platform: Platform; elements: Elements; }) => Promisable<MiddlewareReturn>; } | null | undefined)[] | undefined; platform?: Platform | undefined; }> | undefined | |
show-arrow | boolean | |
offset | number | |
auto-update-options | Partial<AutoUpdateOptions> | |
match-reference-widthIf true, the floating UI content will match the width of the reference element. | boolean | |
anchor-elementAn external DOM element to anchor the floating content to, instead of the
built-in trigger slot wrapper | HTMLElement | null | |
detachedWhen true, the trigger slot is not rendered and the root wrapper is not displayed
Use with `anchorElement`. | boolean |
Events
| Event | Payload |
|---|---|
close | [] |
Slots
| Slot | Bindings |
|---|---|
trigger | {} |
default | { referenceElementWidth: number; referenceElementHeight: number; } |
Best practices
Do
- Manage the open state outside the component and update it through
isOpenedand thecloseevent. - Provide a clear trigger element so users understand what opens the floating surface.
- Style the slotted content as a complete surface, including background, border, spacing, and shadow.
- Use
matchReferenceWidthwhen the floating surface should align to the trigger width.
Don't
- Do not use Floating UI when a higher-level component such as Action Menu already fits the use case.
- Do not rely on it to provide a finished surface design. It only handles positioning and behavior.
- Do not forget to handle keyboard and focus behavior for custom interactive content.
Behavior
- Floating UI teleports its content to
body, so the floating surface can escape clipping and stacking issues in the local layout. - It uses Floating UI middleware to offset, flip, and measure the floating surface automatically.
showArrowadds an arrow element, but the slotted content still needs to provide the actual surface styling.- The default slot receives
referenceElementWidthandreferenceElementHeight, which help when the floating content needs to size itself relative to the trigger. matchReferenceWidthsets the floating container width to the trigger width automatically.
Accessibility
- Make sure the trigger clearly communicates what it opens.
- If the floating content contains interactive controls, manage focus and keyboard behavior intentionally.
- Provide visible structure and labels inside the floating surface so the custom content stays understandable once opened.
Related components
- Popover: when the standard popover styling and interaction model already fit.
- Action Menu: when you need a standard menu of actions or options.