Search block: Render in the semantic <search> element#78485
Search block: Render in the semantic <search> element#78485adamsilverstein wants to merge 1 commit into
Conversation
Wrap the rendered search block in the HTML `<search>` landmark element and drop the now-redundant `role="search"` attribute on the inner `<form>`. The `<search>` element is in Baseline and carries an implicit ARIA landmark role of `search`, providing the same semantics natively. Keeping `role="search"` on the form would create nested search landmarks, so it is removed. The block wrapper attributes and Interactivity API directives are applied to the `<search>` element so it remains the styled block root. This preserves block alignment (wide/full), spacing, the HTML anchor, and the expandable-searchfield state class, all of which rely on those classes living on the outermost element. Internal flex layout is unaffected because it targets descendant `wp-block-search__*` classes.
|
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message. To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
|
Per WordPress/wordpress-develop#11913 (comment):
|
|
Flaky tests detected in 1797583. 🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/26200391361
|
What
Render the
core/searchblock in the native HTML<search>landmark element instead of<form role="search">.Why
<search>is now Baseline (Chrome 118+, Firefox 118+, Safari 17+, Edge 118+) and has an implicit ARIA landmark role ofsearch. Using it expresses the search landmark with native semantics rather than a manualroleattribute.The
role="search"attribute is dropped from the<form>because keeping it alongside the<search>wrapper would produce nestedsearchlandmarks, which assistive technology may announce twice or report as a structural error.Implementation notes
The block wrapper attributes (
get_block_wrapper_attributes()) and Interactivity API directives are applied to the new<search>element, making it the styled block root. This is important for correctness:alignwide/alignfull) and constrained-layout centering only apply when the alignment class is on the layout container's direct child. Leaving the wrapper attributes on the inner<form>would break wide/full alignment.wp-block-search__searchfield-hiddenis toggled by adata-wp-class--*directive and is matched by the compound selector.wp-block-search.wp-block-search__button-only.wp-block-search__searchfield-hidden. Because the directives move to<search>together with the block classes, all three classes stay on the same element and the selector keeps matching.wp-block-search__inside-wrapper/wp-block-search__inputclasses, which remain reachable through the extra<form>layer.The Interactivity handlers (
handleSearchKeydown,handleSearchFocusout) operate on the directive's element (getElement().ref) usingref.querySelector(...)/ref.contains(...); since<search>now hosts the region and contains the whole form, these continue to work.The editor (
edit.js) root is intentionally left as<div { ...blockProps }>. This is a dynamic (server-rendered) block with nosave.js, so the editor DOM does not need to match the rendered output, and editor alignment already works viablockPropson that outer<div>. Adding a<search>landmark inside the editor canvas is out of scope.WordPress Core
The Core-maintained
get_search_form()function and the bundled classic-themesearchform.phptemplates get the same treatment in wordpress-develop#11913. This block change flows into Core via the regular block package sync. A Trac ticket tracks the overall effort.Testing instructions
<search class="wp-block-search …"><form method="get">…</form></search>with norole="search".<search>element.Accessibility
searchlandmark via<search>; no more manualrole="search".