Introducing PrimeReact v11-alpha 🎉Discover Now

Knob

An unstyled circular dial component for numeric input with SVG-based rendering.

Build fully custom circular dial controls with complete control over layout and styling.

50
basic-demo

Pre-styled Versions

Choose a pre-styled library to use Knob with ready-made designs.
For hook-based usage without components, see the Headless API.

Features#

  • Compound component API with four sub-components: Root, Range, Value, Text
  • SVG-based arc rendering with computed paths
  • Mouse drag, touch drag, and click-to-set interaction
  • Full keyboard navigation (arrows, Home, End, PageUp, PageDown)
  • Configurable min, max, step, size, and stroke width

Usage#

import { Knob } from 'primereact/knob';
<Knob.Root>
    <Knob.Range />
    <Knob.Value />
    <Knob.Text />
</Knob.Root>

Behavior#

Polymorphic Rendering#

Use as on any sub-component to change the rendered element.

<Knob.Root as="section"></Knob.Root>

Default elements: Root=div, Range=path, Value=path, Text=text. The SVG container is rendered automatically by Root.

Render Function Children#

Knob.Text accepts a render function as children, providing access to the component instance for custom value formatting.

<Knob.Text>{(instance) => <>{instance.knob?.state.value}%</>}</Knob.Text>

Pass Through#

Some parts may not be visible in the preview depending on the component's current state.

Loading...
/* Select a part to see its CSS selector for custom styling */

API#

KnobRoot#

NameTypeDefault
refRef<unknown>—
The reference to the component instance.
pIfbooleantrue
Whether the component should be rendered.
styleCSSProperties | ((instance?: KnobRootInstance) => CSSProperties)—
The style to apply to the component.
classNamestring | ((instance?: KnobRootInstance) => string)—
The class name to apply to the component.
asstring | number | bigint | boolean | ComponentClass<any, any> | FunctionComponent<any> | ReactElement<unknown, string | JSXElementConstructor<any>> | Iterable<ReactNode, any, any> | ReactPortal | Promise<AwaitedReactNode>—
The component type to render.
asChildbooleanfalse
Whether the component should be rendered as a child component.
instanceKnobRootInstance—
The instance to pass to the component.
ptSafeRecord<KnobRootPassThrough>—
The pass-through props to pass to the component.
ptOptionsPassThroughOptions—
The pass-through options to pass to the component.
unstyledboolean—
Whether the component should be rendered without classes.
dtunknown—
The design token to use for the component.
stylesStylesOptions<ComponentInstance>—
The styles to use for the component.
render(instance: KnobRootInstance) => ReactNode—
The render function to render the component with instance access.
childrenany—
The children to render. Accepts `React.ReactNode` for static content or a render function `(instance: I) => React.ReactNode` for instance access. Typed as `any` to avoid JSX type errors when used directly in templates.
defaultValuenumber—
Value of the knob.
valuenumber—
The default value of the knob.
sizenumber100
Size of the component in pixels.
stepnumber1
Step factor to increment/decrement the value.
minnumber0
Mininum boundary value.
maxnumber100
Maximum boundary value.
strokeWidthnumber14
Width of the knob stroke.
rangeColorstring—
Background color of the range arc.
valueColorstring—
Background color of the value arc.
textColorstring—
Color of the value text.
tabIndexnumber0
Index of the element in tabbing order.
invalidboolean—
When present, it specifies that the component should have invalid state style.
disabledboolean—
When present, it specifies that the component should be disabled.
readOnlyboolean—
When present, it specifies that the component value cannot be edited.
ariaLabelledbystring—
Establishes relationships between the component and label(s) where its value should be one or more element IDs.
ariaLabelstring—
Used to define a string that labels the element.
onValueChange(event: KnobRootChangeEvent) => void—
Callback fired when the knob's value changes.
[key: string]any—
pt-{optionName}-*-—
Pass through attributes for customizing component. For more info, see Pass Through tab.
AttributeValue
data-scope"knob"
data-part"root"
data-disabledPresent when disabled
data-readonlyPresent when read-only

Defines passthrough(pt) options of Knob component.

labeltypedescription
rootKnobRootPassThroughType<HTMLAttributes<HTMLDivElement>>Used to pass attributes to the root's DOM element.
svgKnobRootPassThroughType<HTMLAttributes<SVGSVGElement>>Used to pass attributes to the svg's DOM element.
rangeKnobRootPassThroughType<HTMLAttributes<SVGPathElement>>Used to pass attributes to the range's DOM element.
valueKnobRootPassThroughType<HTMLAttributes<SVGPathElement>>Used to pass attributes to the value's DOM element.
textKnobRootPassThroughType<HTMLAttributes<SVGTextElement>>Used to pass attributes to the text's DOM element.

KnobRange#

NameTypeDefault
refRef<unknown>—
The reference to the component instance.
pIfbooleantrue
Whether the component should be rendered.
styleCSSProperties | ((instance?: KnobRangeInstance) => CSSProperties)—
The style to apply to the component.
classNamestring | ((instance?: KnobRangeInstance) => string)—
The class name to apply to the component.
asstring | number | bigint | boolean | ComponentClass<any, any> | FunctionComponent<any> | ReactElement<unknown, string | JSXElementConstructor<any>> | Iterable<ReactNode, any, any> | ReactPortal | Promise<AwaitedReactNode>—
The component type to render.
asChildbooleanfalse
Whether the component should be rendered as a child component.
instanceKnobRangeInstance—
The instance to pass to the component.
ptSafeRecord<KnobRangePassThrough>—
The pass-through props to pass to the component.
ptOptionsPassThroughOptions—
The pass-through options to pass to the component.
unstyledboolean—
Whether the component should be rendered without classes.
dtunknown—
The design token to use for the component.
stylesStylesOptions<ComponentInstance>—
The styles to use for the component.
render(instance: KnobRangeInstance) => ReactNode—
The render function to render the component with instance access.
childrenany—
The children to render. Accepts `React.ReactNode` for static content or a render function `(instance: I) => React.ReactNode` for instance access. Typed as `any` to avoid JSX type errors when used directly in templates.
[key: string]any—
pt-{optionName}-*-—
Pass through attributes for customizing component. For more info, see Pass Through tab.
AttributeValue
data-scope"knob"
data-part"range"

Defines passthrough(pt) options of KnobRange component.

labeltypedescription
rootKnobRangePassThroughType<HTMLAttributes<SVGPathElement>>Used to pass attributes to the root's DOM element.

KnobValue#

NameTypeDefault
refRef<unknown>—
The reference to the component instance.
pIfbooleantrue
Whether the component should be rendered.
styleCSSProperties | ((instance?: KnobValueInstance) => CSSProperties)—
The style to apply to the component.
classNamestring | ((instance?: KnobValueInstance) => string)—
The class name to apply to the component.
asstring | number | bigint | boolean | ComponentClass<any, any> | FunctionComponent<any> | ReactElement<unknown, string | JSXElementConstructor<any>> | Iterable<ReactNode, any, any> | ReactPortal | Promise<AwaitedReactNode>—
The component type to render.
asChildbooleanfalse
Whether the component should be rendered as a child component.
instanceKnobValueInstance—
The instance to pass to the component.
ptSafeRecord<KnobValuePassThrough>—
The pass-through props to pass to the component.
ptOptionsPassThroughOptions—
The pass-through options to pass to the component.
unstyledboolean—
Whether the component should be rendered without classes.
dtunknown—
The design token to use for the component.
stylesStylesOptions<ComponentInstance>—
The styles to use for the component.
render(instance: KnobValueInstance) => ReactNode—
The render function to render the component with instance access.
childrenany—
The children to render. Accepts `React.ReactNode` for static content or a render function `(instance: I) => React.ReactNode` for instance access. Typed as `any` to avoid JSX type errors when used directly in templates.
[key: string]any—
pt-{optionName}-*-—
Pass through attributes for customizing component. For more info, see Pass Through tab.
AttributeValue
data-scope"knob"
data-part"value"

Defines passthrough(pt) options of KnobValue component.

labeltypedescription
rootKnobValuePassThroughType<HTMLAttributes<SVGPathElement>>Used to pass attributes to the root's DOM element.

KnobText#

NameTypeDefault
refRef<unknown>—
The reference to the component instance.
pIfbooleantrue
Whether the component should be rendered.
styleCSSProperties | ((instance?: KnobTextInstance) => CSSProperties)—
The style to apply to the component.
classNamestring | ((instance?: KnobTextInstance) => string)—
The class name to apply to the component.
asstring | number | bigint | boolean | ComponentClass<any, any> | FunctionComponent<any> | ReactElement<unknown, string | JSXElementConstructor<any>> | Iterable<ReactNode, any, any> | ReactPortal | Promise<AwaitedReactNode>—
The component type to render.
asChildbooleanfalse
Whether the component should be rendered as a child component.
instanceKnobTextInstance—
The instance to pass to the component.
ptSafeRecord<KnobTextPassThrough>—
The pass-through props to pass to the component.
ptOptionsPassThroughOptions—
The pass-through options to pass to the component.
unstyledboolean—
Whether the component should be rendered without classes.
dtunknown—
The design token to use for the component.
stylesStylesOptions<ComponentInstance>—
The styles to use for the component.
render(instance: KnobTextInstance) => ReactNode—
The render function to render the component with instance access.
childrenany—
The children to render. Accepts `React.ReactNode` for static content or a render function `(instance: I) => React.ReactNode` for instance access. Typed as `any` to avoid JSX type errors when used directly in templates.
[key: string]any—
pt-{optionName}-*-—
Pass through attributes for customizing component. For more info, see Pass Through tab.
AttributeValue
data-scope"knob"
data-part"text"

Defines passthrough(pt) options of KnobText component.

labeltypedescription
rootKnobTextPassThroughType<HTMLAttributes<SVGTextElement>>Used to pass attributes to the root's DOM element.

Accessibility#

Screen Reader#

Knob renders an SVG element with role="slider" and sets aria-valuemin, aria-valuemax, and aria-valuenow to communicate the current state. Provide an accessible name with ariaLabel or ariaLabelledby. When disabled or read-only, the respective aria-disabled and aria-readonly states are applied.

<Knob.Root ariaLabel="Volume" defaultValue={50}></Knob.Root>

If you already render a visible label, connect it using ariaLabelledby.

<span id="volume-label">Volume</span>
<Knob.Root ariaLabelledby="volume-label" defaultValue={50}></Knob.Root>

Keyboard Support#

KeyFunction
tabMoves focus to the knob.
left/down arrowDecrements the value.
right/up arrowIncrements the value.
homeSets the value to min.
endSets the value to max.
page upIncrements the value by 10.
page downDecrements the value by 10.