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

handleClickOn (and associated handlers) don’t fire for node views #99

Open
steobrien opened this issue Feb 10, 2024 · 1 comment
Open
Labels
bug Something isn't working

Comments

@steobrien
Copy link

steobrien commented Feb 10, 2024

I noticed this difference in behavior between a regular prosemirror NodeView, and one created by useNodeViews:

  • For a vanilla NodeView, an editor-attached handleClickOn fires, for a click within the NodeView, or elsewhere in the editor, as documented/expected
  • For a useNodeViews NodeView, a click within the NodeView does not fire, but other editor clicks do

This is also the case for handleDoubleClickOn and handleTripleClickOn.

I think this behavior should be consistent?

Vanilla implementation

class Pill {
  constructor(node) {
    this.dom = document.createElement("div");
    this.dom.innerText = node.attrs.text;
  }
}

// in component
<ProseMirror
  nodeViews={{
    pill(node) { return new Pill(node); },
  }}
  // other editor props
>

useNodeViews implementation

function Pill({ node }) {
  return (
    <span>{node.attrs.text}</span>
  );
}

const reactNodeViews = {
  pill: () => {
    const dom = document.createElement("div");
    dom.style.display = "contents";
    return {
      component: Pill,
      dom,
    };
  },
};

// passed to <ProseMirror> with `useNodeViews` as per README example
@steobrien
Copy link
Author

Interestingly, if I replace <span>{node.attrs.text}</span> with an unwrapped <>{node.attrs.text}</>, the event does propagate as expected.

@tilgovi tilgovi added the bug Something isn't working label Feb 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants