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

Tap to the left of a checkbox in iOS browsers results in the caret moving to the end of the document #1424

Open
xenohunter opened this issue Oct 30, 2023 · 0 comments

Comments

@xenohunter
Copy link

In iOS browsers, if you add a single checkbox to a line (nothing to the right of it, not even spaces) and tap directly to the left of the checkbox, the caret position moves to the end of the last line in the editor.

Happens in: Safari iOS, Chrome iOS. (Android seems to be unaffected, couldn't reproduce.)

Code needed to reproduce

Checkbox NodeSpec:

const checkbox = {
  group: "inline",
  selectable: false,
  inline: true,
  attrs: { isChecked: { default: false } },
  toDOM(node) {
    return [
      "label",
      { class: "checkbox-wrapper", contenteditable: "false" },
      [
        "input",
        {
          type: "checkbox",
          ...(node.attrs.isChecked ? { checked: "true" } : undefined),
        },
      ],
    ];
  },
  parseDOM: [
    {
      tag: "input",
      getAttrs: (dom) => {
        if (typeof dom != "string")
          return {
            isChecked: (dom as any).getAttribute("checked") === "true",
          };
        else return {};
      },
    },
  ],
};

To run it, the ProseMirror basic example has been used with the following changes:

const nodes = schema.spec.nodes.addToEnd("checkbox", checkbox);

const mySchema = new Schema({
  nodes: addListNodes(nodes, "paragraph block*", "block"),
  marks: schema.spec.marks,
});

function App() {
  const view = useRef<EditorView>();
  const editorDiv = useRef<HTMLDivElement>(null);
  useEffect(() => {
    view.current = new EditorView(editorDiv.current, {
      state: EditorState.create({
        doc: mySchema.nodeFromJSON({ type: "doc", content: [{ type: "paragraph" }] }),
        plugins: [...exampleSetup({ schema: mySchema })],
      }),
    });
    return () => {
      view.current?.destroy();
    };
  }, []);

  return (
    <div className="App">
      <h1>Prosemirror Basic Example</h1>
      <div style={{
        display: "flex",
        flexDirection: "column",
        alignItems: "center",
      }}>
        <div
          id="editor"
          ref={editorDiv}
          style={{
            width: 600,
            height: 300,
            textAlign: "left"
          }}
        />
      </div>
    </div>
  );
}

const root = ReactDOM.createRoot(document.getElementById("root") as HTMLElement);
root.render(
  <React.StrictMode>
    <App />
  </React.StrictMode>
);
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