Skip to content

Editable Node

Nodes can host real form controls. Typing in a field - Backspace and Delete included - edits the text and leaves the graph alone, because the canvas ignores its keys while focus is in an editable element; a drag handle keeps the fields usable by leaving the rest of the node undraggable.

⠿ 1
⠿ 2
bit Blow

Try it

  • Click into a label field and type, using Backspace and Delete freely: the text changes and the node stays.
  • Write in a notes box: a textarea is just as safe.
  • Drag a node by its grip (⠿ and its id) to move it. Pressing or dragging in the fields never moves it.
  • To delete a node, click its grip - that selects the node and takes focus out of the fields - then press Delete or Backspace.

How it works

  • Graph keys - Delete, Backspace, the arrows, Ctrl+A - are ignored while focus is in a text input, textarea, select or contenteditable element, so a field inside a node is safe to type in. Escape still abandons a gesture in progress.
  • Pressing a field still selects its node; it is the focus in the field that keeps Delete from removing it.
  • UseCustomDragHandle = true stops the node's body from starting a drag, and the BlowDragHandle grip starts one instead - so placing the caret or selecting text never moves the node.
  • The label field writes to node.Label on every keystroke, and Label is also the node's accessible name. The notes live in a dictionary on the page, keyed by node id.
  • The other way to hand a field its presses back is the nodrag class (the canvas's NoDragClass) on the field itself, which leaves the rest of the body draggable; the Custom Node example does that.
An unhandled error has occurred. Reload 🗙