Skip to content

Commit

Permalink
test: assert typed option search
Browse files Browse the repository at this point in the history
  • Loading branch information
welingtonms committed Sep 4, 2023
1 parent ee32b2d commit 69b5e46
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
31 changes: 31 additions & 0 deletions packages/xb-wc/src/components/dropdown/dropdown.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,37 @@ describe( '<xb-dropdown>', () => {
cy.get( '@menu' ).should( 'not.have.attr', 'aria-activedescendant' );
} );

it( 'should focus via keyboard-typed search', () => {
// this is powed by the focus-manager

cy.mount( html`
<xb-dropdown>
<xb-dropdown-trigger id="trigger-actions">Actions</xb-dropdown-trigger>
<xb-dropdown-menu id="actions-menu">
<xb-dropdown-item id="item-accept">Accept</xb-dropdown-item>
<xb-dropdown-item id="item-change">Change</xb-dropdown-item>
<xb-dropdown-item id="item-leave">Leave</xb-dropdown-item>
</xb-dropdown-menu>
</xb-dropdown>
` );

cy.get( 'xb-dropdown' ).find( 'xb-dropdown-trigger' ).as( 'trigger' );
cy.get( 'xb-dropdown' ).find( 'xb-dropdown-menu' ).as( 'menu' );

cy.get( '@trigger' ).click();

cy.get( '@menu' ).should( 'have.attr', 'aria-activedescendant', 'item-accept' );
cy.get( '@menu' ).find( '.is-focused' ).should( 'have.text', 'Accept' );

cy.get( '@menu' ).type( 'leav' );

cy.get( '@menu' ).should( 'have.attr', 'aria-activedescendant', 'item-leave' );
cy.get( '@menu' ).find( '.is-focused' ).should( 'have.text', 'Leave' );

cy.get( '@trigger' ).click();
} );

it( 'should navigate & select using the keyboard', () => {
const onClickSpy = cy.stub().as( 'onClickSpy' );
cy.mount( html`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,8 @@ class FocusManagerController {

element.classList.add( 'is-focused' );

// TODO: scroll element into view

this.getInteractiveElement().setAttribute( 'aria-activedescendant', element.id );
this.activeDescendant = element.id;
};
Expand Down

0 comments on commit 69b5e46

Please sign in to comment.