Skip to content

NumberControl

NumberControl (from scenerystack/scenery-phet) bundles a title, a value readout, a slider, and (by default) increment/decrement arrow buttons into one composite Node bound to a numeric Property. It's the standard way to expose a bounded numeric quantity to the user without hand-assembling a slider, a NumberDisplay, and arrow buttons yourself every time.

ts
import { NumberControl } from 'scenerystack/scenery-phet';
import { NumberProperty } from 'scenerystack/axon';
import { Range } from 'scenerystack/dot';

A minimal example

ts
const frequencyProperty = new NumberProperty( 5, { range: new Range( 0, 10 ) } );

const frequencyControl = new NumberControl(
  'Frequency',
  frequencyProperty,
  new Range( 0, 10 ),
  {
    delta: 0.5,
    numberDisplayOptions: {
      decimalPlaces: 1,
      valuePattern: '{{value}} Hz'
    }
  }
);

Constructor

ts
new NumberControl(
  title: string | TReadOnlyProperty<string> | Node,
  numberProperty: PhetioProperty<number>,
  numberRange: Range,
  providedOptions?: NumberControlOptions
)

title can be a plain string, a string Property (for i18n), or an arbitrary Node if you need something richer than text.

Options

OptionDefaultEffect
delta1Step size used by both the arrow buttons and the slider's keyboard shift-step
includeArrowButtonstrueWhether to show the increment/decrement arrow buttons
numberDisplayOptions{}Options forwarded to the internal NumberDisplay (readout formatting, units, decimal places, …)
sliderOptions{}Options forwarded to the internal Slider — accepts majorTicks, minorTickSpacing in addition to normal slider options
arrowButtonOptions{}Options forwarded to the increment/decrement ArrowButtons
titleNodeOptions{}Options forwarded to the title Text/RichText
useRichTextfalseRender the title with RichText instead of Text
enabledRangePropertyConstrains the effective slider/arrow-button range to a sub-range of numberRange
startCallback / endCallbackno-opsCalled when interaction begins/ends on any subcomponent (slider drag or arrow press)
layoutFunctionNumberControl.createLayoutFunction1()Arranges title, readout, slider, and arrow buttons; swap in createLayoutFunction2/3/4 for the other standard layouts
soundGeneratorauto-createdA ValueChangeSoundPlayer; pass null for silence

Static helpers

Static memberPurpose
NumberControl.withMinMaxTicks( label, property, range, options? )Convenience constructor that adds major ticks labeled with the range's min and max
NumberControl.createLayoutFunction1()createLayoutFunction4()Pre-built layout strategies for options.layoutFunction, each with its own spacing/alignment options

Public API

MemberDescription
sliderThe internal HSlider, exposed read-only for accessibility wiring

Don't mix general and per-component callbacks

Use either the top-level startCallback/endCallback pair, or the per-component callbacks nested in sliderOptions/arrowButtonOptions (startDrag, leftStart, rightEnd, …) — never both. NumberControl asserts against mixing them, since it can't guarantee sensible ordering between the two mechanisms.