Board
Columns of cards you move from one column to another, with the card following the pointer and a placeholder marking where it lands.
Goal
A task board, a kanban or a triage view: each column is a list, and a card moves within it or to another column. The columns scroll, and the card must stay visible when it leaves one, so it is lifted out of its column while it moves.
Primitives
- SortableController with
preview: truelifts the card into a layer ondocument.bodythrough PortalController, keeps a placeholder in its slot and moves the placeholder to the target index as the pointer or the keys move. It handles the pointer drag, the keyboard path (Space lifts, the arrows move within the column, PageDown and PageUp move to the next and previous column, Space drops, Escape cancels) and the announcements. - SortableGroup makes the columns containers that exchange cards. There is one controller per column, all sharing the group.
Left to the recipe: where the cards live (here, the DOM: onChange inserts the card into toContainer and focuses it), the look of the lifted card ([data-sortable-state='lifted']) and the placeholder ([data-sortable-placeholder]). The lifted card is no longer inside the example, so its styles select it by its own attribute, not by an ancestor.
Example
Drag a card to another column, or focus one, press Space, press PageDown to move it to the next column, use the arrows to choose its place and press Space to drop it. The first column scrolls.
Pick an authoring pattern below; they all behave the same, and the one you pick is remembered on the other recipes.
The same behavior as a RadiantElement. The markup is authored inside the element and the element finds its parts with @query; there is nothing to mount, clean up or run again.
To do
- Write the brief
- Sketch the layout
- Pick the colors
- Draft the copy
- Review accessibility
- Plan the launch
Doing
- Build the header
- Wire the form
Done
- Set up the repo
Focus a card, press Space, PageDown for the next column, Space to drop
import { RadiantElement, customElement, query, queryAll } from '@ecopages/radiant';
import { SortableGroup, createSortableController } from '@ecopages/radiant-ui/controllers';
@customElement('board-element')
export class BoardElement extends RadiantElement {
@queryAll('ul') private lists!: HTMLElement[];
@query('[data-status]') private status!: HTMLElement;
private readonly group = new SortableGroup();
/**
* One sortable per column.
*
* @remarks
* A controller binds to the host when the class is constructed, before the markup can be queried, so the count is
* written here and has to match the number of `ul` in the markup; the component form takes it from its data.
*/
private readonly sortables = Array.from({ length: 3 }, (_, column) =>
createSortableController(this, {
group: this.group,
preview: true,
createPlaceholder: () => document.createElement('li'),
getContainer: () => this.lists[column] ?? null,
getItems: () => [...this.lists[column].children] as HTMLElement[],
announce: (message) => (this.status.textContent = message),
onChange: ({ item, to, toContainer }) => {
const others = [...toContainer.children].filter((child) => child !== item);
toContainer.insertBefore(item, others[to] ?? null);
item.focus();
},
}),
);
}export type Card = { id: string; title: string };
export type Column = { id: string; title: string; cards: Card[] };
export const initialColumns: Column[] = [
{
id: 'todo',
title: 'To do',
cards: [
{ id: 'brief', title: 'Write the brief' },
{ id: 'layout', title: 'Sketch the layout' },
{ id: 'colors', title: 'Pick the colors' },
{ id: 'copy', title: 'Draft the copy' },
{ id: 'a11y', title: 'Review accessibility' },
{ id: 'launch', title: 'Plan the launch' },
],
},
{
id: 'doing',
title: 'Doing',
cards: [
{ id: 'header', title: 'Build the header' },
{ id: 'form', title: 'Wire the form' },
],
},
{ id: 'done', title: 'Done', cards: [{ id: 'repo', title: 'Set up the repo' }] },
];
export function moveCard(columns: Column[], cardId: string, toColumn: string, to: number): Column[] {
const card = columns.flatMap((column) => column.cards).find((candidate) => candidate.id === cardId)!;
return columns.map((column) => {
const cards = column.cards.filter((candidate) => candidate.id !== cardId);
if (column.id === toColumn) cards.splice(to, 0, card);
return { ...column, cards };
});
}<board-element>
<div data-board>
<section data-column>
<h3>To do</h3>
<ul aria-label="To do">
<li data-board-card tabindex="0">Write the brief</li>
<li data-board-card tabindex="0">Sketch the layout</li>
<li data-board-card tabindex="0">Pick the colors</li>
<li data-board-card tabindex="0">Draft the copy</li>
<li data-board-card tabindex="0">Review accessibility</li>
<li data-board-card tabindex="0">Plan the launch</li>
</ul>
</section>
<section data-column>
<h3>Doing</h3>
<ul aria-label="Doing">
<li data-board-card tabindex="0">Build the header</li>
<li data-board-card tabindex="0">Wire the form</li>
</ul>
</section>
<section data-column>
<h3>Done</h3>
<ul aria-label="Done">
<li data-board-card tabindex="0">Set up the repo</li>
</ul>
</section>
</div>
<p data-status aria-live="polite">Focus a card, press Space, PageDown for the next column, Space to drop</p>
</board-element>.primitive-example:has(> board-element, > board-app, > [data-controller='board'], > [data-example='board']) {
flex-direction: column;
flex-wrap: nowrap;
align-items: stretch;
}
:is([data-example='board'], board-element, board-app, div[data-controller='board']) :where([data-board]) {
display: grid;
grid-template-columns: repeat(3, minmax(0, 1fr));
gap: var(--space-3);
}
:is([data-example='board'], board-element, board-app, div[data-controller='board']) :where([data-column]) {
display: flex;
flex-direction: column;
gap: var(--space-2);
min-width: 0;
padding: var(--space-2);
border: 1px solid var(--border);
border-radius: var(--radius-container);
background: var(--surface-container);
color: var(--on-surface-container);
}
:is([data-example='board'], board-element, board-app, div[data-controller='board']) :where(h3) {
margin: 0;
font-size: 0.875rem;
}
:is([data-example='board'], board-element, board-app, div[data-controller='board']) :where(ul) {
min-height: 3rem;
max-height: 8rem;
overflow-y: auto;
border-radius: var(--radius-control);
}
:is([data-example='board'], board-element, board-app, div[data-controller='board']) ul[data-sortable-over] {
outline: 2px solid var(--primary);
outline-offset: -2px;
}
[data-board-card] {
padding: var(--space-1) var(--space-3);
border: 1px solid var(--border);
border-radius: var(--radius-control);
background: var(--surface);
color: var(--on-surface);
font-size: 0.875rem;
cursor: grab;
touch-action: none;
user-select: none;
}
[data-board-card]:focus-visible {
outline: 2px solid var(--focus-ring);
outline-offset: 2px;
}
[data-board-card][data-sortable-state='lifted'] {
z-index: 10;
background: var(--primary);
color: var(--on-primary);
box-shadow: var(--shadow-overlay);
list-style: none;
cursor: grabbing;
}
:is([data-example='board'], board-element, board-app, div[data-controller='board']) [data-sortable-placeholder] {
border: 1px dashed var(--primary);
border-radius: var(--radius-control);
background: transparent;
}
:is([data-example='board'], board-element, board-app, div[data-controller='board']) [data-sortable-drop] {
box-shadow: none;
}Each column gets its own createSortableController(this, ...), all sharing a SortableGroup kept in a field. The controllers are created in the element, one for each of the three columns, and look their column up by index when they attach, so @queryAll('ul') is read lazily and the markup stays plain. They attach when the element connects and are destroyed when it disconnects.
What the Radiant form removes: the mount function and its registration, the cleanup that destroys each controller, and the re-run after a client-side navigation.
The same behavior as a RadiantElement. The markup is authored inside the element and the element finds its parts with @query; there is nothing to mount, clean up or run again.
To do
- Write the brief
- Sketch the layout
- Pick the colors
- Draft the copy
- Review accessibility
- Plan the launch
Doing
- Build the header
- Wire the form
Done
- Set up the repo
Focus a card, press Space, PageDown for the next column, Space to drop
import { RadiantElement, customElement, query, queryAll } from '@ecopages/radiant';
import { SortableGroup, createSortableController } from '@ecopages/radiant-ui/controllers';
@customElement('board-element')
export class BoardElement extends RadiantElement {
@queryAll('ul') private lists!: HTMLElement[];
@query('[data-status]') private status!: HTMLElement;
private readonly group = new SortableGroup();
/**
* One sortable per column.
*
* @remarks
* A controller binds to the host when the class is constructed, before the markup can be queried, so the count is
* written here and has to match the number of `ul` in the markup; the component form takes it from its data.
*/
private readonly sortables = Array.from({ length: 3 }, (_, column) =>
createSortableController(this, {
group: this.group,
preview: true,
createPlaceholder: () => document.createElement('li'),
getContainer: () => this.lists[column] ?? null,
getItems: () => [...this.lists[column].children] as HTMLElement[],
announce: (message) => (this.status.textContent = message),
onChange: ({ item, to, toContainer }) => {
const others = [...toContainer.children].filter((child) => child !== item);
toContainer.insertBefore(item, others[to] ?? null);
item.focus();
},
}),
);
}export type Card = { id: string; title: string };
export type Column = { id: string; title: string; cards: Card[] };
export const initialColumns: Column[] = [
{
id: 'todo',
title: 'To do',
cards: [
{ id: 'brief', title: 'Write the brief' },
{ id: 'layout', title: 'Sketch the layout' },
{ id: 'colors', title: 'Pick the colors' },
{ id: 'copy', title: 'Draft the copy' },
{ id: 'a11y', title: 'Review accessibility' },
{ id: 'launch', title: 'Plan the launch' },
],
},
{
id: 'doing',
title: 'Doing',
cards: [
{ id: 'header', title: 'Build the header' },
{ id: 'form', title: 'Wire the form' },
],
},
{ id: 'done', title: 'Done', cards: [{ id: 'repo', title: 'Set up the repo' }] },
];
export function moveCard(columns: Column[], cardId: string, toColumn: string, to: number): Column[] {
const card = columns.flatMap((column) => column.cards).find((candidate) => candidate.id === cardId)!;
return columns.map((column) => {
const cards = column.cards.filter((candidate) => candidate.id !== cardId);
if (column.id === toColumn) cards.splice(to, 0, card);
return { ...column, cards };
});
}<board-element>
<div data-board>
<section data-column>
<h3>To do</h3>
<ul aria-label="To do">
<li data-board-card tabindex="0">Write the brief</li>
<li data-board-card tabindex="0">Sketch the layout</li>
<li data-board-card tabindex="0">Pick the colors</li>
<li data-board-card tabindex="0">Draft the copy</li>
<li data-board-card tabindex="0">Review accessibility</li>
<li data-board-card tabindex="0">Plan the launch</li>
</ul>
</section>
<section data-column>
<h3>Doing</h3>
<ul aria-label="Doing">
<li data-board-card tabindex="0">Build the header</li>
<li data-board-card tabindex="0">Wire the form</li>
</ul>
</section>
<section data-column>
<h3>Done</h3>
<ul aria-label="Done">
<li data-board-card tabindex="0">Set up the repo</li>
</ul>
</section>
</div>
<p data-status aria-live="polite">Focus a card, press Space, PageDown for the next column, Space to drop</p>
</board-element>.primitive-example:has(> board-element, > board-app, > [data-controller='board'], > [data-example='board']) {
flex-direction: column;
flex-wrap: nowrap;
align-items: stretch;
}
:is([data-example='board'], board-element, board-app, div[data-controller='board']) :where([data-board]) {
display: grid;
grid-template-columns: repeat(3, minmax(0, 1fr));
gap: var(--space-3);
}
:is([data-example='board'], board-element, board-app, div[data-controller='board']) :where([data-column]) {
display: flex;
flex-direction: column;
gap: var(--space-2);
min-width: 0;
padding: var(--space-2);
border: 1px solid var(--border);
border-radius: var(--radius-container);
background: var(--surface-container);
color: var(--on-surface-container);
}
:is([data-example='board'], board-element, board-app, div[data-controller='board']) :where(h3) {
margin: 0;
font-size: 0.875rem;
}
:is([data-example='board'], board-element, board-app, div[data-controller='board']) :where(ul) {
min-height: 3rem;
max-height: 8rem;
overflow-y: auto;
border-radius: var(--radius-control);
}
:is([data-example='board'], board-element, board-app, div[data-controller='board']) ul[data-sortable-over] {
outline: 2px solid var(--primary);
outline-offset: -2px;
}
[data-board-card] {
padding: var(--space-1) var(--space-3);
border: 1px solid var(--border);
border-radius: var(--radius-control);
background: var(--surface);
color: var(--on-surface);
font-size: 0.875rem;
cursor: grab;
touch-action: none;
user-select: none;
}
[data-board-card]:focus-visible {
outline: 2px solid var(--focus-ring);
outline-offset: 2px;
}
[data-board-card][data-sortable-state='lifted'] {
z-index: 10;
background: var(--primary);
color: var(--on-primary);
box-shadow: var(--shadow-overlay);
list-style: none;
cursor: grabbing;
}
:is([data-example='board'], board-element, board-app, div[data-controller='board']) [data-sortable-placeholder] {
border: 1px dashed var(--primary);
border-radius: var(--radius-control);
background: transparent;
}
:is([data-example='board'], board-element, board-app, div[data-controller='board']) [data-sortable-drop] {
box-shadow: none;
}Each column gets its own createSortableController(this, ...), all sharing a SortableGroup kept in a field. The controllers are created in the element, one for each of the three columns, and look their column up by index when they attach, so @queryAll('ul') is read lazily and the markup stays plain. They attach when the element connects and are destroyed when it disconnects.
What the Radiant form removes: the mount function and its registration, the cleanup that destroys each controller, and the re-run after a client-side navigation.
The same board as one self-contained tag. The element owns its markup: it keeps the columns and their cards as state and draws them with render(), so there is no markup to author or copy and the page holds only the tag.
import { RadiantElement, customElement, state } from '@ecopages/radiant';
import { SortableGroup, createSortableController } from '@ecopages/radiant-ui/controllers';
import { initialColumns, moveCard } from './board.data';
@customElement('board-app')
export class BoardApp extends RadiantElement<{ status: string }> {
@state columns = initialColumns;
@state status = 'Focus a card, press Space, PageDown for the next column, Space to drop';
private focusCard: string | null = null;
private readonly group = new SortableGroup();
private readonly sortables = initialColumns.map((_, column) =>
createSortableController(this, {
group: this.group,
preview: true,
createPlaceholder: () => document.createElement('li'),
getContainer: () => this.querySelectorAll('ul')[column] ?? null,
getItems: () => [...(this.querySelectorAll('ul')[column]?.children ?? [])] as HTMLElement[],
announce: (message) => (this.status = message),
onChange: ({ item, to, toContainer }) => {
this.focusCard = item.dataset.boardCard!;
this.columns = moveCard(this.columns, item.dataset.boardCard!, toContainer.dataset.columnId!, to);
},
}),
);
/**
* Attaches the sortables to the lists the render produced, and focuses the card that was just moved.
*
* @remarks
* The controllers attach when the element connects, before the first render, when no list exists yet; a second
* `attach()` resolves each list again. The keyed sections keep their lists across renders, so later calls change
* nothing, but one that replaced a list would need them. A card that changed column is a new node, so it is found
* by its id.
*/
protected override updated(): void {
for (const sortable of this.sortables) sortable.attach();
if (this.focusCard) {
this.querySelector<HTMLElement>(`[data-board-card="${this.focusCard}"]`)?.focus();
this.focusCard = null;
}
}
override render() {
return (
<>
<div data-board>
{this.columns.map((column) => (
<section key={column.id} data-column>
<h3>{column.title}</h3>
<ul aria-label={column.title} data-column-id={column.id}>
{column.cards.map((card) => (
<li key={card.id} data-board-card={card.id} tabindex="0">
{card.title}
</li>
))}
</ul>
</section>
))}
</div>
<p data-status aria-live="polite">
{this.$.status}
</p>
</>
);
}
}export type Card = { id: string; title: string };
export type Column = { id: string; title: string; cards: Card[] };
export const initialColumns: Column[] = [
{
id: 'todo',
title: 'To do',
cards: [
{ id: 'brief', title: 'Write the brief' },
{ id: 'layout', title: 'Sketch the layout' },
{ id: 'colors', title: 'Pick the colors' },
{ id: 'copy', title: 'Draft the copy' },
{ id: 'a11y', title: 'Review accessibility' },
{ id: 'launch', title: 'Plan the launch' },
],
},
{
id: 'doing',
title: 'Doing',
cards: [
{ id: 'header', title: 'Build the header' },
{ id: 'form', title: 'Wire the form' },
],
},
{ id: 'done', title: 'Done', cards: [{ id: 'repo', title: 'Set up the repo' }] },
];
export function moveCard(columns: Column[], cardId: string, toColumn: string, to: number): Column[] {
const card = columns.flatMap((column) => column.cards).find((candidate) => candidate.id === cardId)!;
return columns.map((column) => {
const cards = column.cards.filter((candidate) => candidate.id !== cardId);
if (column.id === toColumn) cards.splice(to, 0, card);
return { ...column, cards };
});
}.primitive-example:has(> board-element, > board-app, > [data-controller='board'], > [data-example='board']) {
flex-direction: column;
flex-wrap: nowrap;
align-items: stretch;
}
:is([data-example='board'], board-element, board-app, div[data-controller='board']) :where([data-board]) {
display: grid;
grid-template-columns: repeat(3, minmax(0, 1fr));
gap: var(--space-3);
}
:is([data-example='board'], board-element, board-app, div[data-controller='board']) :where([data-column]) {
display: flex;
flex-direction: column;
gap: var(--space-2);
min-width: 0;
padding: var(--space-2);
border: 1px solid var(--border);
border-radius: var(--radius-container);
background: var(--surface-container);
color: var(--on-surface-container);
}
:is([data-example='board'], board-element, board-app, div[data-controller='board']) :where(h3) {
margin: 0;
font-size: 0.875rem;
}
:is([data-example='board'], board-element, board-app, div[data-controller='board']) :where(ul) {
min-height: 3rem;
max-height: 8rem;
overflow-y: auto;
border-radius: var(--radius-control);
}
:is([data-example='board'], board-element, board-app, div[data-controller='board']) ul[data-sortable-over] {
outline: 2px solid var(--primary);
outline-offset: -2px;
}
[data-board-card] {
padding: var(--space-1) var(--space-3);
border: 1px solid var(--border);
border-radius: var(--radius-control);
background: var(--surface);
color: var(--on-surface);
font-size: 0.875rem;
cursor: grab;
touch-action: none;
user-select: none;
}
[data-board-card]:focus-visible {
outline: 2px solid var(--focus-ring);
outline-offset: 2px;
}
[data-board-card][data-sortable-state='lifted'] {
z-index: 10;
background: var(--primary);
color: var(--on-primary);
box-shadow: var(--shadow-overlay);
list-style: none;
cursor: grabbing;
}
:is([data-example='board'], board-element, board-app, div[data-controller='board']) [data-sortable-placeholder] {
border: 1px dashed var(--primary);
border-radius: var(--radius-control);
background: transparent;
}
:is([data-example='board'], board-element, board-app, div[data-controller='board']) [data-sortable-drop] {
box-shadow: none;
}The columns are @state, so a move is a new array: onChange does not touch the DOM, it writes the moved card into columns with moveCard, and render() draws the result. A render can replace a list, so updated(), which runs after each commit, attaches the sortables again, and focuses the card that moved by its id, because a card that changed column is a new node. The status line is bound with this.$.status, so announcing during a sort patches one text node and never re-renders the columns while a card is lifted.
Compared with the Radiant element above, the markup lives inside the element, so there is nothing to keep in step with the page and the data is state you can change, but restyling the structure means editing the class. It also needs the render path on the server to have content before the script runs: this docs build prerenders the tag empty and the client draws it, so the page shows nothing until the script loads, which a page of authored children does not.
The same behavior as a RadiantController. The markup is authored with data-controller="board" and no custom element tag, and the controller attaches to it.
To do
- Write the brief
- Sketch the layout
- Pick the colors
- Draft the copy
- Review accessibility
- Plan the launch
Doing
- Build the header
- Wire the form
Done
- Set up the repo
Focus a card, press Space, PageDown for the next column, Space to drop
import { RadiantController, controller, query, queryAll } from '@ecopages/radiant';
import { SortableGroup, createSortableController } from '@ecopages/radiant-ui/controllers';
@controller('board')
export class BoardController extends RadiantController {
@queryAll('ul') private lists!: HTMLElement[];
@query('[data-status]') private status!: HTMLElement;
private readonly group = new SortableGroup();
/**
* @remarks
* `RadiantController` has the two registration methods `createSortableController` asks of a host, so the sortables
* attach when the controller connects and are destroyed when the registry disconnects it, as on an element. They are
* bound when the class is constructed, before the lists can be queried, so there is one per column written here, and the
* count has to match the number of `ul` in the markup.
*/
private readonly sortables = Array.from({ length: 3 }, (_, column) =>
createSortableController(this, {
group: this.group,
preview: true,
createPlaceholder: () => document.createElement('li'),
getContainer: () => this.lists[column] ?? null,
getItems: () => [...this.lists[column].children] as HTMLElement[],
announce: (message) => (this.status.textContent = message),
onChange: ({ item, to, toContainer }) => {
const others = [...toContainer.children].filter((child) => child !== item);
toContainer.insertBefore(item, others[to] ?? null);
item.focus();
},
}),
);
}export type Card = { id: string; title: string };
export type Column = { id: string; title: string; cards: Card[] };
export const initialColumns: Column[] = [
{
id: 'todo',
title: 'To do',
cards: [
{ id: 'brief', title: 'Write the brief' },
{ id: 'layout', title: 'Sketch the layout' },
{ id: 'colors', title: 'Pick the colors' },
{ id: 'copy', title: 'Draft the copy' },
{ id: 'a11y', title: 'Review accessibility' },
{ id: 'launch', title: 'Plan the launch' },
],
},
{
id: 'doing',
title: 'Doing',
cards: [
{ id: 'header', title: 'Build the header' },
{ id: 'form', title: 'Wire the form' },
],
},
{ id: 'done', title: 'Done', cards: [{ id: 'repo', title: 'Set up the repo' }] },
];
export function moveCard(columns: Column[], cardId: string, toColumn: string, to: number): Column[] {
const card = columns.flatMap((column) => column.cards).find((candidate) => candidate.id === cardId)!;
return columns.map((column) => {
const cards = column.cards.filter((candidate) => candidate.id !== cardId);
if (column.id === toColumn) cards.splice(to, 0, card);
return { ...column, cards };
});
}<div data-controller="board">
<div data-board>
<section data-column>
<h3>To do</h3>
<ul aria-label="To do">
<li data-board-card tabindex="0">Write the brief</li>
<li data-board-card tabindex="0">Sketch the layout</li>
<li data-board-card tabindex="0">Pick the colors</li>
<li data-board-card tabindex="0">Draft the copy</li>
<li data-board-card tabindex="0">Review accessibility</li>
<li data-board-card tabindex="0">Plan the launch</li>
</ul>
</section>
<section data-column>
<h3>Doing</h3>
<ul aria-label="Doing">
<li data-board-card tabindex="0">Build the header</li>
<li data-board-card tabindex="0">Wire the form</li>
</ul>
</section>
<section data-column>
<h3>Done</h3>
<ul aria-label="Done">
<li data-board-card tabindex="0">Set up the repo</li>
</ul>
</section>
</div>
<p data-status aria-live="polite">Focus a card, press Space, PageDown for the next column, Space to drop</p>
</div>.primitive-example:has(> board-element, > board-app, > [data-controller='board'], > [data-example='board']) {
flex-direction: column;
flex-wrap: nowrap;
align-items: stretch;
}
:is([data-example='board'], board-element, board-app, div[data-controller='board']) :where([data-board]) {
display: grid;
grid-template-columns: repeat(3, minmax(0, 1fr));
gap: var(--space-3);
}
:is([data-example='board'], board-element, board-app, div[data-controller='board']) :where([data-column]) {
display: flex;
flex-direction: column;
gap: var(--space-2);
min-width: 0;
padding: var(--space-2);
border: 1px solid var(--border);
border-radius: var(--radius-container);
background: var(--surface-container);
color: var(--on-surface-container);
}
:is([data-example='board'], board-element, board-app, div[data-controller='board']) :where(h3) {
margin: 0;
font-size: 0.875rem;
}
:is([data-example='board'], board-element, board-app, div[data-controller='board']) :where(ul) {
min-height: 3rem;
max-height: 8rem;
overflow-y: auto;
border-radius: var(--radius-control);
}
:is([data-example='board'], board-element, board-app, div[data-controller='board']) ul[data-sortable-over] {
outline: 2px solid var(--primary);
outline-offset: -2px;
}
[data-board-card] {
padding: var(--space-1) var(--space-3);
border: 1px solid var(--border);
border-radius: var(--radius-control);
background: var(--surface);
color: var(--on-surface);
font-size: 0.875rem;
cursor: grab;
touch-action: none;
user-select: none;
}
[data-board-card]:focus-visible {
outline: 2px solid var(--focus-ring);
outline-offset: 2px;
}
[data-board-card][data-sortable-state='lifted'] {
z-index: 10;
background: var(--primary);
color: var(--on-primary);
box-shadow: var(--shadow-overlay);
list-style: none;
cursor: grabbing;
}
:is([data-example='board'], board-element, board-app, div[data-controller='board']) [data-sortable-placeholder] {
border: 1px dashed var(--primary);
border-radius: var(--radius-control);
background: transparent;
}
:is([data-example='board'], board-element, board-app, div[data-controller='board']) [data-sortable-drop] {
box-shadow: none;
}The class is the element form's logic, extending RadiantController and registered with @controller('board'), with the same @query fields and one createSortableController(this, ...) for each column: a RadiantController has the two registration methods the factory asks of a host, so no primitive is built by hand. There is no custom element tag to define, so the markup can come from a server or a CMS and carry only the attribute.
One registry that the docs site starts attaches the class to each data-controller="board" element, including ones inserted later, and disconnects it when the element is removed, which destroys the sortables.
A mount function wires the controllers to the markup and returns the cleanup that undoes it.
To do
- Write the brief
- Sketch the layout
- Pick the colors
- Draft the copy
- Review accessibility
- Plan the launch
Doing
- Build the header
- Wire the form
Done
- Set up the repo
Focus a card, press Space, PageDown for the next column, Space to drop
import { SortableController, SortableGroup } from '@ecopages/radiant-ui/controllers';
export function mount(root: HTMLElement): () => void {
const status = root.querySelector('[data-status]')!;
const group = new SortableGroup();
const sortables = [...root.querySelectorAll('ul')].map(
(list) =>
new SortableController({
group,
preview: true,
createPlaceholder: () => document.createElement('li'),
getContainer: () => list,
getItems: () => [...list.children] as HTMLElement[],
announce: (message) => (status.textContent = message),
onChange: ({ item, to, toContainer }) => {
const others = [...toContainer.children].filter((child) => child !== item);
toContainer.insertBefore(item, others[to] ?? null);
item.focus();
},
}),
);
sortables.forEach((sortable) => sortable.attach());
return () => sortables.forEach((sortable) => sortable.destroy());
}export type Card = { id: string; title: string };
export type Column = { id: string; title: string; cards: Card[] };
export const initialColumns: Column[] = [
{
id: 'todo',
title: 'To do',
cards: [
{ id: 'brief', title: 'Write the brief' },
{ id: 'layout', title: 'Sketch the layout' },
{ id: 'colors', title: 'Pick the colors' },
{ id: 'copy', title: 'Draft the copy' },
{ id: 'a11y', title: 'Review accessibility' },
{ id: 'launch', title: 'Plan the launch' },
],
},
{
id: 'doing',
title: 'Doing',
cards: [
{ id: 'header', title: 'Build the header' },
{ id: 'form', title: 'Wire the form' },
],
},
{ id: 'done', title: 'Done', cards: [{ id: 'repo', title: 'Set up the repo' }] },
];
export function moveCard(columns: Column[], cardId: string, toColumn: string, to: number): Column[] {
const card = columns.flatMap((column) => column.cards).find((candidate) => candidate.id === cardId)!;
return columns.map((column) => {
const cards = column.cards.filter((candidate) => candidate.id !== cardId);
if (column.id === toColumn) cards.splice(to, 0, card);
return { ...column, cards };
});
}<div data-example="board">
<div data-board>
<section data-column>
<h3>To do</h3>
<ul aria-label="To do">
<li data-board-card tabindex="0">Write the brief</li>
<li data-board-card tabindex="0">Sketch the layout</li>
<li data-board-card tabindex="0">Pick the colors</li>
<li data-board-card tabindex="0">Draft the copy</li>
<li data-board-card tabindex="0">Review accessibility</li>
<li data-board-card tabindex="0">Plan the launch</li>
</ul>
</section>
<section data-column>
<h3>Doing</h3>
<ul aria-label="Doing">
<li data-board-card tabindex="0">Build the header</li>
<li data-board-card tabindex="0">Wire the form</li>
</ul>
</section>
<section data-column>
<h3>Done</h3>
<ul aria-label="Done">
<li data-board-card tabindex="0">Set up the repo</li>
</ul>
</section>
</div>
<p data-status aria-live="polite">Focus a card, press Space, PageDown for the next column, Space to drop</p>
</div>.primitive-example:has(> board-element, > board-app, > [data-controller='board'], > [data-example='board']) {
flex-direction: column;
flex-wrap: nowrap;
align-items: stretch;
}
:is([data-example='board'], board-element, board-app, div[data-controller='board']) :where([data-board]) {
display: grid;
grid-template-columns: repeat(3, minmax(0, 1fr));
gap: var(--space-3);
}
:is([data-example='board'], board-element, board-app, div[data-controller='board']) :where([data-column]) {
display: flex;
flex-direction: column;
gap: var(--space-2);
min-width: 0;
padding: var(--space-2);
border: 1px solid var(--border);
border-radius: var(--radius-container);
background: var(--surface-container);
color: var(--on-surface-container);
}
:is([data-example='board'], board-element, board-app, div[data-controller='board']) :where(h3) {
margin: 0;
font-size: 0.875rem;
}
:is([data-example='board'], board-element, board-app, div[data-controller='board']) :where(ul) {
min-height: 3rem;
max-height: 8rem;
overflow-y: auto;
border-radius: var(--radius-control);
}
:is([data-example='board'], board-element, board-app, div[data-controller='board']) ul[data-sortable-over] {
outline: 2px solid var(--primary);
outline-offset: -2px;
}
[data-board-card] {
padding: var(--space-1) var(--space-3);
border: 1px solid var(--border);
border-radius: var(--radius-control);
background: var(--surface);
color: var(--on-surface);
font-size: 0.875rem;
cursor: grab;
touch-action: none;
user-select: none;
}
[data-board-card]:focus-visible {
outline: 2px solid var(--focus-ring);
outline-offset: 2px;
}
[data-board-card][data-sortable-state='lifted'] {
z-index: 10;
background: var(--primary);
color: var(--on-primary);
box-shadow: var(--shadow-overlay);
list-style: none;
cursor: grabbing;
}
:is([data-example='board'], board-element, board-app, div[data-controller='board']) [data-sortable-placeholder] {
border: 1px dashed var(--primary);
border-radius: var(--radius-control);
background: transparent;
}
:is([data-example='board'], board-element, board-app, div[data-controller='board']) [data-sortable-drop] {
box-shadow: none;
}mount runs once for each example element on the page, and the function it returns undoes it; see how the examples run.
Styles
The same attributes style the lifted card, the placeholder and the column a card is over; touch-action: none on the cards lets a touch drag move them instead of scrolling. The stylesheet is the board.css tab in the files above.