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

Node-aware Context Menu Items #5791

Merged
merged 3 commits into from
Apr 1, 2024
Merged

Conversation

ivailop7
Copy link
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.

Copy link

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
@@ -199,10 +203,32 @@ export default function ContextMenuPlugin(): JSX.Element {
[editor],
);

const onWillOpen = (event: MouseEvent) => {
let newOptions = defaultOptions;
editor.update(() => {
Copy link
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
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.

@@ -97,6 +99,9 @@ export function LexicalContextMenuPlugin<TOption extends MenuOption>({
const handleContextMenu = useCallback(
(event: MouseEvent) => {
event.preventDefault();
if (onWillOpen) {
Copy link
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
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