From 40eca0b26f0e394be8a6db601effff067dea0a71 Mon Sep 17 00:00:00 2001 From: zepumph Date: Tue, 26 Jan 2021 17:01:30 -0900 Subject: [PATCH] only add/remove if applicable, support weird focus cases, https://github.com/phetsims/scenery/issues/1147 --- js/listeners/PressListener.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/js/listeners/PressListener.js b/js/listeners/PressListener.js index 88a97e562..bcc2da117 100644 --- a/js/listeners/PressListener.js +++ b/js/listeners/PressListener.js @@ -894,7 +894,9 @@ class PressListener { 'cannot focus node with zero or multiple accessible displays attached' ); // this.display = accessibleDisplays[ 0 ]; - this.display.focusHighlightsVisibleProperty.link( this.boundInvalidateOverListener ); + if ( !this.display.focusHighlightsVisibleProperty.hasListener( this.boundInvalidateOverListener ) ) { + this.display.focusHighlightsVisibleProperty.link( this.boundInvalidateOverListener ); + } // On focus, button should look 'over'. this.isFocusedProperty.value = true; @@ -907,7 +909,9 @@ class PressListener { */ blur() { if ( this.display ) { - this.display.focusHighlightsVisibleProperty.unlink( this.boundInvalidateOverListener ); + if ( this.display.focusHighlightsVisibleProperty.hasListener( this.boundInvalidateOverListener ) ) { + this.display.focusHighlightsVisibleProperty.unlink( this.boundInvalidateOverListener ); + } this.display = null; }