From 7c7385234820c13cfbbe02cfff8671d382d7a988 Mon Sep 17 00:00:00 2001 From: Chris Malley Date: Sun, 20 Jan 2019 23:15:17 -0700 Subject: [PATCH] move displayOnlyProperty to ComboBox, #451 --- js/ComboBox.js | 13 +++++++++++++ js/ComboBoxButton.js | 27 ++++++++++++++------------- 2 files changed, 27 insertions(+), 13 deletions(-) diff --git a/js/ComboBox.js b/js/ComboBox.js index 690d128e..23720d05 100644 --- a/js/ComboBox.js +++ b/js/ComboBox.js @@ -177,6 +177,19 @@ define( require => { }; this.enabledProperty.link( enabledObserver ); + // @private for use via PhET-iO, see https://github.com/phetsims/sun/issues/451 + // This is NOT reset when the Reset All button is pressed. + this.displayOnlyProperty = new BooleanProperty( false, { + tandem: options.tandem.createTandem( 'displayOnlyProperty' ), + phetioDocumentation: 'disables interaction with the ComboBox and ' + + 'makes it appear like a display that shows the current selection' + } ); + this.displayOnlyProperty.link( displayOnly => { + this.hideListBox(); + this.button.setDisplayOnly( displayOnly ); + this.pickable = !displayOnly; + } ); + // @private called by dispose this.disposeComboBox = () => { diff --git a/js/ComboBoxButton.js b/js/ComboBoxButton.js index 03d55c26..82122c17 100644 --- a/js/ComboBoxButton.js +++ b/js/ComboBoxButton.js @@ -11,7 +11,6 @@ define( require => { // modules const AccessiblePeer = require( 'SCENERY/accessibility/AccessiblePeer' ); - const BooleanProperty = require( 'AXON/BooleanProperty' ); const HStrut = require( 'SCENERY/nodes/HStrut' ); const Node = require( 'SCENERY/nodes/Node' ); const Path = require( 'SCENERY/nodes/Path' ); @@ -188,18 +187,20 @@ define( require => { property.unlink( propertyObserver ); }; - // @private for use via PhET-iO, see https://github.com/phetsims/sun/issues/451 - // This is NOT reset when the Reset All button is pressed. - this.displayOnlyProperty = new BooleanProperty( false, { - tandem: options.tandem.createTandem( 'displayOnlyProperty' ), - phetioDocumentation: 'disables interaction with the ComboBox button and ' + - 'makes it appear like a display that shows the current selection' - } ); - this.displayOnlyProperty.link( displayOnly => { - arrow.visible = !displayOnly; - separator.visible = !displayOnly; - this.pickable = !displayOnly; - } ); + // @private needed by methods + this.arrow = arrow; + this.separator = separator; + } + + /** + * Sets the button to look like a value display instead of a combo box button. + * See https://github.com/phetsims/sun/issues/451 + * @param {boolean} displayOnly + * @public + */ + setDisplayOnly( displayOnly ) { + this.arrow.visible = !displayOnly; + this.separator.visible = !displayOnly; } /**