Popover
A Popover is a surface that displays content relative to an anchor element. The Popover component is composed of three subcomponents:
Popover.Root: a surface-level container for grouping related components.Popover.Anchor: a component that acts as the anchor element for thePopover.Popover.Content: the wrapper for thePopover’s main content.
How to Use
local Neuron = require(Packages.Neuron)
local Popover = Neuron.Popover
local PopoverSide = Neuron.Enums.PopoverSide
local Button = Neuron.Button
local Text = Neuron.Text
return React.createElement(Popover.Root, {
Anchor = Roact.createElement(Popover.Anchor, nil, {
React.createElement(Button, {
text = "Open Popover",
}),
}),
Content = Roact.createElement(Popover.Content, nil, {
React.createElement(Text, {
text = "This is a popover!",
}),
}),
})Positioning implementation
Required Events and Refs
There is a ref for the anchor, content, and the overlay.
- The anchor
refis used to listen forAbsolutePositionandAbsoluteSizechanges. - The content
refis used to read theAbsoluteSizeof the content. - The overlay
refis used to listen forAbsolutePositionandAbsoluteSizechanges.
If the popover is not open, no AbsolutePositions or AbsoluteSizes will be read from the refs. This is to prevent unnecessary re-layouts.
Calculation
Calculating the position of the popover has three steps:
- Check whether the anchor is on the screen.
- If the anchor is not on the screen, the popover will not be shown and the calculation exits early.
- Calculate which side the popover should be placed on.
- If the popover does not have space on the desired side, but the opposite side has space, it will switch sides.
- Calculate the position of the popover.
- With the final side and alignment, calculate the position of the popover relative to the anchor. The position will be clamped to the screen.
Last updated on