Page MenuHomePhabricator

FloatingUI: Update Menu-using components to use the useFloating composable for positioning
Closed, ResolvedPublic5 Estimated Story Points

Description

Background

Codex has 4 components so far that use the Menu component internally to provide a dropdown menu of options. These components are:

  • Select
  • Combobox
  • Lookup
  • TypeaheadSearch

For the first 3 components, we need to use FloatingUI's useFloating composable to implement positioning features and styles. Ideally, this implementation would be easily extensible to future components that use Menu.

We will not implement FloatingUI in TypeaheadSearch at this time: it should not need any of its features due to its single use in the header in Vector, and will only increase the size of the codex-search package.

Requirements

This task covers only menu positioning and horizontal sizing. Further features will be implemented in other tasks. For this task:

Menus should:

  1. Always remain "attached" to their triggering element
  2. Always have an appropriate width (e.g. in most cases, menus are the width of their triggering element)
  3. Be able to extend past the bounds of their container (e.g. a dialog)

This should all work:

  • With scrolling
  • With window resizing
  • In LTR and RTL

Implementation details

  • Use the floatingStyles object returned by useFloating() to position the menu. This includes:
    • position: floatingStyles.position
    • top: floatingStyles.top
    • right: unset (needed for RTL contexts; no-flip)
    • left: floatingStyles.left (no-flip)
    • transform: floatingStyles.transform
  • Use the size middleware to set the width of the menu
  • Use the hide middleware to hide the menu when its triggering element is out of view, and to set the menu's visibility in CSS
  • Use autoUpdate to recalculate position styles in reaction to certain changes
  • Remove most of the code that previously positioned menus within dialogs, except setting position: static on the parent component when inside a dialog
Code sharing

The above proof-of-concept implements useFloating() for the Select component. We should implement it with a second component, then determine if there is enough repeated code to warrant a custom composable within Codex that implements useFloating() in a standard way that is sharable across menu components.

Open questions
  1. Drop-shadow buffer: OOUI's ClippableElement implemented a 7px buffer to account for off-by-one-pixel errors and to add space for drop-shadows. Do we also want a buffer and, if so, what size?

Acceptance criteria

  • For Select, Combobox, and Lookup:
    • The dropdown menu is the expected width (equal to its triggering element)
    • The dropdown menu is properly placed below the triggering element
    • The dropdown menu always remains "attached" to its triggering element, including on scroll and window resize
  • This works for components inside or outside of a Dialog
  • This works in LTR and RTL

Event Timeline

AnneT changed the task status from Open to In Progress.Sep 13 2023, 8:57 PM
AnneT updated the task description. (Show Details)
AnneT subscribed.

I added notes about making clipping work with scrollable menus because this currently happens when a scrollable menu is clipped:

image.png (732×524 px, 45 KB)

Change 957357 had a related patch set uploaded (by Anne Tomasevich; author: Anne Tomasevich):

[design/codex@main] [PoC, DNM] Implement FloatingUI in Lookup

https://gerrit.wikimedia.org/r/957357

Change 957358 had a related patch set uploaded (by Anne Tomasevich; author: Anne Tomasevich):

[design/codex@main] [PoC, DNM] Add a composable implementing FloatingUI for menus

https://gerrit.wikimedia.org/r/957358

Change 957357 abandoned by Anne Tomasevich:

[design/codex@main] [PoC, DNM] Implement FloatingUI in Lookup

Reason:

merged into the previous patch

https://gerrit.wikimedia.org/r/957357

Change 957358 abandoned by Anne Tomasevich:

[design/codex@main] [PoC, DNM] Add a composable implementing FloatingUI for menus

Reason:

merged into the previous patch

https://gerrit.wikimedia.org/r/957358

AnneT renamed this task from FloatingUI: Update Menu-using components to use the useFloating composable to FloatingUI: Update Menu-using components to use the useFloating composable for positioning.Sep 18 2023, 9:18 PM
AnneT updated the task description. (Show Details)

Change 953740 had a related patch set uploaded (by Anne Tomasevich; author: Anne Tomasevich):

[design/codex@main] Combobox, Lookup, Select: Use FloatingUI

https://gerrit.wikimedia.org/r/953740

Change 953740 merged by jenkins-bot:

[design/codex@main] Combobox, Lookup, Select: Use FloatingUI

https://gerrit.wikimedia.org/r/953740

@bmartinezcalvo I'd recommend the following to test the work done for this patch:

  • Visit the beta docs site and test that Combobox, Lookup, and Select work as expected with no changes. Note that you might see a tiny gap between the triggering element and the dropdown menu; see this comment for an explanation.
  • Visit the sandbox page based on this task's patch and test the final dialog demo, which is triggered by the "With menu components" button. This dialog contains the 3 affected components.

@bmartinezcalvo I'd recommend the following to test the work done for this patch:

  • Visit the beta docs site and test that Combobox, Lookup, and Select work as expected with no changes. Note that you might see a tiny gap between the triggering element and the dropdown menu; see this comment for an explanation.
  • Visit the sandbox page based on this task's patch and test the final dialog demo, which is triggered by the "With menu components" button. This dialog contains the 3 affected components.

@AnneT I've checked it the sandbox page and the dropdown menu works well in all these components. Moving the task to Pending Release.

This is causing a slight issue with the new floating menus:

image.png (562×352 px, 21 KB)

Also, I've checked the beta docs site and I don't see any gap between the component and the menu since for me there is no 0.15px of space between the component (e.g. select) and the menu.

Captura de pantalla 2023-09-25 a las 16.59.49.png (1,330×708 px, 100 KB)

Change 961452 had a related patch set uploaded (by VolkerE; author: VolkerE):

[mediawiki/core@master] Update Codex from v0.19.0 to v0.20.0

https://gerrit.wikimedia.org/r/961452