Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement Floating UI for positioning floating elements #14139

Open
19 of 20 tasks
tay1orjones opened this issue Jul 5, 2023 · 9 comments
Open
19 of 20 tasks

Implement Floating UI for positioning floating elements #14139

tay1orjones opened this issue Jul 5, 2023 · 9 comments
Labels
planning: umbrella Umbrella issues, surfaced in Projects views proposal: accepted This request has gone through triaging and we are accepting PR's against it. role: dev 🤖 type: enhancement 💡
Milestone

Comments

@tay1orjones
Copy link
Member

tay1orjones commented Jul 5, 2023

The problem

All across the system we have components that render various types of floating elements. Each of these cannot be rendered via a portal because it fails SC 1.3.2: meaningful sequence.

Due to this, there are a bunch of situations where floating elements don't render properly above other elements:

Modal

Issues already resolved by this workstream

Popover's autoAlign prop was a step towards attempting to rectify this situation by adding some logic for overflow detection and reflow #11508, but it has a few limitations/drawbacks:

  • Lots of rendering/calculation logic encapsulated in the component that isn't reusable across the system
  • Overall hasn't been optimized and is still experimental
  • Only works on the first render
  • Only detects window/viewport boundaries, doesn't detect container boundaries
  • Can't be modified to include additional padding for overflow detection

Proposed solution

Use floating-ui for positioning of floating elements.

It's licensed MIT, has an intuitive api, is extensible, and is quickly becoming a de-facto solution for this type of positioning. It's the successor to the popular popper.js library.

It includes collision detection and we could enable the feature behind experimental props.

There are ready-made packages for react, react-native, and vue. The @floating-ui/dom package can be used for other framework implementations of Carbon (web components, angular, etc).

It's worth mentioning Radix UI and Fluent UI Web are using it, as are some others

This also could open up the possibility for more easily implementing advanced positioning features such as:

Questions and concerns

General items, open questions to resolve

Preview Give feedback
  1. role: dev 🤖 status: help wanted 👐 status: needs more info status: waiting for maintainer response 💬
    annawen1 ariellalgilmore
    preetibansalui

@carbon/react

Preview Give feedback
  1. component: popover role: dev 🤖 type: infrastructure 🤖
  2. component: popover role: dev 🤖 type: infrastructure 🤖
    tay1orjones
  3. 1 of 1
    area: typescript role: dev 🤖 type: bug 🐛
    2nikhiltom
  4. component: dropdown role: dev 🤖
    2nikhiltom preetibansalui
  5. component: combobox
    Gururajj77
  6. guidari
  7. role: dev 🤖 severity: 2 type: bug 🐛
    riddhybansal tay1orjones
  8. component: combo-button package: @carbon/react
    riddhybansal
  9. component: overflow-menu package: @carbon/react
    preetibansalui
  10. component: overflow-menu package: @carbon/react
    2nikhiltom
  11. 4 of 4
    guidari preetibansalui
    riddhybansal tay1orjones
  12. planning: umbrella type: enhancement 💡
    preetibansalui tay1orjones
  13. 4 of 4
    component: combobox component: dropdown component: filterable-multiselect component: multiselect planning: umbrella severity: 2 type: bug 🐛
  14. component: button package: @carbon/react proposal: accepted severity: 3 type: bug 🐛 type: enhancement 💡 type: infrastructure 🤖
    preetibansalui
  15. component: code-snippet component: copy-button role: dev 🤖 type: enhancement 💡
    preetibansalui

@carbon/ibm-products

Preview Give feedback
  1. 0 of 2
    area: plg ✨ role: dev
    devadula-nandan
  2. 2 of 2
    component: TagSet role: dev
    davidmenendez
  3. 0 of 2
    component: TagSet role: dev
    davidmenendez
  4. 0 of 1
    area: migration ➡️ component: PageHeader role: dev
    devadula-nandan
@tay1orjones tay1orjones changed the title Use floating-ui for positioning floating elements Use floating-ui for positioning floating elements Jul 5, 2023
@github-project-automation github-project-automation bot moved this to Triage in Roadmap Jul 5, 2023
@tay1orjones tay1orjones changed the title Use floating-ui for positioning floating elements Proposal: Use floating-ui for positioning floating elements Jul 5, 2023
@tay1orjones tay1orjones added the proposal: open This request has gone through triaging. We're determining whether we take this on or not. label Jul 6, 2023
@sstrubberg sstrubberg moved this from Triage to Later in Roadmap Aug 9, 2023
@sstrubberg sstrubberg added proposal: accepted This request has gone through triaging and we are accepting PR's against it. and removed proposal: open This request has gone through triaging. We're determining whether we take this on or not. labels Aug 9, 2023
@sstrubberg sstrubberg moved this from Later to Next in Roadmap Aug 22, 2023
@matthewgallo
Copy link
Member

matthewgallo commented Aug 28, 2023

I did some exploration into floating-ui after you presented a bit about it last Friday @tay1orjones. It definitely feels like a good solution to some of the issues that are linked above (popover elements inside of modals, ie OverflowMenus, Dropdowns, menu button issues). It also addresses #6551, allowing floating menus to auto align based on available space.

I have put together two prototypes using floating-ui to do some research here, one that is most akin to the new MenuButton component and another to add that new MenuButton to Carbon for IBM Products Datagrid to test in context.

  1. MenuButton - https://stackblitz.com/edit/github-28pu2z-tyjd7f
  2. MenuButton in Datagrid - https://stackblitz.com/edit/github-j7ci5k

@tay1orjones tay1orjones moved this from 🪆 Needs Refined to 🏗 In Progress in Design System May 22, 2024
@tay1orjones
Copy link
Member Author

@kurtwaldowski-b right now Datepicker isn't on the list because it doesn't have any alignment or positioning options/props. The only reason to add floating-ui to it would be to avoid the issue of it being clipped within another component like a modal. To my knowledge we don't have an issue reporting that. Could you provide an example in a stackblitz of it not working properly? With that reproduction we can open a new issue for it.

@ljcarot ljcarot moved this from 🏗 In progress to ✅ Done in Carbon for AI Jun 10, 2024
@sstrubberg sstrubberg modified the milestones: 2024 Q2, 2024 Q3 Jun 28, 2024
@kurtwaldowski-b
Copy link

kurtwaldowski-b commented Jul 1, 2024

@kurtwaldowski-b Yes, but we had to break this up into different phases. The initial phase to add this to Popover, Tooltip, Toggletip and Slug has been delivered in #14654 and should go out in @carbon/[email protected]. We're targeting the remaining pieces for Q2.

Thanks! Do you know if the floating-ui updates will be applied to IconButtons? We are still seeing IconButton tooltips being cut off by parent containers for example:

image

Curious as well on autoAlign

Thanks!

@kurtwaldowski-b
Copy link

Following up here; this update should be applied to both Buttons and IconButtons for consistent behavior. I opened the following to address it with a stackblitz: #17168

Its forcing us to do some wonky things like add a Tooltip around an IconButton and then hide the built in tooltip with styling :/

@elycheea
Copy link
Contributor

@kurtwaldowski-b right now Datepicker isn't on the list because it doesn't have any alignment or positioning options/props. The only reason to add floating-ui to it would be to avoid the issue of it being clipped within another component like a modal. To my knowledge we don't have an issue reporting that. Could you provide an example in a stackblitz of it not working properly? With that reproduction we can open a new issue for it.

@rodet just opened an issue in our repo on DatePicker being clipped, which links to our Storybook.
carbon-design-system/ibm-products#6083

@sstrubberg
Copy link
Member

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
planning: umbrella Umbrella issues, surfaced in Projects views proposal: accepted This request has gone through triaging and we are accepting PR's against it. role: dev 🤖 type: enhancement 💡
Projects
Status: 🏗 In Progress
Status: Now 💫
Development

No branches or pull requests