Ranking field
Items put in order: drag the handle, press the arrow buttons, or Alt + Up and Alt + Down on an item.
import { RankingField, moveFormItem } from "@forgeron/ui";not ordered yet
import { RankingField } from "@forgeron/ui";
import { useState } from "react";
const items = [
{ id: "api", label: "A public API" },
{ id: "mobile", label: "A mobile app" },
{ id: "sso", label: "Single sign-on" },
{ id: "audit", label: "An audit log" },
];
export default function Default() {
const [order, setOrder] = useState<string[] | null>(null);
return (
<div style={{ display: "grid", gap: 12, width: 420, maxWidth: "100%" }}>
<RankingField
label="Rank these by how much you want them"
items={items}
value={order}
onChange={setOrder}
/>
<p style={{ margin: 0, font: "12px/18px var(--font-mono)", color: "var(--ink-muted)" }}>
{order ? order.join(" > ") : "not ordered yet"}
</p>
</div>
);
}import { RankingField } from "@forgeron/ui";
// Starts ordered: no dimming and no Keep this order button.
export default function Ordered() {
return (
<div style={{ width: 420, maxWidth: "100%" }}>
<RankingField
label="Your priorities"
defaultValue={["b", "c", "a"]}
items={[
{ id: "a", label: "Price" },
{ id: "b", label: "Quality" },
{ id: "c", label: "Delivery time" },
]}
/>
</div>
);
}API → Props
| Prop | Type | Default | Description |
|---|---|---|---|
label | string | — | Names the list for assistive technology: the question. |
items | { id, label }[] | — | What is ranked, in the order shown at first. |
value / defaultValue | string[] | null | — | The item ids in the chosen order. `null` until the respondent orders them: the list is dimmed and Keep this order accepts it. |
onChange | (ids: string[] | null) => void | — | After every move. |
invalid / describedBy | boolean / string | — | Ties the list to its error. |
disabled | boolean | — | Locks the list. |
className | string | — | Extra classes. |