sortablelist

package
v0.3.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 8, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package sortablelist renders a reorderable list with HTML5 drag-and-drop plus keyboard fallback (Space to grab, Arrow up/down to move, Space again to drop, Esc to cancel).

Output structure:

<ol data-fui-comp="ui-sortable-list" role="listbox"
    data-fui-sortable data-fui-sortable-rpc="<path>">
  <li data-fui-sortable-item data-fui-sort-key="<key>"
      draggable="true" tabindex="0" role="option">
    <button class="ui-sortable-list__grip" aria-label="Drag <label>">⋮⋮</button>
    <span class="ui-sortable-list__label">…</span>
  </li>
  …
</ol>

After a successful reorder (mouse or keyboard) the runtime POSTs the new key sequence to RPCPath as form-encoded `order=<comma-sep-keys>`. The server is authoritative — it can reject the reorder by returning non-2xx, in which case the runtime reverts the DOM.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Render

func Render(cfg Config) render.HTML

Render renders the SortableList.

Types

type Config

type Config struct {
	// Items are the entries in initial order (≥1).
	Items []Item
	// Label is the accessible label for the list (required, used as
	// aria-label on the <ol>).
	Label string
	// RPCPath, when set, is POSTed with order=<keys> after every
	// successful reorder. Server responds 2xx to confirm or non-2xx
	// to reject + revert.
	RPCPath    string
	ID         string
	Class      string
	ExtraAttrs html.Attrs
}

Config configures a SortableList.

type Item

type Item struct {
	// Key is the stable identifier the server uses to apply the new
	// order (required).
	Key string
	// Label is the visible row text + accessible label for the drag
	// handle (required).
	Label string
	// Content, when set, replaces Label as the row body. Use for
	// richer rows (icons, badges, etc.). The grip's aria-label still
	// uses Label.
	Content render.HTML
}

Item is one entry in the list.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL