Floating Arrow
Renders a customizable <svg>
pointing arrow triangle
inside the floating element that gets automatically positioned.
Usage
- Create an arrowRef and
pass it to the arrow middleware’s
element
option and the<FloatingArrow />
component. This lets the arrow be measured for positioning. - Pass the context to the
<FloatingArrow />
component. This lets the component read the positioning data.
The arrow will, by default, overlap the reference element. The
height
of the arrow will offset it by the desired
amount.
This does not take into account tip rounding or strokes.
Props
The arrow accepts all the props of an <svg>
element, plus
some additional props:
ref
context
The context
object returned from useFloating()
.
width
default: 14
The width of the arrow.
height
default: 7
The height of the arrow.
tipRadius
default: 0
(sharp)
The radius (rounding) of the arrow tip.
staticOffset
default: undefined
(use dynamic position)
A static offset override of the arrow from the floating element
edge. Often desirable if the floating element is smaller than the
reference element along the relevant axis and has an edge
alignment ('start'
/'end'
). This is ignored if the
shift() middleware caused the floating element to shift.
d
default: undefined
(use dynamic path)
A custom path for the arrow. Useful if you want fancy rounding.
The path should be inside a square SVG and placed at the bottom
of it. The path is designed for the 'bottom'
placement,
which will be rotated for other placements.
fill
default: "black"
(browser default)
The color of the arrow.
stroke
default: "none"
The stroke (border) color of the arrow.
strokeWidth
default: 0
The stroke (border) width of the arrow. This must match (or be less than) the floating element’s border width.
Tailwind and utility CSS styling
fill-*
sets the arrow’s fill color.[&>path:first-of-type]
targets the “stroke” path.[&>path:last-of-type]
targets the “fill” path’s extra stroke, to reduce gaps.
strokeWidth
should still be manually specified as a
prop.
Scale transforms
When animating the floating element’s scale, it looks best if the
floating element’s transform-origin
is at the tip of the arrow.
The arrow
middleware provides data to achieve this.
Troubleshooting
Stroke is not visible
Ensure you’ve specified at least a strokeWidth
of
1
.
A gap is present
- Styling the top-level
<svg>
using native CSS properties likefill
andstroke
directly won’t work correctly. This can happen if you’re styling usingstyled(FloatingArrow)
for example. Instead, use thefill
andstroke
props, or target the child path elements as shown in Tailwind and utility CSS styling. - If a border is applied to an inner element of the floating
element, make sure arrow is inside the inner element and that
the inner element has
position: relative
CSS. This ensures the arrow will align with the border correctly. - Ensure the
strokeWidth
of the arrow is the same as the floating element’s border width. - The gap may be related to zoom levels in some browsers or the OS. To support transparency and prevent overlapping of colors of the floating and arrow element, this problem cannot be avoided. If your floating element and arrow are not partially transparent and are instead solid colors, you can use the following workaround:
Arrow does not avoid rounded corners
The arrow doesn’t automatically avoid rounded corners of the
floating element when it’s shifted. To ensure it doesn’t overflow
the corners, you can use the padding
prop in the
arrow()
middleware when calling useFloating()
to
account for this.