Number Field
A numeric input element with increment and decrement buttons, and a scrub area.
<?phem
use Phem\Attribute\Component;
use Phem\Node;
use function Phem\Ui\{NumberField, NumberFieldDecrement, NumberFieldGroup, NumberFieldIncrement, NumberFieldInput, NumberFieldScrubArea, NumberFieldScrubAreaCursor};
#[Component]
function NumberFieldHeroDemo(): Node
{
return (
<NumberField defaultValue={{ 100 }}>
<NumberFieldScrubArea>
<label htmlFor="amount" className="cursor-ew-resize text-sm font-bold text-neutral-950 dark:text-white">Amount</label>
<NumberFieldScrubAreaCursor />
</NumberFieldScrubArea>
<NumberFieldGroup>
<NumberFieldDecrement />
<NumberFieldInput id="amount" />
<NumberFieldIncrement />
</NumberFieldGroup>
</NumberField>
);
}
API reference#
Import the components of the family:
use function Phem\Ui\{NumberField, NumberFieldScrubArea, NumberFieldScrubAreaCursor, NumberFieldGroup, NumberFieldInput, NumberFieldDecrement, NumberFieldIncrement};NumberField#
A text input for a number, with steppers and a scrub area: Base UI NumberField.Root, on the phem-number-field controller. With a name (or phem:bind), a hidden input keeps the raw value for the form. format takes the options of Intl.NumberFormat.
| Prop | Type | Default |
|---|---|---|
defaultValue | ?float | null |
min | ?float | null |
max | ?float | null |
step | float | 1 |
smallStep | float | 0.1 |
largeStep | float | 10 |
allowOutOfRange | bool | false |
snapOnStep | bool | false |
allowWheelScrub | bool | false |
format | ?array | null |
locale | ?string | null |
disabled | bool | false |
readOnly | bool | false |
required | bool | false |
name | ?string | null |
value | ?Bound | null |
children | ?Html | null |
...rest | mixed | — |
NumberFieldScrubArea#
An area that changes the value when the user drags in it, such as the label.
| Prop | Type | Default |
|---|---|---|
children | ?Html | null |
...rest | mixed | — |
NumberFieldScrubAreaCursor#
The virtual cursor that shows while the user drags in the scrub area.
| Prop | Type | Default |
|---|---|---|
children | ?Html | null |
...rest | mixed | — |
NumberFieldGroup#
The group of the input and its two buttons.
| Prop | Type | Default |
|---|---|---|
children | ?Html | null |
...rest | mixed | — |
NumberFieldInput#
The text input of the number. The arrow keys change the value by the step.
The input and the buttons of a group have the radius on the outer corners of the group (first:rounded-s-control last:rounded-e-control). To change these corners, use the same variants: first:rounded-s-none last:rounded-e-none.
| Prop | Type | Default |
|---|---|---|
...rest | mixed | — |
NumberFieldDecrement#
The button that takes a step from the value. A press that stays repeats it.
| Prop | Type | Default |
|---|---|---|
children | ?Html | null |
...rest | mixed | — |
NumberFieldIncrement#
The button that adds a step to the value. A press that stays repeats it.
| Prop | Type | Default |
|---|---|---|
children | ?Html | null |
...rest | mixed | — |
The source of the examples: examples/ui/NumberField.phem.