Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

problem with a11y listeners for sun buttons #463

Closed
pixelzoom opened this issue Jan 22, 2019 · 5 comments
Closed

problem with a11y listeners for sun buttons #463

pixelzoom opened this issue Jan 22, 2019 · 5 comments

Comments

@pixelzoom
Copy link
Contributor

a11y has introduced a general problem with sun buttons. In button listeners, we need to know whether a button fired due to an event involving accessible input (e.g. keyboard) or pointer. And button listeners are currently provided with no information to make that decisions.

E.g. in ComboBox, here's what we currently had to do:

      // Clicking on the button toggles visibility of the list box
      this.button.addListener( () => {
        if ( !this.listBox.visible ) {
          this.showListBox();
        }
        else {
          this.hideListBox();
        }
      } );

      // Handle button clicks, for a11y
      this.button.addInputListener( {
        click: () => {

          //TODO sun#314 order dependency, requires that button's listener has called showList
          if ( this.listBox.visible ) {
            this.listBox.focus();
          }
        }
      } );

This requires a completely different listener for the button to handle button clicks for a11y, outside of sun/buttons/ listener API. And a11y is not at all integrated (or integratabtle) into a standard button listener.

We need a solution that allows us to write button listeners that handle all forms of input.

@pixelzoom
Copy link
Contributor Author

pixelzoom commented Jan 22, 2019

In ComboBox, something better might look like:

      // Clicking on the button toggles visibility of the list box
      this.button.addListener( event => {
        if ( !this.listBox.visible ) {
          this.showListBox();
          if ( event.pointer.type === 'a11y' ) {
            this.listBox.focus();
          }
        }
        else {
          this.hideListBox();
          if ( event.pointer.type === 'a11y' ) {
            this.button.focus();
          }
        }
      } );

@pixelzoom
Copy link
Contributor Author

pixelzoom commented Jan 22, 2019

But see also the problem with if ( event.pointer.type === 'a11y' ), phetsims/scenery#932.

@zepumph
Copy link
Member

zepumph commented Jun 4, 2019

Looks like this is already solved, @jessegreenberg offered to just clean it up.

@zepumph
Copy link
Member

zepumph commented Mar 6, 2024

This is not duplicated anymore:

sun/js/ComboBox.ts

Lines 364 to 368 in ee93abe

// Clicking on the button toggles visibility of the list box
this.button.addListener( () => {
this.listBox.visibleProperty.value = !this.listBox.visibleProperty.value;
this.listBox.visibleProperty.value && this.listBox.focusListItemNode( property.value );
} );

Also noting that sun buttons use a PressListener now, thus supporting keyboard in addition to mouse touch input.

@jessegreenberg
Copy link
Contributor

OK thanks, you were right @zepumph - I don't see anything else for this issue. There is also SceneryEvent.isFromPDOM if there is a need for code like #463 (comment).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants