ProseMirror / prosemirror

The ProseMirror WYSIWYM editor
http://prosemirror.net/
MIT License
7.61k stars 336 forks source link

event.stopPropagation() does not stop parent element event from being call #1346

Closed coolcorexix closed 1 year ago

coolcorexix commented 1 year ago

I tried to create an extension for Tiptap editor for timestamp link and it use addProseMirrorPlugins. On the handle click, I set up like this:

handleClick: (view, pos, event) => {
            event.stopPropagation();
            if (!this.options.timestampClickHandler) return false;

            const attrs = this.editor.getAttributes('timestampLink');
            const link = event.target?.closest('a');

            if (link && attrs.timestamp) {
              this.options.timestampClickHandler(attrs.timestamp);
              return true;
            }

            return false;
          },
        },

But the app still trigger the parent's onClick. I expect it to just do the timestampClickHandler() logic. Am I misunderstanding anything or is it a bug?

marijnh commented 1 year ago

That's just a native event. So whichever way stopPropagation is behaving, that's something your browser is doing, not ProseMirror.

coolcorexix commented 1 year ago

I dont know who need to fix this bug or the document has not mentioned this but the event param of handleClick of ProseMirror is not equivalent to onclick event of new Mark. To stop propagation, I did this

addAttributes() {
    return {
   ...
      onclick: {
        default: 'event.stopPropagation();'
      }
    };
  },
...
addProseMirrorPlugins() { 
...
// nothing to do with DOM stop propagation here