Skip to content

Block side menu show/hide detection fix - #99

Closed
matthewlipski wants to merge 3 commits into
mainfrom
block-side-menu-detection-fix
Closed

matthewlipski wants to merge 3 commits into
mainfrom
block-side-menu-detection-fix

Conversation

@matthewlipski

Copy link
Copy Markdown
Collaborator

This PR changes when the block side menu is shown and hidden. Previously, it only hid the block side menu when the mouse cursor was beyond the horizontal range of the editor. Now, it also hides the menu if the mouse cursor is beyond the horizontal range of the editor (includes a 100px margin to the left of the editor to account for the menu itself, so that it can be clicked). However, this approach is flawed as the menu size and position can change if a custom element is used, is which case the menu will disappear even when hovered/clicked.

There are a few alternative solutions:

  1. The editor's vertical and horizontal range is still used to determine when the menu is shown & hidden, but does not include the left margin for the menu itself. Instead, a timer is used to keep the menu open for some time until it's hovered over, similarly to the hyperlink hover menu. With this approach, the menu won't show up until the block it's next to is hovered.

  2. The editor's vertical and horizontal range is still used to determine when the menu is shown, but again does not include a margin for the menu itself. To hide the menu, we check if the mouse cursor is within the bounding box of the editor or the menu itself. This doesn't work if there is a gap between the menu and the editor, and the menu also won't show up until the block it's next to is hovered.

  3. The editor's vertical range only is still used to determine when the menu is shown & hidden, as before. However, a parent HTML element or CSS selector pointing to a single element, is also used. While the cursor is outside this element, the menu is prevented from showing. This can be implemented in a number of ways:

    1. The HTML element is provided as an option for the DraggableBlocks extension, which defaults to document.body to copy the current behaviour.
    2. A CSS ID is provided as an option for the DraggableBlocks extension, which defaults to e.g. #block-side-menu-detection. The user attaches this CSS ID to any HTML element, so that the menu stays hidden while the mouse cursor is outside of it. If no block with the ID is found, the behaviour is the same as the current implementation.

The fix used in this PR is simpler than the alternatives and seems closest to what Notion is doing. However, I think 3.ii. is the most elegant and provides the best functionality, though I want to make sure this implementation will work for Fermat.

@vercel

vercel Bot commented Feb 16, 2023 •

Copy link
Copy Markdown

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

Name Status Preview Comments Updated
blocknote ✅ Ready (Inspect) Visit Preview 💬 Add your feedback Feb 17, 2023 at 0:31AM (UTC)

This branch was successfully deployed

1 active deployment
Preview — 02b4e9ca Deployed Feb 17, 2023 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants