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

[Example Request]: Toggle Action Menu programmatically #447

Open
1 task done
niraj-khatiwada opened this issue Feb 6, 2025 · 0 comments
Open
1 task done

[Example Request]: Toggle Action Menu programmatically #447

niraj-khatiwada opened this issue Feb 6, 2025 · 0 comments

Comments

@niraj-khatiwada
Copy link

What's the example?

Is there a way to programmatically open the action menu? My requirement is when user presses the "Enter" key on a new block and if the block is empty, I need to prompt user to select the block type for which I need to trigger the action menu. I figured out the keyboarding handling part but couldn't figure out how to open action menu programmatically. I also tried setting the block content to "/" hoping that it'll trigger the menu via shortcut but doesn't seem to work.
Thanks for the awesome library.

import { PluginEvents } from '@yoopta/editor/dist/plugins/types'

export const events: Partial<PluginEvents> = {
  onKeyDown: (editor, _, options) => {
    return evt => {
      // Block entering new line when text is empty and trigger the action list.
      if (options.hotkeys.isEnter(evt)) {
        if (
          'children' in options?.currentBlock?.value?.[0] &&
          'text' in options?.currentBlock?.value?.[0]?.children?.[0]
        ) {
          const text = options?.currentBlock?.value?.[0]?.children?.[0]?.text as string
          if (text?.length === 0) {
            evt.preventDefault()
            // TODO: Need to trigger the action menu.
          }
        }
      }
    }
  },
}

Code of Conduct

  • I agree to follow this project's Code of Conduct
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

No branches or pull requests

1 participant