Skip to content

Basic Context Menu (behind Switch) - #4285

Merged
tylerjbainbridge merged 8 commits into
mainfrom
new-context-menu-v1
May 23, 2023
Merged

tylerjbainbridge merged 8 commits into
mainfrom
new-context-menu-v1

Conversation

@tylerjbainbridge

@tylerjbainbridge tylerjbainbridge commented Apr 7, 2023 •

Copy link
Copy Markdown
Contributor

Basic working context menu built with LexicalMenus so there's built in support for keyboard interaction, positioning, and an identical API to typeaheads, autoembeds, etc.

WIP demo

Screen.Recording.2023-04-07.at.3.09.20.PM.mov

@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 Apr 7, 2023
@vercel

vercel Bot commented Apr 7, 2023 •

Copy link
Copy Markdown

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 May 22, 2023 7:01pm
lexical-playground ✅ Ready (Inspect) Visit Preview 💬 Add feedback May 22, 2023 7:01pm

@github-actions

github-actions Bot commented Apr 7, 2023 •

Copy link
Copy Markdown

size-limit report 📦

Path Size Loading time (3g) Running time (snapdragon) Total time
packages/lexical/dist/Lexical.js 27.25 KB (0%) 546 ms (0%) 257 ms (+56.27% 🔺) 802 ms
packages/lexical-rich-text/dist/LexicalRichText.js 38.2 KB (0%) 765 ms (0%) 327 ms (+24.41% 🔺) 1.1 s
packages/lexical-plain-text/dist/LexicalPlainText.js 38.18 KB (0%) 764 ms (0%) 519 ms (+100.38% 🔺) 1.3 s

@ivailop7

ivailop7 commented May 15, 2023 •

Copy link
Copy Markdown
Collaborator

Hey, @tylerjbainbridge, any plans for updating this one, since the generic part is now merged?

@tylerjbainbridge

Copy link
Copy Markdown
Contributor Author

Hey, @tylerjbainbridge, any plans for updating this one, since the generic part is now merged?

Thanks for the reminder. I'll try to get this merged today.

@ivailop7 ivailop7 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Wasn't sure, if I should review, since it's still a draft, but this looks pretty complete to me to what what's in the PR description

@tylerjbainbridge
tylerjbainbridge marked this pull request as ready for review May 16, 2023 17:58
selectedIndex: number | null;
selectOptionAndCleanUp: (option: TOption) => void;
setHighlightedIndex: (index: number) => void;
options: Array<TOption>;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Are we planning to add the ability to have nested options?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Not yet, but good call-out.

All LexicalMenu's are flat right now but I can see this being helpful in the future.

(event: MouseEvent) => {
event.preventDefault();
openNodeMenu({
getRect: () => new DOMRect(event.clientX, event.clientY, 1, 1),

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

1, 1?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Kind of a hack, but the menus are positioned using a div (in this case 1px by 1px) that is replaced with React portal's content. I can add enums though.

Comment on lines +151 to +157
onOptionClick={(option: ContextMenuOption, index: number) => {
setHighlightedIndex(index);
selectOptionAndCleanUp(option);
}}
onOptionMouseEnter={(index: number) => {
setHighlightedIndex(index);
}}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think this is fine, alternatively we can tell the user which one is highlighted and request what action to take beforehand, more like a framework-like approach instead of a library, but what you have is good imo

This branch was successfully deployed

2 active deployments
Preview – lexical-playground — a4d317b2 Deployed May 22, 2023 by vercel[bot]
Preview – lexical — a4d317b2 Deployed May 22, 2023 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.

4 participants