Splits a whole among parts on one rail: each part is a pill, handles are balls that push their neighbours, squash at the minimum and roll every percentage.
DragDrag
Marketing budget · Q4
€120,000 across four channels. Drag a handle to move budget.
Approved by finance on Oct 2
allocation-slider, lively
Use an allocation slider when a fixed whole is split among parts: a budget by channel, a revenue share, portfolio weights, A/B/n traffic, storage quotas. A form with one number field per part never adds up; here every part is a pill on one rail, the handles between them are shared edges, and the sum is always total. For a single value or a range, use the Slider. For exact typing with the rail as feedback, use the inputs preset.
The motion follows the three beats. Pressing a handle charges it: the ball stretches toward the pointer. Dragging is the action: one pill stretches, its neighbour shortens and both percentages roll. When the shrinking part reaches its min, the handle resists: it follows only part of the pointer, flattens against the squeezed pill, and that pill compresses across the rail while its label stays still. Releasing settles it: both spring back to the limit. A flick throws the handle so it slides on and squashes at the limit.
pnpm dlx shadcn@latest add @motionkit-pro/allocation-slidernpx shadcn@latest add @motionkit-pro/allocation-slideryarn dlx shadcn@latest add @motionkit-pro/allocation-sliderbunx --bun shadcn@latest add @motionkit-pro/allocation-sliderRequires a Pro license and the @motionkit-pro registry with your token. See Installation.
import { useState } from "react"
import { AllocationSlider } from "@/components/ui/allocation-slider"
const channels = [
{ id: "search", label: "Paid search" },
{ id: "social", label: "Social", min: 18 },
{ id: "content", label: "Content" },
{ id: "events", label: "Events" },
]
export function BudgetSplit() {
const [value, setValue] = useState([35, 25, 20, 20])
return (
<AllocationSlider
aria-label="Marketing budget"
segments={channels}
value={value}
onValueChange={setValue}
scale={1200}
format={{ style: "currency", currency: "EUR", maximumFractionDigits: 0 }}
/>
)
}value has one share per segment and sums to total (100 by default, with unit="%"). onValueChange(value, { id, from, to }) says which part the person moved; onValueCommit fires once per drag, key step or typed value. scale and format add an amount to each legend row (a share of 35 × 1200 = €42,000). Each segment takes min, max, color (primary or chart-1 to chart-5) and locked.
pushMode="resist" (default) stops a handle at its neighbour's minimum; pushMode="shove" pushes the next handles along like a train until a locked handle or the rail end. Double-click a handle, or press L, to lock it: a dot appears in the ball and the handle becomes a wall.
Set the character for the whole app with MotionKitProvider temperament="calm", or per component with temperament. At calm there is no rubber band: the handle stops at the limit and the squeezed pill compresses by 3%. preset picks the layout: bar (default), stacked (a vertical rail with the legend at its right) and inputs (a number input per part). size is sm, md or lg; name adds hidden inputs (name[id]) for form posts.
Prop
Type
Also accepts all props of Omit<
ComponentProps<"div">,
"defaultValue" | "onChange" | "ref" | "children"
>.
DragDrag
allocation-slider, lively
DragDrag
Traffic split
Checkout experiment · 3 variants
Draft · not live yet
allocation-slider, lively
The default demo is a Q4 budget card: four channels of €120,000 with the amount rolling next to each percentage. On first view the Paid search handle drags itself toward 48%: Social stops at its 18% minimum, the handle resists and flattens, then everything returns. Replay runs it again.
The stacked preset in a side panel, with pushMode="shove": dragging the Documents handle down pushes Media and Backups along once each reaches its minimum.
The inputs preset for an experiment: type a share into one variant and the others give way in proportion to their room, the rail moving on the calm spring.
| Part | Element | Notes |
|---|---|---|
| Root | div[role=group][data-slot=allocation-slider] | Takes aria-label / aria-labelledby and className |
| Rail | [data-slot=allocation-slider-rail] | The ref; inset track that holds the pills |
| Segment | [data-slot=allocation-segment][data-segment=id] | Tinted pill, label and rolling share |
| Handle | [data-slot=allocation-handle][data-handle=n] | role="slider", the ball between part n and n + 1 |
| Legend | [data-slot=allocation-legend] | Dot, label, rolling share and amount per part |
role="group": name it with aria-label or aria-labelledby.role="slider" named after both parts ("Paid search and Social"). aria-valuenow is the left part's share, aria-valuemin and aria-valuemax its current limits, and aria-valuetext reads both parts ("Paid search 35%, Social 25%", plus "locked").role="spinbutton" that + and − adjust. It is not a Tab stop: the handles are the keyboard path.background with foreground text, AA in both themes. Color is never the only cue: labels are always visible, in the pill or, when a pill is too narrow (under 50 px at the default size: the handle plus 30 px), in the legend. In a container under 28rem (a phone card) each name sits in a caption just above its pill and the pill keeps the value. A caption is never cut: when its pill is narrower than the word (a 20% part on a 320px card, or mid drag) it fades out and the legend row carries the name; without a legend it truncates instead.ring focus ring. Only the handles take touch-action: none, so the page still scrolls around the rail.| Key | Action |
|---|---|
| Arrow Right / Arrow Left | Moves the focused handle one step: the part on its left grows, the next one shrinks |
| Arrow Up / Arrow Down | Same as Right / Left (on the stacked rail, Down grows the part above) |
| Shift + Arrow, Page Up / Page Down | Moves the focused handle ten steps |
| Home / End | Moves the focused handle to its limit (it lands with the squash against the part at its minimum) |
| L, double click | Locks or unlocks the focused handle: a locked handle is a wall |
| + / − on a clicked part | Adjusts that part by one step, taking from (or giving to) its right neighbour |
| Tab / Shift+Tab | Moves focus between the handles |
With reduced motion (the OS setting, or MotionKitProvider reducedMotion="always") there is no charge, squash or rubber band. Handles still follow the finger and glide to key steps in the short fade time, the pills resize with them and the digits crossfade instead of rolling. Nothing disappears: every pill, label, share and legend amount stays.
transform and their length is set directly (an absolutely positioned pill, so nothing else reflows). Shares roll with the shared Roll primitive.motion only. Our code (component, Number Input for the inputs preset and the shared ball, beats and roll primitives) is about 14 kB gzip.Main spring of each temperament. Set it with the temperament prop or MotionKitProvider; the default is lively.
Not measured yet · budget 16.9 kB gzip
Component and MotionKit helpers; excludes react, react-dom, motion.
drag, press, keyboard focus, a value change, typing
No charge, squash or rubber band: the handles follow the finger and glide to key steps in the fade time, the pills resize with them and the digits crossfade.
Last 2 versions of Chrome, Edge, Firefox and Safari (iOS 16.4+)