fix: preserve progressive CHRNX search
This commit is contained in:
7 files changed
+66
-31
No files matched your search
+15
-6
@@ -2,11 +2,14 @@ const modulePath = '../../assets/js/search.js';
|
||||
|
||||
function markup() {
|
||||
document.body.innerHTML = `
|
||||
<form data-chrnx-search action="/" role="search">
|
||||
<label for="chrnx-search-input">Search</label>
|
||||
<input id="chrnx-search-input" name="s" type="search">
|
||||
<form data-chrnx-search action="/" role="search" data-expanded="true">
|
||||
<div id="chrnx-search-panel" data-chrnx-search-panel>
|
||||
<label for="chrnx-search-input">Search</label>
|
||||
<input id="chrnx-search-input" name="s" type="search">
|
||||
</div>
|
||||
<button type="submit" data-chrnx-search-button data-label-open="Open search"
|
||||
data-label-submit="Search">Search</button>
|
||||
data-label-submit="Search" aria-controls="chrnx-search-panel"
|
||||
aria-expanded="true">Search</button>
|
||||
</form>
|
||||
`;
|
||||
}
|
||||
@@ -24,11 +27,15 @@ describe( 'progressive header search', () => {
|
||||
const form = document.querySelector( 'form' );
|
||||
const input = document.querySelector( 'input' );
|
||||
const button = document.querySelector( 'button' );
|
||||
const panel = document.querySelector( '[data-chrnx-search-panel]' );
|
||||
expect( panel.hidden ).toBe( true );
|
||||
expect( button.getAttribute( 'aria-expanded' ) ).toBe( 'false' );
|
||||
const event = new Event( 'submit', { bubbles: true, cancelable: true } );
|
||||
form.dispatchEvent( event );
|
||||
expect( event.defaultPrevented ).toBe( true );
|
||||
expect( form.dataset.expanded ).toBe( 'true' );
|
||||
expect( input.hidden ).toBe( false );
|
||||
expect( panel.hidden ).toBe( false );
|
||||
expect( button.getAttribute( 'aria-expanded' ) ).toBe( 'true' );
|
||||
expect( document.activeElement ).toBe( input );
|
||||
expect( button.getAttribute( 'aria-label' ) ).toBe( 'Search' );
|
||||
} );
|
||||
@@ -52,10 +59,12 @@ describe( 'progressive header search', () => {
|
||||
const form = document.querySelector( 'form' );
|
||||
const input = document.querySelector( 'input' );
|
||||
const button = document.querySelector( 'button' );
|
||||
const panel = document.querySelector( '[data-chrnx-search-panel]' );
|
||||
form.dispatchEvent( new Event( 'submit', { bubbles: true, cancelable: true } ) );
|
||||
input.dispatchEvent( new window.KeyboardEvent( 'keydown', { key: 'Escape', bubbles: true } ) );
|
||||
expect( form.dataset.expanded ).toBe( 'false' );
|
||||
expect( input.hidden ).toBe( true );
|
||||
expect( panel.hidden ).toBe( true );
|
||||
expect( button.getAttribute( 'aria-expanded' ) ).toBe( 'false' );
|
||||
expect( document.activeElement ).toBe( button );
|
||||
expect( button.getAttribute( 'aria-label' ) ).toBe( 'Open search' );
|
||||
} );
|
||||
|
||||
Reference in new issue
Block a user