Skip to content

[lexical-playground] Bug Fix: Show the floating toolbar as a clickable row after a block drag - #9966

Open
burrows99 wants to merge 4 commits into
meta:mainfrom
burrows99:fix/floating-toolbar-after-block-drag
Open

burrows99 wants to merge 4 commits into
meta:mainfrom
burrows99:fix/floating-toolbar-after-block-drag

Conversation

@burrows99

Copy link
Copy Markdown

Description

After a block is dragged by its handle and dropped while text is selected, the playground's floating format toolbar comes back squeezed into one narrow column, and its buttons do not respond to the first click.

Two things in FloatingTextFormatToolbarPlugin cause it:

  • The toolbar is hidden with an inline display: none on dragstart. On drop / dragend it was set back to display: block, which overrides the stylesheet's display: flex, so the buttons wrap into a single column. It now clears the inline value ('') so the stylesheet applies again.
  • While the mouse button is held and the pointer leaves the toolbar (the start of the drag), the mousemove listener sets pointer-events: none, and only a mouseup turns it back on. An HTML5 drag ends with drop / dragend and no mouseup, so the toolbar stayed click-through: clicking Bold after a drop hit the editor underneath and cleared the selection. The same drag-end handler now sets pointer-events: auto.
flowchart TD
    A[Select text then drag a block by its handle] --> B{Drop the block}
    B -->|Before| C[Toolbar is one narrow column and Bold clicks fall through]
    B -->|After| D[Toolbar is one row and Bold formats the selection]
Loading

Closes #9964

Changeset

None: the change is in the playground only (no published package changes).

Test plan

Narrated recording, before then after (sound on):

evidence.mp4

The recording drives the playground dev server (?emptyEditor=false for the welcome content) in headless Chrome: select text, drag the "Lastly..." paragraph by its handle, drop it, then click Bold.

Before

The toolbar comes back as a single column of buttons (inline style display: block; pointer-events: none); clicking Bold clears the selection and nothing is formatted.

After

The toolbar comes back as one row (inline display cleared, pointer-events: auto); clicking Bold formats the selected text.

Edge cases and unchanged behaviour checked

In the running playground (shown in the third part of the video):

  • Unchanged: a plain mouse selection shows the full toolbar.
  • Unchanged: the toolbar stays hidden while a block is being dragged.
  • Edge case: dragging the paragraph that holds the selection; the toolbar follows it as one row and Italic works.
  • Edge case: dropping a block back onto itself (nothing moves, drop still fires); the toolbar is one row and Strikethrough works.

By unit test only: the dragend path (a drag that ends without a drop on the page).

Automated

Added two cases to packages/lexical-playground/__tests__/unit/FloatingTextFormatToolbar.test.tsx (one per drag-end event: drop and dragend). They fail on main (expected 'block' to be '') and pass with the fix.

npx vitest run --project unit packages/lexical-playground/__tests__/unit/FloatingTextFormatToolbar.test.tsx
 Test Files  1 passed (1)
      Tests  3 passed (3)

prettier --check and eslint pass on both changed files. I did not run the full ci-check (tsc / flow) or the e2e suites.

AI assistance (Claude Code) was used to investigate, write and record this change.

🤖 Generated with Claude Code

…e row after a block drag

The toolbar's drag-end handler set an inline display of 'block', which
overrode the stylesheet's flex layout and stacked the buttons in one
column. Clear the inline display instead. A drag also ends without the
mouseup that turns the toolbar's pointer events back on, so turn them on
there too; otherwise the first click on a button fell through to the
editor and dropped the selection.

Fixes meta#9964
@vercel

vercel Bot commented Nov 22, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
lexical Ready Ready Preview Nov 23, 2026 1:09pm UTC
lexical-playground Ready Ready Preview Nov 23, 2026 1:09pm UTC

Request Review

@meta-cla

meta-cla Bot commented Nov 22, 2026

Copy link
Copy Markdown

Hi @burrows99!

Thank you for your pull request and welcome to our community.

Action Required

In order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you.

Process

In order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA.

Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with CLA signed. The tagging process may take up to 1 hour after signing. Please give it that time before contacting us about it.

If you have received this in error or have any questions, please contact us at cla@meta.com. Thanks!

@rootnode-bot

rootnode-bot Bot commented Nov 22, 2026 •

Copy link
Copy Markdown

AI review status for this pull request.

Review status Updated
🟢 Reviewed (for maintainers only) Nov 23, 2026, 1:26 PM UTC

@rootnode-bot rootnode-bot Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the clear write-up and the before/after recording. This looks good to me.

The drag-end handler in packages/lexical-playground/src/plugins/FloatingTextFormatToolbarPlugin/index.tsx (lines 455-465) now clears the inline display, so the stylesheet's display: flex applies again. It also sets pointer-events: auto to undo what the mousemove listener writes when the drag starts. I reproduced both halves in Chromium on the playground's welcome content. On main the toolbar comes back as a single narrow column, and a click on Bold lands on the editor and clears the selection. With this change it comes back as one row and the same click bolds the selected word. The two new unit cases fail on main with expected 'block' to be '' and pass with the fix.

Optional, non-blocking suggestions:

  1. An E2E test for the real drag. The new cases in __tests__/unit/FloatingTextFormatToolbar.test.tsx run in jsdom, set pointer-events: none by hand and check inline style strings, so they would not catch a regression in layout or in which element receives the click. AGENTS.md ("Testing Strategy") puts behaviour that depends on real layout and input in browser or E2E tests, and the E2E suite already has what this needs: dragDraggableMenuTo in packages/lexical-playground/__tests__/utils/index.mjs, used by DraggableBlock.spec.mjs. A spec that selects a word, drags a block by its handle, clicks Bold and asserts the word is bold would pin the behaviour users see.
  2. Test plan output. AGENTS.md ("Commits and Pull Requests") asks the Test plan to paste the real failing output under Before as well as the passing output under After. The Before for the unit test is currently described rather than pasted.

No changeset is needed: the change is confined to the playground, which CONTRIBUTING.md and AGENTS.md exempt.

Automated review (maintainer link)

@rootnode-bot rootnode-bot Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the fix, this looks good to me. Clearing the inline display lets the stylesheet's display: flex apply again. Resetting pointer-events in the same drag-end handler covers the mouseup that never arrives after an HTML5 drag. The new unit cases fail without the change and pass with it. The playground behaves as described: after a block is dropped, the toolbar is a row and Bold formats the selection, including when the drag ends with only dragend (released outside the editor).

Optional, non-blocking suggestions:

  1. An E2E for the drag-then-click path in packages/lexical-playground/__tests__/e2e/DraggableBlock.spec.mjs. jsdom can't lay out flex or hit-test, so the unit cases check inline style values rather than what the user sees, and AGENTS.md (Testing Strategy) puts real layout and input behaviour in the browser and E2E tiers. One detail if you add one: dragDraggableMenuTo → dragMouse (__tests__/utils/index.mjs:1348-1354) moves from the handle to the target in one step. When I tried a direct move like that, the page saw no held-button mousemove before dragstart, and the toolbar stayed clickable even without the fix. Press the mouse and move a pixel or two before the long move to reproduce the pointer-events half, then assert the popup's computed display is flex and that clicking Bold makes the selected text bold.
  2. Drive the real listener in the unit test (FloatingTextFormatToolbar.test.tsx:120). Instead of setting popup.style.pointerEvents = 'none' by hand, you could stub document.elementFromPoint (jsdom doesn't implement it) and dispatch new MouseEvent('mousemove', {buttons: 1}). The test would then also break if the listener's condition changes.
  3. Test plan output. AGENTS.md ("Commits and Pull Requests") asks the ### Before section to carry the pasted failing output of the command you ran. The expected 'block' to be '' failure from the vitest run would fit there.

No changeset is needed: AGENTS.md and CONTRIBUTING.md both exempt playground-only changes.

Automated review (maintainer link)

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Nov 22, 2026
@meta-cla

meta-cla Bot commented Nov 22, 2026

Copy link
Copy Markdown

Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Meta Open Source project. Thanks!

@pkg-pr-new

pkg-pr-new Bot commented Nov 22, 2026 •

Copy link
Copy Markdown
lexical

npm i https://pkg.pr.new/lexical@9966

@lexical/a11y

npm i https://pkg.pr.new/@lexical/a11y@9966

@lexical/clipboard

npm i https://pkg.pr.new/@lexical/clipboard@9966

@lexical/code

npm i https://pkg.pr.new/@lexical/code@9966

@lexical/code-core

npm i https://pkg.pr.new/@lexical/code-core@9966

@lexical/code-prism

npm i https://pkg.pr.new/@lexical/code-prism@9966

@lexical/code-shiki

npm i https://pkg.pr.new/@lexical/code-shiki@9966

@lexical/compiler

npm i https://pkg.pr.new/@lexical/compiler@9966

@lexical/devtools-core

npm i https://pkg.pr.new/@lexical/devtools-core@9966

@lexical/dragon

npm i https://pkg.pr.new/@lexical/dragon@9966

@lexical/eslint-plugin

npm i https://pkg.pr.new/@lexical/eslint-plugin@9966

@lexical/extension

npm i https://pkg.pr.new/@lexical/extension@9966

@lexical/fast-check

npm i https://pkg.pr.new/@lexical/fast-check@9966

@lexical/file

npm i https://pkg.pr.new/@lexical/file@9966

@lexical/hashtag

npm i https://pkg.pr.new/@lexical/hashtag@9966

@lexical/headless

npm i https://pkg.pr.new/@lexical/headless@9966

@lexical/history

npm i https://pkg.pr.new/@lexical/history@9966

@lexical/html

npm i https://pkg.pr.new/@lexical/html@9966

@lexical/internal

npm i https://pkg.pr.new/@lexical/internal@9966

@lexical/link

npm i https://pkg.pr.new/@lexical/link@9966

@lexical/list

npm i https://pkg.pr.new/@lexical/list@9966

@lexical/mark

npm i https://pkg.pr.new/@lexical/mark@9966

@lexical/markdown

npm i https://pkg.pr.new/@lexical/markdown@9966

@lexical/mdast

npm i https://pkg.pr.new/@lexical/mdast@9966

@lexical/offset

npm i https://pkg.pr.new/@lexical/offset@9966

@lexical/overflow

npm i https://pkg.pr.new/@lexical/overflow@9966

@lexical/plain-text

npm i https://pkg.pr.new/@lexical/plain-text@9966

@lexical/react

npm i https://pkg.pr.new/@lexical/react@9966

@lexical/rich-text

npm i https://pkg.pr.new/@lexical/rich-text@9966

@lexical/selection

npm i https://pkg.pr.new/@lexical/selection@9966

@lexical/table

npm i https://pkg.pr.new/@lexical/table@9966

@lexical/tailwind

npm i https://pkg.pr.new/@lexical/tailwind@9966

@lexical/text

npm i https://pkg.pr.new/@lexical/text@9966

@lexical/utils

npm i https://pkg.pr.new/@lexical/utils@9966

@lexical/y

npm i https://pkg.pr.new/@lexical/y@9966

@lexical/yjs

npm i https://pkg.pr.new/@lexical/yjs@9966

commit: d441e7c

…floating toolbar drag test

Stub document.elementFromPoint (jsdom has none) and dispatch a held-button
mousemove instead of setting pointer-events by hand, so the case also
breaks if the listener's condition changes.

@rootnode-bot rootnode-bot Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the fix, this looks good. Clearing the inline display lets the stylesheet's display: flex apply again, and restoring pointer-events in the same drag-end handler covers an HTML5 drag ending without the mouseup that would normally turn them back on. The updated test now drives the real mousemove listener, so both the drop and dragend cases fail without the fix and pass with it.

Optional, non-blocking suggestions:

  1. An end-to-end case for the user-visible behaviour (packages/lexical-playground/__tests__/e2e/DraggableBlock.spec.mjs). The unit cases assert inline style values, which is what jsdom can see; the stacked column and the click falling through to the editor only show up in a real browser, and AGENTS.md's testing strategy puts behaviour that depends on real layout in browser or E2E tests. A case that selects a word, drags a block with dragDraggableMenuTo, clicks the floating toolbar's Bold button and asserts the word is bold would keep both halves of this fix from regressing.
  2. Test plan output (nit). AGENTS.md (Commits and Pull Requests) asks ### Before and ### After to carry the command you ran with its real failing and passing output. Pasting the full vitest failure from main under ### Before and the passing run under ### After would match that; the description of the playground behaviour can stay beside it.

No changeset is needed: CONTRIBUTING.md and AGENTS.md exempt playground-only changes, and a maintainer can add the skip-changeset label if CI asks for one.

Automated review (maintainer link)

This branch was successfully deployed

2 active deployments
Preview – lexical — d441e7c0 Deployed Nov 23, 2026 by vercel[bot]
Preview – lexical-playground — d441e7c0 Deployed Nov 23, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: Floating menu breaks after drag-and-drop with an active selection

1 participant