Skip to content

[Example Request]: Toggle Action Menu programmatically #447

Open
@niraj-khatiwada

Description

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

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions