Handle
With Handle=".handle" a row can only be dragged by grabbing the handle icon. The rest of the row
keeps its normal pointer behaviour: its text can be selected, its inputs focused and typed into, its buttons
clicked.
A drag handle
Handle is a CSS selector, matched inside each item. Press anywhere else on a row and nothing is
dragged - select its text instead.
☰Item 1
☰Item 2
☰Item 3
☰Item 4
☰Item 5
☰Item 6
To pick up the item, press Space or Enter. While it is picked up, the arrow keys move it, Home and End move it to the start or the end of its list, Space or Enter drops it, and Escape puts it back.
Order: Item 1, Item 2, Item 3, Item 4, Item 5, Item 6
Rows with controls
Where a handle earns its place: rows that hold controls. Each step of this checklist is an input you can click into and edit, with a checkbox to tick - and the grip on the left reorders the steps.
☰
☰
☰
☰
To pick up the item, press Space or Enter. While it is picked up, the arrow keys move it, Home and End move it to the start or the end of its list, Space or Enter drops it, and Escape puts it back.
Steps: Pack the tent, Check the weather ✓, Fill the water bottles, Charge the torch
Try it
- Drag a row of the first list by its body: nothing moves, and the text can be selected. Drag it by ☰: it sorts.
- In the checklist, click into a step and edit it, tick its box, then reorder it by ☰ - the edit and the tick travel with it, because they live in the item.
- From the keyboard nothing changes: Tab to a row (not to the input inside it) and Space picks it up. Keys pressed inside the input are the input's - Space types a space.
- On a touch screen a handle still needs the long press; the touch page shows a handle that drags at once.
How it works
-
With a
Handle, items render as not draggable. Pressing an element that matches the selector makes its item draggable for the drag that follows; the next press starts from undraggable again. -
The list's container gets the
bit-bortable-has-handleclass, which the stylesheet uses to take the grab cursor and the no-select rule off the rest of the item. Give the handle its own grab cursor. - A handle belongs to the item it sits in: in nested lists, a handle of an inner list's item never drags the outer item around it.
- An invalid selector does not break the page: the browser layer warns once in the console, and no item drags.
-
For a handle that a keyboard user reaches as well, make it a
<button type="button">with an accessible name: it picks its item up too.
Parameters on this page
| Parameter | Here | What it does |
|---|---|---|
Handle | .handle | The CSS selector of the element, inside each item, that starts a drag. |
ItemLabel | s => s.Text | How announcements name a step: by its text, as it is now. |
AriaLabel | Checklist | The list's accessible name. |