Refactor ds-search-navbar so the <form> is only rendered when expanded#5612
Draft
bram-atmire wants to merge 1 commit intoDSpace:mainfrom
Draft
Refactor ds-search-navbar so the <form> is only rendered when expanded#5612bram-atmire wants to merge 1 commit intoDSpace:mainfrom
bram-atmire wants to merge 1 commit intoDSpace:mainfrom
Conversation
Pa11y/HTMLCS rule WCAG2AA H32.2 ("This form does not contain a submit
button") fires on every page because the navbar search renders a <form>
even while collapsed, and the icon control inside it is type="button"
(it has to be: in collapsed state its job is to expand the input, not
to submit). Functionally, Enter still submits the search via HTML5
implicit submission on a single-input form, so this is a false positive
in behavioural terms. The rule is, however, pointing at a real semantic
ambiguity: the icon button's role depends on whether the search is
collapsed or expanded.
Restructure the template so:
- when collapsed, only a single <button type="button"> is rendered
(the magnifying-glass toggle). No form is in the DOM.
- when expanded, the full <form> is rendered with <input> and a real
<button type="submit"> as the icon. Enter submits natively; clicking
the icon submits natively.
The icon's role is now unambiguous in each state and Pa11y H32.2 no
longer reports the navbar form. The cypress e2e tests
(`cypress/e2e/search-navbar.cy.ts`) keep working because they query the
icon by `[data-test="header-search-icon"]`, which is set on both the
collapsed-state toggle and the expanded-state submit button.
The expand-on-collapse slide animation defined by `expandSearchInput`
is still applied to the input element while expanded; it is no longer
applied to the entry transition (the form simply appears). A follow-up
can re-introduce a `:enter`/`:leave` slide on the conditional form if
desired.
Fixes DSpace#5603
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
References
Description
Refactor
ds-search-navbarso the<form>is only rendered when the search bar is expanded. Removes the Pa11y H32.2 false positive while keeping all current behavior (Enter submits, clicking the icon submits when expanded, dsClickOutside collapses).Instructions for Reviewers
Background
Pa11y / HTMLCS rule
WCAG2AA.Principle3.Guideline3_2.3_2_2.H32.2("This form does not contain a submit button") fires on every page because the navbar search keeps a<form>in the DOM at all times, and the icon control inside it istype="button"(it has to be - while collapsed its job is to expand the input). Functionally Enter still submits via HTML5 implicit submission, so the audit report is a false positive in behavioral terms - but it points at a real structural ambiguity around the icon button's role.Approach
Rather than suppressing a tool-specific rule, the issue's author (#5603) suggested restructuring so that "when collapsed, there simply is no form (yet)". This PR implements that: the collapsed state renders only the toggle
<button type="button">, and the expanded state renders the full<form>containing<input>and a real<button type="submit">. Other auditing tools that check the same pattern (axe, WAVE, Lighthouse) will benefit equally.List of changes
src/app/search-navbar/search-navbar.component.html- split the collapsed and expanded states into two@ifbranches. Both keep[data-test="header-search-icon"]on their icon button so the existing Cypress e2e tests (cypress/e2e/search-navbar.cy.ts) keep working.src/app/search-navbar/search-navbar.component.ts- injectChangeDetectorRef, callcdr.detectChanges()inexpand()so the@ViewChild('searchInput')reference resolves beforeeditSearch()focuses it (the input only exists after the conditional branch renders). Made the@ViewChildreferences null-safe incollapse()andeditSearch().src/app/search-navbar/search-navbar.component.spec.ts- updated to reflect the new structure: assert the collapsed state renders no<form>, assert the expanded state renders the form with a real submit button, exercise both submit paths (icon click and native Enter viatriggerEventHandler('submit')).Known minor regression
The slide-in animation defined by
expandSearchInputis still applied to the[@toggleAnimation]state on the input while the form is rendered, but the entry transition (collapsed → expanded) is no longer animated (the form simply appears). The slide can be re-introduced via an Angular:enter/:leavetransition on the conditional form in a follow-up PR.How to test
yarn startorpm2 start config/dspace-ui-test.json).<button class="search-toggle">, no<form>element.<input>and<button type="submit">. Focus is in the input./search?query=<query>. Inspect the form's submit button while expanded: it is<button type="submit">.npm run test -- --include='src/app/search-navbar/search-navbar.component.spec.ts'shows 6 specs pass.cypress run --spec cypress/e2e/search-navbar.cy.ts(or the project's standard e2e command) - existing scenarios still pass; selectors are unchanged.ds-search-navbar > formwhile collapsed (the<form>is no longer in the DOM in that state).Checklist
mainbranch of code (unless it is a backport or is fixing an issue specific to an older branch).npm run lintnpm run check-circ-deps)package.json), I've made sure their licenses align with the DSpace BSD License based on the Licensing of Contributions documentation. (n/a)