Prepare the record
Aliquot / Sample 042
A 44px Vlak numeric input and styled unit selector with controlled quantity values, form submission and reset support.
Aliquot / Sample 042
Three ways in. They share one source, so the pixels match whichever you pick.
npm install @noorddev/vlak-react
// once, next to your app's root
import "@noorddev/vlak-react/css";
import { QuantityField } from "@noorddev/vlak-react";Precompiled React and one stylesheet. No compiler to configure. Per-component imports work too: @noorddev/vlak-react/components/quantity-field.
npx @noorddev/vlak-cli add quantity-field
The StyleX leaf lands in components/vlak/ with its dependencies, for your own compiler to own. See StyleX.
npx shadcn add https://vlak.dev/r/quantity-field.json
The same registry item, installed by shadcn's CLI.
<link rel="stylesheet" href="node_modules/@noorddev/vlak/css/vlak.css" />
No React. Link vlak.css and use the markup and classes below.
import { QuantityField } from "@noorddev/vlak-react";
<QuantityField label="Sample volume" name="volume" units={[{ value: "ul", label: "µL" }, { value: "ml", label: "mL" }]} defaultValue={{ amount: 250, unit: "ul" }} min={0} required description="Enter the amount and its unit" />A native numeric input and unit selector. Selection never converts the amount.
| Prop | Type | Default | Description |
|---|---|---|---|
labelrequired | ReactNode | ||
unitsrequired | readonly QuantityUnit[] | ||
value | QuantityValue | ||
defaultValue | QuantityValue | { amount: null, unit: null } | |
onValueChange | (value: QuantityValue) => void | Requests a quantity change. A unit change preserves the amount; the host owns conversion. | |
description | ReactNode | ||
unitName | string | name ? `${name}.unit` : undefined | Input names: name submits the amount; unitName defaults to name + '.unit'. |
amountLabel | string | "Amount" | |
unitLabel | string | "Unit" | |
unitPlaceholder | string | "Choose unit" | |
min | number | ||
max | number | ||
step | number | "any" | "any" | |
required | boolean | ||
readOnly | boolean | false |
Also accepts Omit<FieldsetHTMLAttributes<HTMLFieldSetElement>, "defaultValue">.
| Keys | Does |
|---|---|
| Tab | Moves between the amount input and unit selector. |
| Arrow keys | Uses native number stepping or opens and navigates the Vlak unit selector. Enter or Space confirms a unit; Escape closes its menu. |
<fieldset class="rs-quantity-field"><legend class="rs-quantity-field-legend">Sample volume</legend><div class="rs-quantity-field-row"><label class="rs-quantity-field-label">Amount<input class="rs-input rs-input-full rs-quantity-field-control" name="volume" type="number" step="any" value="250" /></label><div class="rs-quantity-field-label"><span id="quantity-unit-label">Unit</span><div class="rs-select rs-select-fluid"><button type="button" class="rs-dropdown" role="combobox" aria-labelledby="quantity-unit-label" aria-expanded="false" aria-haspopup="listbox"><span>µL</span></button></div></div></div></fieldset>