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

Basic Context Menu (behind Switch) #4285

Merged
merged 8 commits into from May 23, 2023
Merged

Conversation

tylerjbainbridge
Copy link
Contributor

@tylerjbainbridge tylerjbainbridge commented Apr 7, 2023

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

vercel bot commented Apr 7, 2023

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

github-actions bot commented Apr 7, 2023

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
Copy link
Collaborator

ivailop7 commented May 15, 2023

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

@tylerjbainbridge
Copy link
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.

Copy link
Collaborator

@ivailop7 ivailop7 left a comment

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
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
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
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
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
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

@tylerjbainbridge tylerjbainbridge merged commit 0b4b281 into main May 23, 2023
45 checks passed
@tylerjbainbridge tylerjbainbridge deleted the new-context-menu-v1 branch May 23, 2023 16:20
This was referenced May 23, 2023
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.

None yet

4 participants