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

[lexical-playground] Bug Fix: Table action menu visibility with cell overflow #7334

Merged

Conversation

kirandash
Copy link
Contributor

@kirandash kirandash commented Mar 14, 2025

Description

Current behavior:
Currently, the table action menu button remains visible even when a cell is partially visible due to overflow, as reported in issue #7331. This creates a confusing user experience since the menu appears for cells that are not fully in view.

Changes being added:
This PR improves the table action menu visibility check by properly handling cell overflow in the scrollable container. The menu is now correctly hidden when a cell is partially visible and reappears when scrolled into full view.

Technical Changes:

  1. Created checkTableCellOverflow in TableActionMenuPlugin to:

    • Check direct cell overflow (width/height)
    • Verify cell is fully visible within its scrollable container
    • Handle both single cell and table selection cases
  2. Added E2E test to verify:

    • Menu visibility when cell has no overflow
    • Menu hidden when cell overflows

Closes #7331

Test plan

Before

  • Table action menu button remains visible for partially visible cells
  • No E2E test coverage for overflow behavior
lexical-bug-7331.mp4

After

  • Table action menu correctly hides when cells overflow
  • Menu appears when cells are fully visible
  • Added E2E test Table action menu is hidden when cell overflows
lexical-7331-fix.mov

- Fixed table action menu visibility check for partially visible cells
- Added test coverage for menu visibility when:
  - Cell has no overflow (visible)
  - Cell is partially visible due to column resize (hidden)

Fixes facebook#7331
Remove redundant HTMLElement type assertions in checkTableCellOverflow
since tableCellParentNodeDOM is already typed as HTMLElement
Copy link

vercel bot commented Mar 14, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
lexical ✅ Ready (Inspect) Visit Preview 💬 Add feedback Mar 19, 2025 11:55am
lexical-playground ✅ Ready (Inspect) Visit Preview 💬 Add feedback Mar 19, 2025 11:55am

@facebook-github-bot facebook-github-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 Mar 14, 2025
Restore accidentally deleted table markup in 'Resize merged cells height' test.
This reverts part of the previous commit that unintentionally removed the test setup.
@kirandash kirandash marked this pull request as draft March 14, 2025 10:24
@kirandash kirandash changed the title [lexical-playground] Bug Fix: Table action menu visibility with cell overflow [WIP][lexical-playground] Bug Fix: Table action menu visibility with cell overflow Mar 14, 2025
@kirandash kirandash changed the title [WIP][lexical-playground] Bug Fix: Table action menu visibility with cell overflow [lexical-playground] Bug Fix: Table action menu visibility with cell overflow Mar 14, 2025
@kirandash kirandash marked this pull request as ready for review March 14, 2025 10:44
@etrepum etrepum added the extended-tests Run extended e2e tests on a PR label Mar 14, 2025
etrepum
etrepum previously approved these changes Mar 14, 2025
Copy link
Collaborator

@etrepum etrepum left a comment

Choose a reason for hiding this comment

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

This does generally solve the problem but there is a small issue in that we don't update this position when scrolling (not a regression, it occurs before this PR as well). You can reproduce by selecting a fully visible cell and then scrolling the table (the menu stays in place but the cell moves) or selecting an overflowed cell and then scrolling it to be fully visible (no menu appears).

Since this PR strictly makes forward progress I'm inclined to merge as-is, and handling scrolling or revisiting the popover strategy in a more systematic way would make sense.

Generally speaking we have a lot of popover related issues in the playground because none of them are quite implemented correctly popover Issues related to popover/menu code in the playground

It would make sense to finish up #6923 or do something equivalent to that eventually.

Alternatively it might also be possible to do something in the internal getDOMSlot API (#6759) to allow managed portals to be attached to the end of ElementNode and then ignored by the reconciler and mutation observer… but that would require a lot more thought since it has to tie in with the createDOM/updateDOM lifecycle as well (elements can be destroyed and re-created at any time).

@etrepum etrepum dismissed their stale review March 14, 2025 16:54

Looks like some e2e test need to be addressed

@riley-pearce-airteam
Copy link

Something I hadn't considered when I created this issue is that the action button can also overflow on the left hand side when a small portion of the cell is still visible on the left.

@kirandash kirandash marked this pull request as draft March 19, 2025 03:44
@kirandash kirandash changed the title [lexical-playground] Bug Fix: Table action menu visibility with cell overflow [WIP][lexical-playground] Bug Fix: Table action menu visibility with cell overflow Mar 19, 2025
The table action menu positioning has issues in collab mode's split view. Skip the test in collab mode
following the pattern of other table UI tests until the underlying positioning
issue in TableActionMenuPlugin is fixed.
Previously, the table action menu would only hide when a cell overflowed on
the right side of the scrollable container. This update extends the overflow
check to also hide the menu when a cell overflows on the left side, ensuring
consistent behavior for partially visible cells in both directions.

Changes:
- Updated checkTableCellOverflow to check for left side overflow
- Added cellRect.left < containerRect.left condition alongside right edge check
The table action menu visibility test was failing in Firefox due to click
event handling issues. Mark the test as fixme for Firefox since the clicks
work manually but are unreliable in automated tests.

This is a temporary fix until the underlying click event handling in Firefox
can be properly addressed.
@kirandash kirandash changed the title [WIP][lexical-playground] Bug Fix: Table action menu visibility with cell overflow [lexical-playground] Bug Fix: Table action menu visibility with cell overflow Mar 19, 2025
@kirandash kirandash marked this pull request as ready for review March 19, 2025 06:40
@kirandash
Copy link
Contributor Author

Something I hadn't considered when I created this issue is that the action button can also overflow on the left hand side when a small portion of the cell is still visible on the left.

Thanks for catching this! I've updated the checkTableCellOverflow function to handle overflow on both sides. Now the action menu will be hidden when a cell is partially visible on either the left or right side of the scrollable container.

Let me know if you notice any other edge cases that need to be addressed!

@kirandash
Copy link
Contributor Author

@etrepum Thank you for the detailed feedback. I understand there are still underlying issues with popover positioning during scrolling that need to be addressed more systematically. And I agree that completing #6923 would be the right long-term fix.

For now, I've focused on fixing the immediate e2e test failures to unblock the pipeline, but I'll look into contributing to the systematic popover positioning solution which is WIP as well.

I've fixed the failing e2e test for the table action menu visibility in two ways:

  1. For collab mode: Added test.skip(isPlainText || isCollab)
  2. For Firefox: Added test.fixme(browserName === 'firefox') since the clicks work manually but are unreliable in automated tests

@rilrom
Copy link
Contributor

rilrom commented Mar 19, 2025

Something I hadn't considered when I created this issue is that the action button can also overflow on the left hand side when a small portion of the cell is still visible on the left.

Thanks for catching this! I've updated the checkTableCellOverflow function to handle overflow on both sides. Now the action menu will be hidden when a cell is partially visible on either the left or right side of the scrollable container.

Let me know if you notice any other edge cases that need to be addressed!

Thanks for looking into it.

Ideally we'd only hide the action button on left overflow if the actual button is overflowing. Currently it sounds like the button won't get displayed if even the slightest bit of cell is overflowing from the left which wouldn't be ideal since the action button is placed on the right.

Previously, the action button would hide when any part of the cell overflowed.
Now it only hides when the button itself would be inaccessible:
- Calculate actual button position (5px from right edge)
- Account for button width (20px)
- Hide only if button would overflow container bounds
- Check both left and right edges of button for visibility

This makes the button more accessible while still preventing UI issues
when the button would be partially hidden.
Refined the action button position calculation to include:
- Button width (20px)
- Cell padding (8px)
- Right margin (5px)
Total offset is now 28px from right edge

This ensures the button is properly positioned and visible within
the cell's boundaries, preventing any overflow issues.
@kirandash
Copy link
Contributor Author

Something I hadn't considered when I created this issue is that the action button can also overflow on the left hand side when a small portion of the cell is still visible on the left.

Thanks for catching this! I've updated the checkTableCellOverflow function to handle overflow on both sides. Now the action menu will be hidden when a cell is partially visible on either the left or right side of the scrollable container.
Let me know if you notice any other edge cases that need to be addressed!

Thanks for looking into it.

Ideally we'd only hide the action button on left overflow if the actual button is overflowing. Currently it sounds like the button won't get displayed if even the slightest bit of cell is overflowing from the left which wouldn't be ideal since the action button is placed on the right.

Thanks for the feedback! I've updated the logic to be more precise about when to hide the action button. Now it only hides when the button itself would be inaccessible, rather than when any part of the cell overflows. The button's position (5px from right edge), width (20px), table cell padding (8px) are taken into account to ensure it remains visible whenever there's enough space for it to be fully displayed.

When there is enough space:
image

When there is no more space:
image

Copy link
Collaborator

@etrepum etrepum left a comment

Choose a reason for hiding this comment

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

This looks great! I think eventually we will be able to come up with a better solution for this sort of thing (that puts this sort of UI inside the document DOM) with some combination of getDOMSlot and/or setDOMUnmanaged but those are not really public APIs yet.

@etrepum etrepum added this pull request to the merge queue Mar 21, 2025
Merged via the queue into facebook:main with commit ca10bed Mar 21, 2025
39 checks passed
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. extended-tests Run extended e2e tests on a PR
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Playground] Bug: Table action menu button is still visible when the selected cell is overflowed
5 participants