Skip to content

ArrowButton ​

ArrowButton (from scenerystack/sun) is a thin subclass of RectangularPushButton whose content is generated for you: a triangular arrow pointing 'up', 'down', 'left', or 'right'. It's the button NumberSpinner uses internally for its increment/decrement controls, and it's a reasonable choice any time you need a standalone "step" control with an arrow glyph rather than building your own Path and wiring it into RectangularPushButton yourself.

ts
import { ArrowButton } from 'scenerystack/sun';
import { NumberProperty } from 'scenerystack/axon';
import { Range } from 'scenerystack/dot';

const range = new Range( 0, 20 );
const valueProperty = new NumberProperty( 10, { range: range } );

const decrementButton = new ArrowButton( 'left', () => {
  valueProperty.value = Math.max( range.min, valueProperty.value - 1 );
} );
const incrementButton = new ArrowButton( 'right', () => {
  valueProperty.value = Math.min( range.max, valueProperty.value + 1 );
} );

The constructor takes the direction and the fire callback directly (not through a listener option — ArrowButton sets options.listener internally, so content and listener are omitted from ArrowButtonOptions). Unlike a plain RectangularPushButton, ArrowButton enables fireOnHold by default, so press-and-hold repeats the action automatically.

Options ​

ArrowButtonOptions combines its own arrow-drawing options with RectangularPushButtonOptions (minus content/listener, which ArrowButton supplies):

OptionDefaultEffect
arrowHeight20Arrow size from tip to base
arrowWidtharrowHeight * √3 / 2Width of the arrow's base
arrowFill / arrowStroke / arrowLineWidth'black' / null / 1Styling of the arrow Path
numberOfArrows1Draws several overlapping arrows (a ">>" fast-forward look) instead of one
arrowSpacing-arrowHeight / 2Offset between stacked arrows when numberOfArrows > 1
fireOnHoldtruePress-and-hold repeat firing is on by default (opposite of RectangularPushButton)
fireOnHoldDelay / fireOnHoldInterval400 / 100Timing (ms) for the repeat firing
cornerRadius4Smaller default than the general-purpose rectangular button
touchAreaXDilation / touchAreaYDilation7 / 7Expand the touch hit area beyond the small visual button

Pass the direction and callback positionally, not as options

ArrowButton's constructor is new ArrowButton( direction, callback, options? ) — direction and the fire callback aren't part of the options object the way listener is for RectangularPushButton.