Components
ScaleInput
A rating scale drawn from the points and end words the product supplies, for a self-report the product reads, shipping no instrument of its own.
Usage
pnpm dlx shadcn@latest add @opsinjs/scale-input
The @opsinjs namespace is declared in your components.json. Everything it installs is code you then own. There is no runtime package to keep in step.
import { ScaleInput } from "@/components/ui/scale-input"<ScaleInput
label="Comfort right now"
points={10}
value={rating}
onValueChange={setRating}
minLabel="Not at all"
maxLabel="Completely"
/>Examples
scale-input · base base · style base-lyraOpen under the product themeA rating with end words
Ten points with a word at each end, from label, points, minLabel and maxLabel.
scale-input-rating-with-anchors · base base · style base-lyraOpen under the product theme"use client"
import { useState } from "react"
import { ScaleInput } from "@/components/ui/scale-input"
export default function ScaleInputRatingWithAnchors() {
const [rating, setRating] = useState<number | null>(7)
return (
<div className="w-full max-w-md">
<ScaleInput
label="Example rating"
points={10}
value={rating}
onValueChange={setRating}
minLabel="Not at all"
maxLabel="Completely"
/>
</div>
)
}No answer yet
value is null, so the scale draws with no point chosen rather than defaulting to
a middle the reader never picked.
scale-input-no-answer-yet · base base · style base-lyraOpen under the product theme"use client"
import { useState } from "react"
import { ScaleInput } from "@/components/ui/scale-input"
export default function ScaleInputNoAnswerYet() {
const [rating, setRating] = useState<number | null>(null)
return (
<div className="w-full max-w-md">
<ScaleInput
label="Example rating"
points={10}
value={rating}
onValueChange={setRating}
minLabel="Not at all"
maxLabel="Completely"
/>
</div>
)
}When to use it
Use it when
- One self-report on a scale the product's instrument defines, with the points and end words from the product.
- A single question asked repeatedly with the same points and end words, so the reader can watch their answer move.
- A rating with a low end and a high end the reader places themselves between, rather than unordered choices.
Do not use it when
- The answer is free text in the reader's own words, not a point on a scale.Use
textareainstead. - The options are a fixed set of labelled choices with no end word and no ordering.Use
radio-groupinstead. - A multi-question instrument where several rated items add up under one heading.Use
questionnaireinstead.
Clinical meaning
Asserts. The reader chose this point on a scale the product defined. The value
goes back through onValueChange, with no total, band, verdict or
interpretation added.
Never read as. A score, a measurement or a result opsinjs derived. A far point is a high self-report, and whether it matters is a clinical judgement this component does not make; it never diagnoses, triages or advises. See Health.
Colour axis. Neither. The scale writes neither data-status nor data-category,
and the chosen point takes the accent fill, which is neither axis. A product that decides a rating
matters says so on its own status surface. See
Two colour axes.
Thresholds. None. The points and end words arrive through points, minLabel
and maxLabel, and opsinjs ships no scale, no anchor words and no scoring. See
Health and Numbers and units.
Accessibility
One tab stop with a roving focus: role="radiogroup" on the root, role="radio" and
aria-checked on each point, and selection follows focus. Every point floors its hit
area at --opsin-target-minimum in rem, and the row wraps rather than shrinking a
point below its target. The audit made the chosen point repaint in forced colours to
the system Highlight pair, with a Highlight border and forced-color-adjust-none, so
selection stays distinct.
Residual items.
- The question reaches the radiogroup only as an
aria-label, which is weaker than a visible label. A visible label is the recommended enhancement, a decision shared with combobox. - In normal mode the selection carries no glyph, so luminance inversion and the border carry it without hue.
- Every contrast pair on the host's ground is unmeasured, and the report below prints only what has been measured.
| Key | Action | Notes |
|---|---|---|
| Tab | Moves focus into the scale, onto the chosen point | One tab stop. Unanswered, the first point takes it; a disabled point never does. |
| Shift+Tab | Moves focus back out of the scale | A single stop in reverse too. |
| Arrow Right, Arrow Down | Moves to the next point and selects it | Selection follows focus. Wraps last to first. Arrow Left and Right swap in right-to-left. |
| Arrow Left, Arrow Up | Moves to the previous point and selects it | Wraps from the first to the last. |
| Space | Selects the focused point | A point is a role="radio", so Space is its activator. |
| Enter | Does nothing | The primitive cancels Enter, so the scale does not submit a form. |
| Home, End | Not bound | The RadioGroup does not enable them, so they keep the browser default. |
Contrast: 36 measured token pairs, 15 below floor
| Pair | Theme | APCA Lc | WCAG 2.2 | Floor |
|---|---|---|---|---|
| body text on the page | light | 101.6 | 17.18:1 | Pass |
| body text on the page | dark | -100.5 | 18.00:1 | Pass |
| body text on a card | light | 104.7 | 17.96:1 | Pass |
| body text on a card | dark | -99.6 | 16.32:1 | Pass |
| body text on the muted ground | light | 98.1 | 16.32:1 | Pass |
| body text on the muted ground | dark | -97.5 | 13.77:1 | Pass |
| secondary text on the page | light | 83.9 | 7.42:1 | Pass |
| secondary text on the page | dark | -80.7 | 13.44:1 | Pass |
| secondary text on a card | light | 87.0 | 7.76:1 | Pass |
| secondary text on a card | dark | -79.8 | 12.19:1 | Pass |
| secondary text on the muted ground | light | 80.4 | 7.05:1 | Pass |
| secondary text on the muted ground | dark | -77.8 | 10.28:1 | Pass |
| a hairline boundary on the page | light | 19.3 | 1.41:1 | Below floor |
| a hairline boundary on the page | dark | -8.2 | 1.90:1 | Below floor |
| a hairline boundary on a card | light | 22.4 | 1.47:1 | Below floor |
| a hairline boundary on a card | dark | -7.3 | 1.72:1 | Below floor |
| a hairline boundary on the muted ground | light | 15.8 | 1.34:1 | Below floor |
| a hairline boundary on the muted ground | dark | 0.0 | 1.45:1 | Below floor |
| a placeholder boundary on the page | light | 69.8 | 4.52:1 | Pass |
| a placeholder boundary on the page | dark | -51.0 | 7.62:1 | Pass |
| a placeholder boundary on a card | light | 72.8 | 4.72:1 | Pass |
| a placeholder boundary on a card | dark | -50.1 | 6.91:1 | Pass |
| a placeholder boundary on the muted ground | light | 66.2 | 4.29:1 | Pass |
| a placeholder boundary on the muted ground | dark | -48.1 | 5.83:1 | Pass |
| a placeholder fill on the page | light | 8.3 | 1.18:1 | Below floor |
| a placeholder fill on the page | dark | -8.2 | 1.90:1 | Below floor |
| a placeholder fill on a card | light | 11.4 | 1.23:1 | Below floor |
| a placeholder fill on a card | dark | -7.3 | 1.72:1 | Below floor |
| a placeholder fill on the muted ground | light | 0.0 | 1.12:1 | Below floor |
| a placeholder fill on the muted ground | dark | 0.0 | 1.45:1 | Below floor |
| a placeholder boundary on its own fill | light | 58.9 | 3.84:1 | Pass |
| a placeholder boundary on its own fill | dark | -41.5 | 4.01:1 | Below floor |
| the card hairline on the page | light | 69.8 | 4.52:1 | Pass |
| the card hairline on the page | dark | -28.7 | 4.19:1 | Below floor |
| the card hairline on a card | light | 72.8 | 4.72:1 | Pass |
| the card hairline on a card | dark | -27.9 | 3.80:1 | Below floor |
These are the measured token pairs this component draws colour from, not a measurement of the component itself.
Props interface
Prop
Type
Generated from ScaleInputProps in registry/bases/base/scale-input.tsx.
points has no default, and fewer than two renders nothing with a development
warning. value is number | null: null draws nothing chosen, and a number
outside 1 to points does the same and warns. label is required: a
radiogroup with no accessible name is a defect the types cannot prevent.
Data attributes
| Attribute | Condition | Value |
|---|---|---|
| data-checked, data-unchecked | On each point, stamped by the Base UI Radio | One of the two, by whether the point is the chosen one |