fix: preserve progressive CHRNX search

This commit is contained in:
chrnx committed 2026-08-11 19:45:14 -05:00
1 parent 55166c6d2a
commit e7956a1496
7 files changed
+66 -31

No files matched your search

+15 -6
View File
@@ -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' );
} );