Skip to content

Node-aware Context Menu Items#5791

Merged
acywatson merged 3 commits intofacebook:mainfrom
ivailop7:preopen_hook
Apr 1, 2024
Merged

Node-aware Context Menu Items#5791
acywatson merged 3 commits intofacebook:mainfrom
ivailop7:preopen_hook

Conversation

@ivailop7
Copy link
Copy Markdown
Collaborator

@ivailop7 ivailop7 commented Mar 31, 2024

Expose a 'onWillOpen' method that passes the 'contextmenu' mouse event, so users can do their logic what items should end up in the context menu before it's rendered. Have added an example for 'Link node', that appends an item to 'Remove Link' when a link node is right-clicked. Also fixed wrong positioning of the context menu when the page is scrolled.

@vercel
Copy link
Copy Markdown

vercel bot commented Mar 31, 2024

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 Apr 1, 2024 1:36pm
lexical-playground ✅ Ready (Inspect) Visit Preview 💬 Add feedback Apr 1, 2024 1:36pm

@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 31, 2024

const onWillOpen = (event: MouseEvent) => {
let newOptions = defaultOptions;
editor.update(() => {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This should probably be a read that returns the node type, then call an update onClick

Copy link
Copy Markdown
Collaborator Author

@ivailop7 ivailop7 Apr 1, 2024

Choose a reason for hiding this comment

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

$getNearestNodeFromDOMNode works only inside editor.update(), unsure on why this is the case.

const handleContextMenu = useCallback(
(event: MouseEvent) => {
event.preventDefault();
if (onWillOpen) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Can we be strict with the check here, like for onOpen and onClose?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

updated

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.

3 participants