Positioning
The FloatingToolbar supports anchored positioning and free positioning. It updates its placement while the page scrolls or resizes. You can also control its visibility and set its margin.
Anchored Mode
Set the anchor prop to an HTMLElement to position the FloatingToolbar relative to that element. Pass the element itself, such as the value of a Vue template ref, rather than a selector string. The position prop specifies the preferred side of the anchor:
top(default)bottomleftright
If the preferred side does not have enough space, collision handling flips the component to the opposite side. The FloatingToolbar follows its anchor while the page scrolls or the viewport resizes.
The following example demonstrates a formatting toolbar anchored to a highlighted phrase. Use the configurator to change position.
Free-Position Mode
When anchor is null or omitted, the FloatingToolbar aligns within its container according to containerAlign. This prop accepts horizontal and vertical keys and defaults to { horizontal: 'center', vertical: 'top' }.
The available horizontal values are left, center (default), and right. The available vertical values are top (default), center, and bottom.
Use appendTo to choose where the FloatingToolbar is rendered:
- Omit
appendToto append it todocument.bodyand align it within the page. - Pass an
HTMLElementto render it inside a custom container. In free-position mode,containerAlignaligns it within that element. Give the container a positioning context, such asposition: relative. - Set
appendTotonullto render it inline at its place in the Vue template without moving it to another element. Inline rendering controls its DOM location; use an explicit container element when you also need container-relative alignment.
Changing anchor or appendTo resets a manually positioned toolbar so that its configured alignment applies again.
The following example demonstrates free positioning inside a custom container. Change the horizontal and vertical alignment to reposition the FloatingToolbar.
Controlling Visibility
Mount and unmount the FloatingToolbar with Vue conditional rendering, such as v-if, to show and hide it. The component does not expose a show prop. For selection-based actions, set anchor to an element representing the current selection when mounting the component.
The following example displays the FloatingToolbar above selected text. Select part of the text to show it and clear the selection to hide it.
Setting the Margin
Use the margin prop with horizontal and vertical values in pixels. In anchored mode, it controls the gap between the FloatingToolbar and its anchor. In free-position mode, it controls the inset from the alignment container's edge.
The following example shows how increasing the margin insets a bottom-aligned FloatingToolbar from the page edge.