Knob is a form component to define number inputs with a dial.
import { Knob } from 'primereact/knob';
Knob is used as a controlled input with value and onChange properties.
<Knob value={value} onChange={(e) => setValue(e.value)} />
Boundaries are configured with the min and max properties whose defaults are 0 and 100 respectively.
<Knob value={value} onChange={(e) => setValue(e.value)} min={-50} max={50} />
Size of each movement is defined with the step property.
<Knob value={value} step={10} onChange={(e) => setValue(e.value)} />
Label is a string template that can be customized with the valueTemplate property having 60 as the placeholder .
<Knob value={value} onChange={(e) => setValue(e.value)} valueTemplate={'{value}%'} />
The border size is specified with the stroke property as a number in pixels.
<Knob value={value} onChange={(e) => setValue(e.value)} strokeWidth={5} />
Diameter of the knob is defined in pixels using the size property.
<Knob value={value} onChange={(e) => setValue(e.value)} size={200} />
Colors are customized with the textColor, rangeColor and valueColor properties.
<Knob value={value} onChange={(e) => setValue(e.value)} valueColor="#708090" rangeColor="#48d1cc" />
Knob can be controlled with custom controls as well.
<Knob value={value} size={150} />
<Button icon="pi pi-plus" onClick={() => setValue(value + 1)} disabled={value === 100} />
<Button icon="pi pi-minus" onClick={() => setValue(value - 1)} disabled={value === 0} />
When readOnly present, value cannot be edited.
<Knob value={50} readOnly />
When disabled is present, a visual hint is applied to indicate that the Knob cannot be interacted with.
<Knob value={50} disabled />
Knob element component uses slider role in addition to the aria-valuemin, aria-valuemax and aria-valuenow attributes. Value to describe the component can be defined usingaria-labelledby and aria-label props.
<label htmlFor="firstname">Firstname</label>
<InputText id="firstname" />
<span id="lastname">Lastname</span>
<InputText aria-labelledby="lastname" />
<InputText aria-label="Age"/>
Key | Function |
---|---|
tab | Moves focus to the slider. |
left arrowdown arrow | Decrements the value. |
right arrowup arrow | Increments the value. |
home | Set the minimum value. |
end | Set the maximum value. |
page up | Increments the value by 10 steps. |
page down | Decrements the value by 10 steps. |