Skip to content

ABSwitch

Overview

ABSwitch is a control for switching between 2 choices, referred to as 'A' & 'B'. Choice 'A' is to the left of the switch, choice 'B' is to the right. This decorates ToggleSwitch with labels.

@author Chris Malley (PixelZoom, Inc.)

Class ABSwitch

import { ABSwitch } from 'scenerystack/sun';

Constructor

new ABSwitch( property : Property<T>, valueA : T, labelA : Node, valueB : T, labelB : Node, providedOptions? : ABSwitchOptions )

Instance Methods

dispose()

onEnabledPropertyChange( enabled : boolean )

(protected)

Provide a custom look for when this switch is disabled. We are overriding the default implementation so that the unselected label does not appear to be doubly disabled when the ABSwitch is disabled. See https://github.com/phetsims/sun/issues/853

Instance Properties

onInputEmitter : TEmitter

(readonly)

Emits on input that results in a change to the Property value, after the Property has changed.

Type ABSwitchOptions

Accessible name for the ABSwitch is created by combining the accessible names of the labels. See options.

import type { ABSwitchOptions } from 'scenerystack/sun';
  • toggleSwitchOptions?: ToggleSwitchOptions
    options passed to ToggleSwitch
  • setLabelEnabled?: ( labelNode: Node, enabled: boolean ) => void
    method of making a label look disabled
  • valueAAccessibleName?: TReadOnlyProperty<string> | string | null
    Accessible names for each value. They will be inserted into a pattern string for the accessible name of the ABSwitch. If not provided, ABSwitch will try to find default values from the label Nodes. The final string will look like: "{{valueAAccessibleName}}, Switch to {{valueBAccessibleName}}"
  • valueBAccessibleName?: TReadOnlyProperty<string> | string | null
  • centerOnSwitch?: boolean
    if true, this.center will be at the center of the ToggleSwitch
  • & StrictOmit<TrimParallelDOMOptions<HBoxOptions>, "accessibleName">

Source Code

See the source for ABSwitch.ts in the sun repository.