Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

A low-level toolkit to position floating elements while intelligently keeping them in view. Tooltips, popovers, dropdowns, menus, and more

License

NotificationsYou must be signed in to change notification settings

forker-man/floating-ui

 
 

Repository files navigation

Floating UI

Popper is now Floating UI! For Popper v2, visitits dedicated branch.

Rolling Versions

Website

Floating UI is a low-level library for positioning "floating" elements liketooltips, popovers, dropdowns, menus and more while intelligently keeping themin view.

Challenges arise when positioning floating elements as they get taken out of thenormal layout flow of a document, leading to issues with clipping and overflow,which is where this library can help!

  • Tiny: 600-byte core with highly modular architecture for tree-shaking
  • Low-level: Granular control over positioning behavior
  • Pure: Predictable and side-effect free
  • Extensible: Powerful middleware system
  • Platform-agnostic: Runs on any JavaScript environment which providesmeasurement APIs, including the web and React Native

Installation

To use it on the web:

npm install @floating-ui/dom
yarn add @floating-ui/dom

Quick start

import{computePosition}from'@floating-ui/dom';constreferenceElement=document.querySelector('#button');constfloatingElement=document.querySelector('#tooltip');functionapplyStyles({x=0, y=0, strategy='absolute'}){Object.assign(floatingElement.style,{position:strategy,left:`${x}px`,top:`${y}px`,});}applyStyles();computePosition(referenceElement,floatingElement,{placement:'right',}).then(applyStyles);

Visit the docs for detailed information.

Development and production builds

Floating UI is published with default, development, andproduction builds, using Node's support forexport conditions.

  • "default": usesprocess.env.NODE_ENV, in whichyour bundler handles the env variable, dead code elimination,and minification
  • "production": minified with no debug logging
  • "development": unminified with debug logging

If you're using a bundler like webpack, Vite, or Parcel, this ishandled for youautomatically.

If this is not handled, you must opt into one of the builds intools that support export conditions. This is done differentlyfor each tool.

React

Components

Right now, Floating UI focuses on positioning floating elements, but a packagethat exposes higher-level primitives for building these elements more easily isin development.

Contributing

This project is a monorepo written in TypeScript using npm workspaces. Thewebsite is using Next.js SSG and Tailwind CSS for styling.

  • Fork and clone the repo
  • Install dependencies in root directory withnpm install
  • Build initial package dist files withnpm run build

Testing grounds

npm run dev in the root will launch the@floating-ui/dom development visualtests athttp://localhost:1234. The playground uses React to write each testroute, bundled by Parcel. When making changes topackages/core orpackages/dom, Parcel will hot reload the app and display the changes.

Each route has screenshots taken of the page by Playwright to ensure all thefunctionalities work as expected; this is an easy, reliable and high-level wayof testing the code.

Below the main container are UI controls to turn on certain state and options.Every single combination of state is tested visually via the snapshots to coveras much as possible.

Website

npm -w website run dev in the root will launch the website atlocalhost:3000.

License

MIT

About

A low-level toolkit to position floating elements while intelligently keeping them in view. Tooltips, popovers, dropdowns, menus, and more

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • TypeScript70.0%
  • JavaScript28.6%
  • CSS1.2%
  • HTML0.2%

[8]ページ先頭

©2009-2025 Movatter.jp