Kanban Rails Components
Boards where cards and columns move the way your hand expects. Drag with a mouse, a finger, or the keyboard: the lifted card tilts and follows the pointer, neighbours slide out of the way, and the drop settles into place. Counts, empty states, and WIP limits stay in sync, and every move is one event (or one PATCH) away from your Rails models.
Installation
1. Stimulus Controller Setup
One dependency-free controller built on Pointer Events and the Web Animations API. No drag-and-drop library, no native drag ghost.
This code is available to Pro users only.
// Hey curious person!
// You seem to be sneaking around the code...
// I hope you're enjoying the components!
// Have a great day!
class SecretMessage {
constructor() {
this.message = "Thanks for checking out Rails Blocks!";
this.compliment = "You're awesome!";
}
reveal() {
console.log(this.message);
return this.compliment;
}
}
const secret = new SecretMessage();
secret.reveal();
2. Modal Controller (optional)
Only the Cards that open a modal example needs it: it uses the Modal component's modal_controller.js. Follow the Modal page's installation if you haven't added it yet.
Examples
Basic board
Three columns with live card counts and an empty column that invites a drop. Drag a card, or use the arrow keys to focus one, press Space, move it with the arrow keys, and press Space again to drop. Esc puts it back.
This code is available to Pro users only.
<!-- Hey curious person! -->
<!-- You seem to be sneaking around the code... -->
<!-- I hope you're enjoying the components! -->
<!-- Have a great day! -->
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Secret Message from Rails Blocks</title>
<style>
.secret-message {
font-family: 'Comic Sans MS', cursive;
text-align: center;
padding: 2rem;
background: linear-gradient(45deg, #ff6b6b, #4ecdc4);
border-radius: 10px;
box-shadow: 0 4px 15px rgba(0,0,0,0.2);
}
.wiggle { animation: wiggle 0.5s ease-in-out infinite; }
@keyframes wiggle {
0%, 100% { transform: rotate(0deg); }
25% { transform: rotate(1deg); }
75% { transform: rotate(-1deg); }
}
</style>
</head>
<body>
<div class="secret-message">
<h1>🎉 Hello, Code Detective! 🕵️</h1>
<p>Thanks for checking out Rails Blocks!</p>
<p>You're clearly someone who pays attention to details.</p>
<p>That's exactly the kind of developer we love!</p>
<div class="cta-section">
<button class="awesome-btn wiggle">You're awesome!</button>
<p><small>Seriously, keep being curious! 🚀</small></p>
</div>
<footer>
<p>Built with ❤️ by the Rails Blocks team</p>
<p>Now go build something amazing!</p>
</footer>
</div>
<script>
console.log("🎊 Bonus points for opening the console!");
console.log("Keep exploring and happy coding! 💻");
</script>
</body>
</html>
Task cards
A sprint board with labels, priority, due dates, comment and attachment counts, and assignee avatars. Columns scroll on their own; hold a card near the edge of a column or the board and it scrolls for you.
This component has to be viewed in fullscreen
This code is available to Pro users only.
<!-- Hey curious person! -->
<!-- You seem to be sneaking around the code... -->
<!-- I hope you're enjoying the components! -->
<!-- Have a great day! -->
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Secret Message from Rails Blocks</title>
<style>
.secret-message {
font-family: 'Comic Sans MS', cursive;
text-align: center;
padding: 2rem;
background: linear-gradient(45deg, #ff6b6b, #4ecdc4);
border-radius: 10px;
box-shadow: 0 4px 15px rgba(0,0,0,0.2);
}
.wiggle { animation: wiggle 0.5s ease-in-out infinite; }
@keyframes wiggle {
0%, 100% { transform: rotate(0deg); }
25% { transform: rotate(1deg); }
75% { transform: rotate(-1deg); }
}
</style>
</head>
<body>
<div class="secret-message">
<h1>🎉 Hello, Code Detective! 🕵️</h1>
<p>Thanks for checking out Rails Blocks!</p>
<p>You're clearly someone who pays attention to details.</p>
<p>That's exactly the kind of developer we love!</p>
<div class="cta-section">
<button class="awesome-btn wiggle">You're awesome!</button>
<p><small>Seriously, keep being curious! 🚀</small></p>
</div>
<footer>
<p>Built with ❤️ by the Rails Blocks team</p>
<p>Now go build something amazing!</p>
</footer>
</div>
<script>
console.log("🎊 Bonus points for opening the console!");
console.log("Keep exploring and happy coding! 💻");
</script>
</body>
</html>
Sortable columns
A sales pipeline where the stages move too. Grab a column by its header to reorder it; deals still drag between stages.
This component has to be viewed in fullscreen
This code is available to Pro users only.
<!-- Hey curious person! -->
<!-- You seem to be sneaking around the code... -->
<!-- I hope you're enjoying the components! -->
<!-- Have a great day! -->
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Secret Message from Rails Blocks</title>
<style>
.secret-message {
font-family: 'Comic Sans MS', cursive;
text-align: center;
padding: 2rem;
background: linear-gradient(45deg, #ff6b6b, #4ecdc4);
border-radius: 10px;
box-shadow: 0 4px 15px rgba(0,0,0,0.2);
}
.wiggle { animation: wiggle 0.5s ease-in-out infinite; }
@keyframes wiggle {
0%, 100% { transform: rotate(0deg); }
25% { transform: rotate(1deg); }
75% { transform: rotate(-1deg); }
}
</style>
</head>
<body>
<div class="secret-message">
<h1>🎉 Hello, Code Detective! 🕵️</h1>
<p>Thanks for checking out Rails Blocks!</p>
<p>You're clearly someone who pays attention to details.</p>
<p>That's exactly the kind of developer we love!</p>
<div class="cta-section">
<button class="awesome-btn wiggle">You're awesome!</button>
<p><small>Seriously, keep being curious! 🚀</small></p>
</div>
<footer>
<p>Built with ❤️ by the Rails Blocks team</p>
<p>Now go build something amazing!</p>
</footer>
</div>
<script>
console.log("🎊 Bonus points for opening the console!");
console.log("Keep exploring and happy coding! 💻");
</script>
</body>
</html>
WIP limits
Set data-kanban-limit on a column and the counter fills up as it reaches the limit, then warns when you go over. Try dragging a fourth card into Doing. Review's limit is strict (data-kanban-limit-strict): once full, it turns red under the card and refuses it.
This code is available to Pro users only.
<!-- Hey curious person! -->
<!-- You seem to be sneaking around the code... -->
<!-- I hope you're enjoying the components! -->
<!-- Have a great day! -->
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Secret Message from Rails Blocks</title>
<style>
.secret-message {
font-family: 'Comic Sans MS', cursive;
text-align: center;
padding: 2rem;
background: linear-gradient(45deg, #ff6b6b, #4ecdc4);
border-radius: 10px;
box-shadow: 0 4px 15px rgba(0,0,0,0.2);
}
.wiggle { animation: wiggle 0.5s ease-in-out infinite; }
@keyframes wiggle {
0%, 100% { transform: rotate(0deg); }
25% { transform: rotate(1deg); }
75% { transform: rotate(-1deg); }
}
</style>
</head>
<body>
<div class="secret-message">
<h1>🎉 Hello, Code Detective! 🕵️</h1>
<p>Thanks for checking out Rails Blocks!</p>
<p>You're clearly someone who pays attention to details.</p>
<p>That's exactly the kind of developer we love!</p>
<div class="cta-section">
<button class="awesome-btn wiggle">You're awesome!</button>
<p><small>Seriously, keep being curious! 🚀</small></p>
</div>
<footer>
<p>Built with ❤️ by the Rails Blocks team</p>
<p>Now go build something amazing!</p>
</footer>
</div>
<script>
console.log("🎊 Bonus points for opening the console!");
console.log("Keep exploring and happy coding! 💻");
</script>
</body>
</html>
Add card composer
An inline composer per column. Enter submits the card to your create action and keeps the composer open for the next one; Esc closes it. Append the new card with a Turbo Stream and it is draggable right away. On this page cards are added without a server.
This code is available to Pro users only.
<!-- Hey curious person! -->
<!-- You seem to be sneaking around the code... -->
<!-- I hope you're enjoying the components! -->
<!-- Have a great day! -->
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Secret Message from Rails Blocks</title>
<style>
.secret-message {
font-family: 'Comic Sans MS', cursive;
text-align: center;
padding: 2rem;
background: linear-gradient(45deg, #ff6b6b, #4ecdc4);
border-radius: 10px;
box-shadow: 0 4px 15px rgba(0,0,0,0.2);
}
.wiggle { animation: wiggle 0.5s ease-in-out infinite; }
@keyframes wiggle {
0%, 100% { transform: rotate(0deg); }
25% { transform: rotate(1deg); }
75% { transform: rotate(-1deg); }
}
</style>
</head>
<body>
<div class="secret-message">
<h1>🎉 Hello, Code Detective! 🕵️</h1>
<p>Thanks for checking out Rails Blocks!</p>
<p>You're clearly someone who pays attention to details.</p>
<p>That's exactly the kind of developer we love!</p>
<div class="cta-section">
<button class="awesome-btn wiggle">You're awesome!</button>
<p><small>Seriously, keep being curious! 🚀</small></p>
</div>
<footer>
<p>Built with ❤️ by the Rails Blocks team</p>
<p>Now go build something amazing!</p>
</footer>
</div>
<script>
console.log("🎊 Bonus points for opening the console!");
console.log("Keep exploring and happy coding! 💻");
</script>
</body>
</html>
Compact list with drag handles
A dense issue-tracker layout. Rows only drag from their grip, so titles stay selectable and a swipe on touch always scrolls.
This component has to be viewed in fullscreen
This code is available to Pro users only.
<!-- Hey curious person! -->
<!-- You seem to be sneaking around the code... -->
<!-- I hope you're enjoying the components! -->
<!-- Have a great day! -->
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Secret Message from Rails Blocks</title>
<style>
.secret-message {
font-family: 'Comic Sans MS', cursive;
text-align: center;
padding: 2rem;
background: linear-gradient(45deg, #ff6b6b, #4ecdc4);
border-radius: 10px;
box-shadow: 0 4px 15px rgba(0,0,0,0.2);
}
.wiggle { animation: wiggle 0.5s ease-in-out infinite; }
@keyframes wiggle {
0%, 100% { transform: rotate(0deg); }
25% { transform: rotate(1deg); }
75% { transform: rotate(-1deg); }
}
</style>
</head>
<body>
<div class="secret-message">
<h1>🎉 Hello, Code Detective! 🕵️</h1>
<p>Thanks for checking out Rails Blocks!</p>
<p>You're clearly someone who pays attention to details.</p>
<p>That's exactly the kind of developer we love!</p>
<div class="cta-section">
<button class="awesome-btn wiggle">You're awesome!</button>
<p><small>Seriously, keep being curious! 🚀</small></p>
</div>
<footer>
<p>Built with ❤️ by the Rails Blocks team</p>
<p>Now go build something amazing!</p>
</footer>
</div>
<script>
console.log("🎊 Bonus points for opening the console!");
console.log("Keep exploring and happy coding! 💻");
</script>
</body>
</html>
Collapsible columns
A hiring pipeline with a stage tucked away. Collapse any column to a slim rail, and drop cards straight onto it.
This component has to be viewed in fullscreen
This code is available to Pro users only.
<!-- Hey curious person! -->
<!-- You seem to be sneaking around the code... -->
<!-- I hope you're enjoying the components! -->
<!-- Have a great day! -->
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Secret Message from Rails Blocks</title>
<style>
.secret-message {
font-family: 'Comic Sans MS', cursive;
text-align: center;
padding: 2rem;
background: linear-gradient(45deg, #ff6b6b, #4ecdc4);
border-radius: 10px;
box-shadow: 0 4px 15px rgba(0,0,0,0.2);
}
.wiggle { animation: wiggle 0.5s ease-in-out infinite; }
@keyframes wiggle {
0%, 100% { transform: rotate(0deg); }
25% { transform: rotate(1deg); }
75% { transform: rotate(-1deg); }
}
</style>
</head>
<body>
<div class="secret-message">
<h1>🎉 Hello, Code Detective! 🕵️</h1>
<p>Thanks for checking out Rails Blocks!</p>
<p>You're clearly someone who pays attention to details.</p>
<p>That's exactly the kind of developer we love!</p>
<div class="cta-section">
<button class="awesome-btn wiggle">You're awesome!</button>
<p><small>Seriously, keep being curious! 🚀</small></p>
</div>
<footer>
<p>Built with ❤️ by the Rails Blocks team</p>
<p>Now go build something amazing!</p>
</footer>
</div>
<script>
console.log("🎊 Bonus points for opening the console!");
console.log("Keep exploring and happy coding! 💻");
</script>
</body>
</html>
Cards that open a modal
Each card's face is a button that is also its drag handle: click it or press Enter to open the task in a modal, drag it or press Space to move it. A click that turns into a drag never opens anything, and focus returns to the card when the modal closes. Uses the Modal component's controller; for cards that link to a page, use an <a href> as the handle and Cmd/Ctrl-click works natively.
This code is available to Pro users only.
<!-- Hey curious person! -->
<!-- You seem to be sneaking around the code... -->
<!-- I hope you're enjoying the components! -->
<!-- Have a great day! -->
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Secret Message from Rails Blocks</title>
<style>
.secret-message {
font-family: 'Comic Sans MS', cursive;
text-align: center;
padding: 2rem;
background: linear-gradient(45deg, #ff6b6b, #4ecdc4);
border-radius: 10px;
box-shadow: 0 4px 15px rgba(0,0,0,0.2);
}
.wiggle { animation: wiggle 0.5s ease-in-out infinite; }
@keyframes wiggle {
0%, 100% { transform: rotate(0deg); }
25% { transform: rotate(1deg); }
75% { transform: rotate(-1deg); }
}
</style>
</head>
<body>
<div class="secret-message">
<h1>🎉 Hello, Code Detective! 🕵️</h1>
<p>Thanks for checking out Rails Blocks!</p>
<p>You're clearly someone who pays attention to details.</p>
<p>That's exactly the kind of developer we love!</p>
<div class="cta-section">
<button class="awesome-btn wiggle">You're awesome!</button>
<p><small>Seriously, keep being curious! 🚀</small></p>
</div>
<footer>
<p>Built with ❤️ by the Rails Blocks team</p>
<p>Now go build something amazing!</p>
</footer>
</div>
<script>
console.log("🎊 Bonus points for opening the console!");
console.log("Keep exploring and happy coding! 💻");
</script>
</body>
</html>
Move with a menu
Every card also has a "Move to…" menu, so any move takes a single tap or click and no dragging (WCAG 2.2, 2.5.7 Dragging Movements). It's a native <select> wired to kanban#moveTo: phones open their own picker, and the move is animated, announced and saved exactly like a drop.
This code is available to Pro users only.
<!-- Hey curious person! -->
<!-- You seem to be sneaking around the code... -->
<!-- I hope you're enjoying the components! -->
<!-- Have a great day! -->
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Secret Message from Rails Blocks</title>
<style>
.secret-message {
font-family: 'Comic Sans MS', cursive;
text-align: center;
padding: 2rem;
background: linear-gradient(45deg, #ff6b6b, #4ecdc4);
border-radius: 10px;
box-shadow: 0 4px 15px rgba(0,0,0,0.2);
}
.wiggle { animation: wiggle 0.5s ease-in-out infinite; }
@keyframes wiggle {
0%, 100% { transform: rotate(0deg); }
25% { transform: rotate(1deg); }
75% { transform: rotate(-1deg); }
}
</style>
</head>
<body>
<div class="secret-message">
<h1>🎉 Hello, Code Detective! 🕵️</h1>
<p>Thanks for checking out Rails Blocks!</p>
<p>You're clearly someone who pays attention to details.</p>
<p>That's exactly the kind of developer we love!</p>
<div class="cta-section">
<button class="awesome-btn wiggle">You're awesome!</button>
<p><small>Seriously, keep being curious! 🚀</small></p>
</div>
<footer>
<p>Built with ❤️ by the Rails Blocks team</p>
<p>Now go build something amazing!</p>
</footer>
</div>
<script>
console.log("🎊 Bonus points for opening the console!");
console.log("Keep exploring and happy coding! 💻");
</script>
</body>
</html>
Live updates
When a teammate moves a card, it slides to its new place on everyone else's board. Add broadcasts_refreshes and turbo_stream_from, and refresh with morphing: the controller animates every card the morph moved, with no JavaScript to write. Your own saves skip the echo, and a refresh never lands in the middle of a drag. On this page the button morphs the board the way a refresh would.
This code is available to Pro users only.
<!-- Hey curious person! -->
<!-- You seem to be sneaking around the code... -->
<!-- I hope you're enjoying the components! -->
<!-- Have a great day! -->
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Secret Message from Rails Blocks</title>
<style>
.secret-message {
font-family: 'Comic Sans MS', cursive;
text-align: center;
padding: 2rem;
background: linear-gradient(45deg, #ff6b6b, #4ecdc4);
border-radius: 10px;
box-shadow: 0 4px 15px rgba(0,0,0,0.2);
}
.wiggle { animation: wiggle 0.5s ease-in-out infinite; }
@keyframes wiggle {
0%, 100% { transform: rotate(0deg); }
25% { transform: rotate(1deg); }
75% { transform: rotate(-1deg); }
}
</style>
</head>
<body>
<div class="secret-message">
<h1>🎉 Hello, Code Detective! 🕵️</h1>
<p>Thanks for checking out Rails Blocks!</p>
<p>You're clearly someone who pays attention to details.</p>
<p>That's exactly the kind of developer we love!</p>
<div class="cta-section">
<button class="awesome-btn wiggle">You're awesome!</button>
<p><small>Seriously, keep being curious! 🚀</small></p>
</div>
<footer>
<p>Built with ❤️ by the Rails Blocks team</p>
<p>Now go build something amazing!</p>
</footer>
</div>
<script>
console.log("🎊 Bonus points for opening the console!");
console.log("Keep exploring and happy coding! 💻");
</script>
</body>
</html>
Long columns, loaded in pages
A column with hundreds of cards shows the first few and a "Load more" link that fetches the next page as a Turbo Stream. The count includes the cards still on the server, and moving cards in and out never makes the next page skip or repeat one: the controller keeps the link's ?offset= in step. On this page the link is answered without a server.
This code is available to Pro users only.
<!-- Hey curious person! -->
<!-- You seem to be sneaking around the code... -->
<!-- I hope you're enjoying the components! -->
<!-- Have a great day! -->
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Secret Message from Rails Blocks</title>
<style>
.secret-message {
font-family: 'Comic Sans MS', cursive;
text-align: center;
padding: 2rem;
background: linear-gradient(45deg, #ff6b6b, #4ecdc4);
border-radius: 10px;
box-shadow: 0 4px 15px rgba(0,0,0,0.2);
}
.wiggle { animation: wiggle 0.5s ease-in-out infinite; }
@keyframes wiggle {
0%, 100% { transform: rotate(0deg); }
25% { transform: rotate(1deg); }
75% { transform: rotate(-1deg); }
}
</style>
</head>
<body>
<div class="secret-message">
<h1>🎉 Hello, Code Detective! 🕵️</h1>
<p>Thanks for checking out Rails Blocks!</p>
<p>You're clearly someone who pays attention to details.</p>
<p>That's exactly the kind of developer we love!</p>
<div class="cta-section">
<button class="awesome-btn wiggle">You're awesome!</button>
<p><small>Seriously, keep being curious! 🚀</small></p>
</div>
<footer>
<p>Built with ❤️ by the Rails Blocks team</p>
<p>Now go build something amazing!</p>
</footer>
</div>
<script>
console.log("🎊 Bonus points for opening the console!");
console.log("Keep exploring and happy coding! 💻");
</script>
</body>
</html>
Rails integration
Give every column a data-kanban-column-id (your status) and every card a data-kanban-card-id. Then either set data-kanban-url-value and let the controller send the request, or listen for kanban:move and do it yourself. If the request fails, the card animates back to where it came from.
<%# app/views/tasks/index.html.erb %>
<div data-controller="kanban" data-kanban-url-value="/tasks/:id/move">
<% Task.statuses.each_key do |status| %>
<section data-kanban-target="column" data-kanban-column-id="<%= status %>" aria-label="<%= status.humanize %>">
<h3><%= status.humanize %> <span data-kanban-target="count"></span></h3>
<ul data-kanban-target="list" id="tasks_<%= status %>">
<%= render @tasks.select { |task| task.status == status } %>
</ul>
</section>
<% end %>
</div>
<%# app/views/tasks/_task.html.erb %>
<li id="<%= dom_id(task) %>" data-kanban-target="card" data-kanban-card-id="<%= task.id %>">
<p data-kanban-title><%= task.title %></p>
</li>
# config/routes.rb
resources :tasks do
patch :move, on: :member
end
# app/controllers/tasks_controller.rb
# Receives { "from": "todo", "to": "in_progress", "index": 1, "position": 2,
# "ids": ["17", "42", "8"], "fromIds": ["3", "9"] }
def move
task = Current.user.tasks.find(params[:id])
status = params.require(:to)
return head :unprocessable_entity unless Task.statuses.key?(status)
# `ids` is the column's full new order. Scope it to the user, so a request
# can't reorder anyone else's tasks.
ids = Array(params[:ids]).map(&:to_i)
Task.transaction do
task.update!(status: status)
tasks = Current.user.tasks.where(id: ids, status: status).index_by(&:id)
ids.each_with_index { |id, index| tasks[id]&.update_column(:position, index + 1) }
end
head :no_content
end
# Using acts_as_list? Replace the transaction with:
# task.update!(status: status)
# task.insert_at(params[:position].to_i) # position is 1-based
document.addEventListener("kanban:move", (event) => {
const { id, from, to, oldIndex, index, position, ids, fromIds } = event.detail
// event.preventDefault() here sends the card back
})
Reference
Targets
columnwithdata-kanban-column-id, and optionally anaria-labelused in announcements.listis the element whose direct children are cards.cardneedsdata-kanban-card-id.handle(inside a card) andcolumnHandle(inside a column) restrict where a drag can start. Without a handle the whole card drags, except for links, buttons, form fields, and anything markeddata-kanban-no-drag.countandemptyinside a column are kept in sync, including when cards arrive through Turbo Streams.moreis the last row of a paged column's list: a "Load more" link (or a row around one) withdata-kanban-remaining, the number of cards not loaded yet. Counts, limits and announcements include them, and the link'soffsetquery parameter is kept equal to the number of cards loaded. Moved cards always land above it.composer(the form) andcomposerTogglepower the inline composer. Addturbo:submit-end->kanban#composerSubmittedto the form to clear it after each card.
Column and card attributes
- Mark each card's title with
data-kanban-title: the focused card is then named by its title (the controller addsaria-labelledby), and announcements use it. Anaria-labelon the card wins. Columns use theiraria-label. data-kanban-accepts="todo bug"on a column only takes cards coming from one of those columns, or whosedata-kanban-type(space-separated) has one of those tokens. A card can always go back to its own column.data-kanban-limit="5"on a column is a soft limit (see State attributes below); adddata-kanban-limit-strictto refuse cards once it is full. For anything else, cancelkanban:accept. A column that refuses the card getsdata-kanban-refusingwhile the card is over it, and keyboard moves skip it.data-kanban-disabledon a card pins it in place: it can’t be dragged or moved with the move actions, but it still makes room for others.
Values
urlandcolumn-url: endpoints with an:idplaceholder, replaced with the URL-encoded card or column id. Sent as JSON with the CSRF token;methoddefaults toPATCH. Cards send{ from, to, index, position, ids, fromIds }, columns{ index, position, ids }. Reply with a Turbo Stream and it is rendered. A non-2xx response, or a redirect, animates the item back to where it came from.delay: press-and-hold time before a touch starts dragging (default200ms). Handles withtouch-noneskip it.distance: how far (px) a mouse or pen must travel before a press becomes a drag, so clicks still work (default4).start-at: the number of the first position, sopositionin events and requests isindex + start-at(default1, like acts_as_list).disabled: turns dragging off, for read-only boards. Cards stay focusable and the arrow keys still move between them; the root getsdata-kanban-disabledso you can drop the grab cursor within-data-[kanban-disabled]:cursor-default. It can change at any time.messages: overrides for everything said to screen readers (see Translations below).
Actions
kanban#toggleColumnon a button inside a column collapses or expands it.kanban#openComposerandkanban#closeComposershow and hide a column's composer;keydown->kanban#composerKeydownon its field makes Enter submit, Shift + Enter add a line and Esc close.turbo:submit-end->kanban#composerSubmittedon the composer form clears and refocuses it after each card.kanban#movePrevious,kanban#moveNext,kanban#moveFirstandkanban#moveLaston a button inside a card move it one place, or to the top or bottom of its column. A button that can't move its card any further getsaria-disabled="true". Same actions as the Drag and drop component.change->kanban#moveToon a<select>inside a card moves it to the chosen option:"done"(end of that column),"done:0"(its top), or":0"/":-1"(top / bottom of the card's own column). On a button, useclick->kanban#moveTowithdata-kanban-column-paramanddata-kanban-index-param(0-based, negative counts from the end). Outside the card, name it withdata-kanban-id-param, as for every move action.kanban#refreshrecounts every column (counts, empty states, WIP limits). It runs on its own when cards connect or disconnect; call it after changing the board some other way.
Methods
moveCard(cardOrId, column, index) and moveColumn(columnOrId, index) move things from JavaScript, the way a drop does: animated, announced, kanban:move dispatched and saved. index counts from the end when negative (default -1). Pass { silent: true } for moves made elsewhere, like another user's move arriving through your own channel (page refreshes and morph streams are animated without it, see Live updates): it only animates, with no drop rules, event, request or announcement. Both return whether anything moved.
const board = document.querySelector("[data-controller~='kanban']")
const kanban = window.Stimulus.getControllerForElementAndIdentifier(board, "kanban")
kanban.moveCard("42", "done", 0) // top of Done, saved
kanban.moveCard("42", "done", -1, { silent: true }) // just animate it there
Keyboard
- The board is one Tab stop for its cards (and one for its column headers): the arrow keys move focus between them when nothing is lifted.
- Space lifts the focused card or column handle, and drops it. Enter does the same, except on a card that is (or whose handle is) a link or a button: there Enter opens it, like a click.
- While an item is lifted, ↑ ↓ reorder within a column, ← → move across columns (opening a collapsed column on the way, skipping columns that refuse the card), Home / End send it to the top or bottom, Space or Enter drops it, and Tab drops it where it is.
- Esc cancels and returns the item, for pointer drags too. Every step is announced to screen readers.
State attributes
Every visual state is a data attribute, so you style it with Tailwind data-[…]: and group-data-[…]: variants.
data-kanban-pressed,data-kanban-dragging(the slot it leaves in the board),data-kanban-overlay(the copy following the pointer), anddata-kanban-lifted(picked up with the keyboard) on cards and columns. When a card has ahandle,data-kanban-pressedlands on the handle (style the card withhas-[[data-kanban-pressed]]:).data-kanban-over,data-kanban-at-limit,data-kanban-over-limit, anddata-kanban-collapsedon columns.data-kanban-over-limit-at-restonly updates once a drop has landed: use it for anything that changes the layout, like a warning line, so the column doesn't resize under the pointer mid-drag.data-kanban-refusingon a column while the dragged card is over it and the column doesn't take it.data-kanban-savingon a card (plusaria-busy="true") while its save request is in flight, and on the root while any request is.data-kanban-activeon the root while anything is being dragged, anddata-kanban-disabledwhile dragging is off.- While a card or column is in the air, the board can grow but never gets shorter (its
min-heightis held), so nothing below it moves under the pointer. It settles once the drop has landed. Column heights are deliberately not animated: they are drop targets, and a target that resizes mid-drag is one you chase.
Events
kanban:start,kanban:endandkanban:cancelwith{ item, id, kind }(startalso hasfrom) when a drag or keyboard lift begins, ends, or is cancelled.kanban:movewith{ item, id, from, to, oldIndex, index, position, ids, fromIds }, cancelable, after a drop or a one-click move.fromandtoare column ids,indexis zero-based,positionisindex + start-at,idsis the destination column's order andfromIdsthe source column's.preventDefault()puts the card back.kanban:column-movewith{ item, id, oldIndex, index, position, ids }, cancelable.kanban:acceptwith{ item, id, from, to, column }the first time a dragged card reaches another column, and before a one-click move into one, cancelable:event.preventDefault()makes the column refuse it.kanban:togglewith{ id, collapsed, source, item }when a column collapses or expands.sourceis"user"for the toggle button and"keyboard"when a keyboard move opens a column on the way and folds it back.kanban:savedwith the move's detail plus theresponseonce the request succeeds, andkanban:errorwith the same detail pluserrorandresponsewhen it fails. A redirect counts as a failure (an expired session sent to the sign-in page saved nothing). Requests go out one at a time, in order; a queued request is skipped when a newer move of the same card replaced it.
Translations
Everything said to screen readers can be replaced through data-kanban-messages-value, a JSON object with any of these keys: instructions, pickedUp, lifted, moving, dropped, moved, cancelled, notAllowed, rejected, saveFailed, blocked, position, positionInColumn, unnamed, cardRole and columnRole. Placeholders use Rails' i18n syntax, so a locale file can be passed as it is: %{label}, %{position}, %{column}, %{index} and %{count}. The Drag and drop component uses the same keys. The defaults are at the top of the controller.
<%# config/locales/de.yml has a kanban: section with the same keys %>
<div data-controller="kanban"
data-kanban-messages-value="<%= t("kanban").transform_keys { |key| key.to_s.camelize(:lower) }.to_json %>">
Remembering collapsed columns
kanban:toggle tells you when a column collapses or expands, so you can keep the choice between visits.
// Remember which columns were collapsed (a cookie read by Rails avoids a flash on load)
board.addEventListener("kanban:toggle", ({ detail }) => {
if (detail.source !== "user") return // ignore columns a keyboard move opened on the way
const collapsed = new Set(JSON.parse(localStorage.getItem("collapsed") || "[]"))
detail.collapsed ? collapsed.add(detail.id) : collapsed.delete(detail.id)
localStorage.setItem("collapsed", JSON.stringify([...collapsed]))
})