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

Request: optional shouldShow parameter for FloatingMenu and BubbleMenu #1480

Closed
thatsjonsense opened this issue Jun 16, 2021 · 1 comment · Fixed by #1714
Closed

Request: optional shouldShow parameter for FloatingMenu and BubbleMenu #1480

thatsjonsense opened this issue Jun 16, 2021 · 1 comment · Fixed by #1714
Labels
Type: Feature The issue or pullrequest is a new feature

Comments

@thatsjonsense
Copy link
Contributor

thatsjonsense commented Jun 16, 2021

The problem I am facing
In both the FloatingMenu and BubbleMenu, I wish I could customize the logic for when the menu displays.

Two specific use cases:

  • In BubbleMenu, I want to trigger even when the selection is empty if you click inside a link
  • In FloatingMenu, I want to trigger at depth 2 instead of depth 1 because my schema is a document with multiple sections

The solution I would like
An optional shouldShow function I can pass in the options to these menus where I can write my own logic. This would be consumed in the update method of each plugin. If you don't provide your own, it would use the default. Ideally, you could also access the default method from your custom one to do an OR.

Alternatives I have considered
Right now I've forked both menus just to change 1 line of logic in each one, which means it's hard to stay up to date with future improvements.

bubble-menu-plugin:

    if (empty || isEmptyTextBlock) {
      // OUR CUSTOM LOGIC STARTS HERE
      const isLink = selection.$anchor
        .marks()
        .some((mark) => mark.type.name === 'link')
      if (!isLink) {
        this.hide()
        return
      }
      // END OUR CUSTOM LOGIC
    }

floating-menu-plugin:

const isRootDepth = $anchor.depth === 2 // Was 1
@thatsjonsense thatsjonsense added Type: Feature The issue or pullrequest is a new feature v2 labels Jun 16, 2021
@philippkuehn
Copy link
Contributor

Yes, this is something I want to add! Additionally it would be great to add multiple instances of the menus with different configuration.

philippkuehn added a commit that referenced this issue Aug 11, 2021
…1043, fix #1268, fix #1503)

* add key option to bubble menu

* ignore react for now

* add shouldShow option to bubble menu extension

* improve types

* remove BubbleMenuPluginKey

* add key and shouldShow option to floating menu extension

* fix: don’t show floating menu within code block

* docs: add new menu options
andrewlu0 pushed a commit to trybaseplate/tiptap that referenced this issue Oct 20, 2023
, fix ueberdosis#1043, fix ueberdosis#1268, fix ueberdosis#1503)

* add key option to bubble menu

* ignore react for now

* add shouldShow option to bubble menu extension

* improve types

* remove BubbleMenuPluginKey

* add key and shouldShow option to floating menu extension

* fix: don’t show floating menu within code block

* docs: add new menu options
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Feature The issue or pullrequest is a new feature
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants