Knob

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.

0

<Knob value={value} onChange={(e) => setValue(e.value)} />
         

Boundaries are configured with the min and max properties whose defaults are 0 and 100 respectively.

10

<Knob value={value} onChange={(e) => setValue(e.value)} min={-50} max={50} />
         

Size of each movement is defined with the step property.

10

<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 .

60%

<Knob value={value} onChange={(e) => setValue(e.value)} valueTemplate={'{value}%'} />
         

The border size is specified with the stroke property as a number in pixels.

40

<Knob value={value} onChange={(e) => setValue(e.value)} strokeWidth={5} />
         

Diameter of the knob is defined in pixels using the size property.

60

<Knob value={value} onChange={(e) => setValue(e.value)} size={200} />
         

Colors are customized with the textColor, rangeColor and valueColor properties.

75

<Knob value={value} onChange={(e) => setValue(e.value)} valueColor="#708090" rangeColor="#48d1cc" />
         

Knob can be controlled with custom controls as well.

0

<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.

50

<Knob value={50} readOnly />
         

When disabled is present, a visual hint is applied to indicate that the Knob cannot be interacted with.

50

<Knob value={50} disabled />
         

Screen Reader

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"/>
     

Keyboard Support

KeyFunction
tabMoves focus to the slider.
left arrowdown arrowDecrements the value.
right arrowup arrowIncrements the value.
homeSet the minimum value.
endSet the maximum value.
page upIncrements the value by 10 steps.
page downDecrements the value by 10 steps.