Documentation Index
Fetch the complete documentation index at: https://anvil.servicetitan.com/llms.txt
Use this file to discover all available pages before exploring further.
- Implementation
- Popover Props
- Popover.Content Props
- Popover.Trigger Props
Common Examples
Popover basics
To build a popover, three components are required:Popover: the configurable parent component- A way to control the open state of the popover. One of:
Popover.Button: an Anvil2 ButtonPopover.Trigger: used to render a custom trigger component
Popover.Content: the content rendered within the popover
Popover placement
Use theplacement prop on the Popover to change the default positioning. The popover will reposition itself if there is not enough space in the default placement.Controlling popovers
Popovers can be controlled or uncontrolled (default). Control the popover using theopen prop.Uncontrolled (default)
Controlled
Using a custom trigger
To use something other than an Anvil2 Button to trigger the popover, use thePopover.Trigger component. The Popover.Trigger passes a set of props to the children that should be passed to an interactive HTML element, such as a button or input.Popover close button
ThePopover.Close button can be used to close the popover from within the popover content.On controlled popovers, the onClick prop should be used to update the open state:Disabling default closing behavior
By default, an uncontrolled popover closes if either the user clicks outside of the popover, or the user presses the “Escape” key. Both of these behaviors can be disabled with props:Disable close on outside click
Disable close on “Escape” press
Enabling trapped focus
By default, the popover content does not trap focus so that users can navigate the content with a keyboard without naturally. To enable this behavior, set themodal prop of the Popover to true.Default without trapping
Trapped focus
Using with Anvil1
Popover from version 1.23.0 uses HTML popover API which utilizes top-layer. This feature puts what’s inside the top-layer to be on the top of entire the HTML. Because of this, there are cases where it does not work well with Anvil1’s portaled components.- While having the
Popoveropen, if a portaled Anvil1 component is triggered to open from within, thePopoverwill be on top always. This is something we can potentially adjust in Anvil1 and we have a spike ticket internally for it. If you encounter this issue, please reach out to us. - While having the
Popoveropen, if aDrawerorDialogfrom Anvil1 is triggered to open, not within thePopover, thePopoverwill be on top of theDrawerorDialog.
React Accessibility
Most of the accessibility considerations for managingaria props and keyboard focus are handled internally. There are some things to keep in mind while working with popovers:- Always test keyboard navigation for interactive elements within popovers. The user should be able to easily access the elements in a logical order.
- If the popover includes a form, be sure to follow accessible best practices for form building.
- When building a custom trigger using
Popover.Trigger, be sure to pass the props to an interactive element, as certainariaprops are included to properly connect the trigger to the content.