Floating UI React
Floating UI provides primitives for creating tooltips, popovers, dropdown menus, hover cards, modal dialogs, select menus, comboboxes, and more. Instead of providing pre-built components, this guide will introduce the fundamentals of Floating UI React. This provides an open-ended solution for creating your own popover features and components for any form factor - while pairing with Skeleton’s design system and components.
Learn the Basics
If this is your first time using Floating UI, start here:
- Floating UI Tutorial - covers the basics of using native Javascript.
- Floating UI React Tutorial - covers the basics of using the React wrapper.
Imports
Floating UI React exposes all required Floating UI middleware, types, etc.
Making Elements Float
You’ll need a dedicated CSS class to apply common styles to all floating elements. Apply the following in your global stylesheet. We’ll use the following class convention for all Skeleton examples.
Z-Index Stacking
Please be aware that Floating UI does not take an opinionated stance on z-index stacking. This means that if a floating element is occluded by another element in the z-axis, you must handle this directly.
Middleware
Make sure you’re familiar all available Floating UI Middleware, which provides modules for customizing the look and feel of popovers.
Examples
Floating UI React provides an extensive set of headless React examples. We’ll use these as the foundation for at the following set of examples that fully integrate Skeleton. See the official Floating UI React documentation for a complete API Reference.
Popover
Triggers an anchored popover when you click the trigger element.
Tooltip
Triggers an anchored popover when you hover the trigger element.
Combobox
Triggers an anchored popover list on search. Includes autocomplete with automatic selection.
Modal
Generates any form of modal or dialog that require a user’s immediate attention.
Additional Tips
Reusable Components
See tips for convert the primitive examples above into reusable components in your local project.
Accessibility
When implementing popovers, make sure to account for accessibility and keyboard interactions. Floating UI React provides a number of hooks and components to help facilitate all requirements.
- Tooltip Guidelines
- Combobox Guidelines
- Modal Guidelines
- Alert Dialog Guidelines
- Alert Guidelines
- Listbox Guidelines
Native Browser APIs
Skeleton will always favor native browser APIs over third-party libraries such as Floating UI Svelte. The following is a list of current and upcoming incoming APIs we will aim to support in the future, but are not quite standardized cross-browser yet.