Skip to content

JoistButton

JoistButton (from scenerystack/joist) is the base class behind the chrome buttons that live directly in the NavigationBarHomeButton, the PhET-menu button, and similar — none of which use the ordinary sun button visuals. Instead of a fixed background rectangle, JoistButton draws two overlapping highlight shapes (one for a light background, one for a dark one) and shows whichever one is legible against the navigation bar's current fill, switching automatically as sim.lookAndFeel's color changes (e.g. between the black home-screen background and a lighter in-sim navigation bar). You extend it directly only if you're building a custom navigation-bar-style button; ordinary in-sim UI should use sun's regular button classes instead.

ts
import { JoistButton } from 'scenerystack/joist';
import type { TReadOnlyProperty } from 'scenerystack/axon';
import type { Color, Node } from 'scenerystack/scenery';

A minimal example

ts
class MyChromeButton extends JoistButton {
  public constructor( content: Node, navigationBarFillProperty: TReadOnlyProperty<Color>, tandem: Tandem ) {
    super( content, navigationBarFillProperty, {
      tandem: tandem,
      listener: () => console.log( 'pressed' )
    } );
  }
}

Constructor

ts
new JoistButton(
  content: Node,
  navigationBarFillProperty: TReadOnlyProperty<Color>,
  providedOptions: JoistButtonOptions // tandem is required
)

navigationBarFillProperty is what drives the light/dark highlight swap — pass sim.lookAndFeel.navigationBarFillProperty (a TReadOnlyProperty<Color>) when building a real navigation-bar button.

Options

OptionDefaultEffect
listenernullCallback invoked when the button fires
highlightExtensionWidth / highlightExtensionHeight0Grows the highlight shape beyond content's bounds
highlightCenterOffsetX / highlightCenterOffsetY0Shifts the highlight's center relative to content's center
pointerAreaDilationX / pointerAreaDilationY0Expands mouse/touch areas beyond content's bounds, to close gaps between adjacent chrome buttons and their labels
focusHighlightDilationX / focusHighlightDilationY0Expands the keyboard focus highlight independently of the pointer areas
enabledPropertyOptions{ phetioFeatured: false }JoistButtons intentionally default to a non-featured enabledProperty, unlike most sun buttons

Protected members (for subclasses)

MemberDescription
buttonModelThe underlying PushButtonModel driving press/release behavior
interactionStatePropertyA PushButtonInteractionStateProperty tracking over/pressed/idle state, used to decide which highlight is visible

Method

MethodEffect
isPDOMClicking()Whether the button is currently firing due to keyboard/screen-reader (PDOM) activation rather than pointer input

The two highlight Nodes are both always in the scene graph

JoistButton builds a brightenHighlight (white, for dark backgrounds) and a darkenHighlight (black, for light backgrounds) as siblings of content in every instance, and toggles their visible flags based on navigationBarFillProperty and interaction state rather than swapping children in and out. If you're customizing appearance by inspecting a JoistButton's children, expect exactly three: content, brightenHighlight, darkenHighlight, in that order.