Knob is a form component to define number inputs with a dial.
import Knob from 'primevue/knob';
Knob is an input component and used with the standard v-model directive.
<Knob v-model="value" />
Boundaries are configured with the min and max values whose defaults are 0 and 100 respectively.
<Knob v-model="value" :min="-50" :max="50" />
Step factor is 1 by default and can be customized with step option.
<Knob v-model="value5" :step="10" />
The label can be customized with the valueTemplate property using either a template string or a function.
<Knob v-model="value" valueTemplate="{value}%" />
The border size is specified with the stroke property as a number in pixels.
<Knob v-model="value" :strokeWidth="5" />
Diameter of the knob is defined in pixels using the size property.
<Knob v-model="value" :size="200" />
valueColor defines the value color, rangeColor defines the range background and similarly textColor configures the color of the value text. In addition, strokeWidth is used to determine the width of the stroke of range and value sections.
<Knob v-model="value" valueColor="SlateGray" rangeColor="MediumTurquoise" />
Knob can be controlled with custom controls as well.
<Knob v-model="value" :size="150" readonly />
<div class="flex gap-2">
<Button icon="pi pi-plus" @click="value++" :disabled="value >= 100" />
<Button icon="pi pi-minus" @click="value--" :disabled="value <= 0" />
</div>
When readonly present, value cannot be edited.
<Knob v-model="value" readonly />
When disabled is present, a visual hint is applied to indicate that the Knob cannot be interacted with.
<Knob v-model="value" 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 using aria-labelledby and aria-label props.
<span id="label_number">Number</span>
<Knob aria-labelledby="label_number" />
<Knob aria-label="Number" />
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. |