Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add the <search> element #7320

Merged
merged 2 commits into from
Mar 24, 2023
Merged

Add the <search> element #7320

merged 2 commits into from
Mar 24, 2023

Conversation

domenic
Copy link
Member

@domenic domenic commented Nov 8, 2021

Closes #5811.

Mini-explainer

This new element allows authors to express the semantics of "a set of form controls or other content related to performing a search or filtering operation".

This is an especially desired semantic because it is something that an ARIA landmark role exists for (role="search"), but today can only be expressed with ARIA. Adding a dedicated element allows authors to follow the first rule of ARIA (~ "don't use ARIA if you can avoid it") and is part of the co-evolution process between ARIA and HTML.

Please see the pull request preview for web-developer focused details on usage and examples.

Some notable design choices:

  • The name. We were initially a bit concerned that developers would think that this was a type of search input, not a search container. Although we briefly discussed alternative names to combat this like <searcharea>, <searchform>, <searchgroup>, <searchset>, they each had problems, and a quick Twitter poll helped seal the deal that developers would expect and prefer the name <search>. (In addition to other developers chiming in with reasoning on the thread.) See the comments starting at Consider creating an HTML search element #5811 (comment) for more details.

  • Like other "block-level" elements, <search> closes any open <p> tags. This ensures an easy transition path from <div role="search"> to <search> and maintains platform consistency.

  • Like other "block-level" elements, the user-agent stylesheet for <search> makes it display: block and unicode-bidi: isolate.

  • For conformance-checker purposes, the element is categorized as flow content and palpable content, but not sectioning content. (In this respect, it is categorized similarly to <main>, but not like <nav> or <aside>.) We are not sure whether this is ideal, partly because due to Suggest adding a warning about outline algorithm #83 sectioning content is a tricky category. But we believe that the main effect of sectioning content is to encourage authors to add headings inside the sections, which is perhaps not the right default here?

  • This element is a straightforward replacement for <div role="search">, and does not come with any additional functionality (such as having form-submission capabilities). Instead it can be combined with other primitives such as <form>, or JavaScript, etc. You can see extensive discussion of this in Consider creating an HTML search element #5811. The reasons for disfavoring more complex solutions are implementer-expressed considerations about complexity and compat risk, as well as web-developer and accessibility community preferences.

Credits

The element description and examples is almost entirely written by @scottaohara, although I made a few edits and rearrangements.

PR merge checklist

(See WHATWG Working Mode: Changes for more details.)


/dom.html ( diff )
/grouping-content.html ( diff )
/index.html ( diff )
/indices.html ( diff )
/parsing.html ( diff )
/rendering.html ( diff )
/syntax.html ( diff )

@domenic domenic added addition/proposal New features or enhancements do not merge yet Pull request must not be merged per rationale in comment impacts documentation Used by documentation communities, such as MDN, to track changes that impact documentation labels Nov 8, 2021
@KittyGiraudel
Copy link

KittyGiraudel commented Nov 9, 2021

Hiiii! ✨ That’s pretty neat—I had no idea this was in the work.

I have a couple questions/comments if that’s okay?

  • Is the use of <search> limited to one per page, or can it be used multiple times? The document doesn’t appear to explicitly clarify this.
  • In the case it can in fact be used several times on a page, how would a given occurrence be differentiated from another for assistive technologies (e.g. landmark listing)?

I guess where I’m coming at is that if it is not unique per page (unlike <main>), maybe it should be a sectioning element so that it can essentially be labelled? That’s generally what’s recommended for <nav> elements, where we’d encourage authors to label them properly so multiple navigations can be differentiated from one another.

Unless I’m missing something? :)

@scottaohara
Copy link
Collaborator

thanks for the comment, @KittyGiraudel. There is definitely guidance that can be added to flesh that out some more.

to quickly answer your questions though:

  1. this element is different than <main>, as there can be more than one per document - though as with any landmark that exposes a landmark role, they should be used with purpose. Will draft up some guidance for this.
  2. With native HTML alone, the title attribute would be used to name the element, as there is no other mechanism available at this time without using ARIA.

@domenic
Copy link
Member Author

domenic commented Nov 9, 2021

I do think the comparison with <nav> is worth digging into though. I guess you can have multiple of each per page, and the question is whether we want to encourage <hN> children inside of them.

IIUC, for both <nav> and <search>, per https://w3c.github.io/html-aam/#section-elements-and-grouping-content-elements-not-listed-elsewhere you can only use title="" or ARIA. Using a <hN> will not suffice to give an accessible name.

Not sure where that leaves us...

@scottaohara
Copy link
Collaborator

have some additional content to add. my initial PR got messed up though, so will give it a shot again later.

Copy link

@Kaleidea Kaleidea left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(edited by @domenic) Off-topic: see discussion in #5811 (comment) I'd like to thank the editors' work on this proposal and their long-term service towards the web developer community. However, [there is a viable alternative](https://github.com//issues/7323) with improved API ergonomy that better serves developer needs, but wasn't considered. In my opinion ignoring that alternative would be a missed opportunity to improve developer satisfaction and the quality of the World Wide Web.

Opposition

Since this is a low priority feature, there is no need to rush to a solution without giving due consideration for all needs and use-cases, therefore I have to oppose this proposal in this form at this time. Due to discourtesy and the rejection to discuss the alternative of aliasing <form>, I've appealed the decisions to the Steering Group. I hope their guidance will help achieve an outcome that serves more developers' needs.

source Outdated Show resolved Hide resolved
@domenic domenic added the agenda+ To be discussed at a triage meeting label Nov 15, 2021
@zcorpan
Copy link
Member

zcorpan commented Nov 15, 2021

cc @whatwg/html-parser for

Does not close <p> elements, i.e. does not require any parser changes. (Note: this is unlike <main>.) Implementers are generally not excited about parser changes and I don't think auto-closing <p> elements is a big enough win.

Is it OK for new "block" elements to not close <p>?

If it is, maybe we need to reconsider if </p> should be optional, since it will be very confusing to not be able to omit it inside or before <search>.

@artalar
Copy link

artalar commented Nov 18, 2021

It would be nice to have main property for this element, which indicate to browser that it should be used as a main search for site when user click ctrl(command)+F. It may dramatically improve user search experience for sites with virtual lists.

@Kaleidea
Copy link

Kaleidea commented Nov 25, 2021

It would be nice to have main property for this element, which indicate to browser that it should be used as a main search for site when user click ctrl(command)+F. It may dramatically improve user search experience for sites with virtual lists.

@artalar I think that would be a separate proposal to hook and redirect the browser's CtrlCmd-F search functionality to the marked search element on the page, it's more than what this proposal aims for. Currently CtrlCmd-F search can be hooked with JS.

@Kaleidea
Copy link

cc @whatwg/html-parser for

Does not close <p> elements, i.e. does not require any parser changes. (Note: this is unlike <main>.) Implementers are generally not excited about parser changes and I don't think auto-closing <p> elements is a big enough win.

Is it OK for new "block" elements to not close <p>?

@zcorpan Adding the element requires 2 changes to the WebKit & Blink parsers in the HTMLTreeBuilder class:
commit.

Making it a paragraph closing element requires 2 more trivial changes:
commit.

OTOH if <search> is not closing paragraphs then the trivial transformation from <div role=search> -> <search> will break in cases like:
<p> Paragraph ends here. <div role=search> ... </div>
will not be equivalent to:
<p> Paragraph ends here. <search> ... </search>
Such inconsistency can be a difficulty for dev tool developers (eg. automated migration to <search>) and a footgun for web developers.

Note: I don't like the optional </p> either, but changing it would break the web.

@zcorpan
Copy link
Member

zcorpan commented Nov 25, 2021

OTOH if <search> is not closing paragraphs then the trivial transformation from <div role=search> -> <search> will break in cases like: <p> Paragraph ends here. <div role=search> ... </div> will not be equivalent to: <p> Paragraph ends here. <search> ... </search> Such inconsistency can be a difficulty for dev tool developers (eg. automated migration to <search>) and a footgun for web developers.

I agree, and it will be a persistent footgun. I think it's probably better in the long run to change the parser when adding a new block element.

@domenic
Copy link
Member Author

domenic commented Jan 25, 2022

@hsivonen any updates on your thoughts about whether it's OK to have <search> close <p> tags?

@hsivonen
Copy link
Member

hsivonen commented Feb 4, 2022

If a <search> element is added, making it close <p> is probably the right thing to do. I'm not convinced that adding the <search> element is worthwhile, since it doesn't add expressiveness but mainly addresses a principled concern that all of ARIA should be ported to HTML in non-ARIA form, but I don't know enough about the use cases to argue strongly in favor or agains..

@zcorpan
Copy link
Member

zcorpan commented Mar 23, 2023

Also rendering tests.

web-platform-tests/wpt#39163

@zcorpan
Copy link
Member

zcorpan commented Mar 23, 2023

OK I think this is ready now, modulo review of the rendering tests.

@annevk annevk added the do not merge yet Pull request must not be merged per rationale in comment label Mar 23, 2023
@annevk
Copy link
Member

annevk commented Mar 23, 2023

I suggest we let @domenic do the honors since it's been well over a year since we started all this and he might well have some other relevant insights.

@domenic
Copy link
Member Author

domenic commented Mar 24, 2023

Thank you all for helping push this over the finish line!! I think it's ready to merge. I'll also file an MDN bug.

@domenic domenic removed the do not merge yet Pull request must not be merged per rationale in comment label Mar 24, 2023
@domenic domenic merged commit c598ff0 into main Mar 24, 2023
@domenic domenic deleted the search-element branch March 24, 2023 01:54
domenic pushed a commit to web-platform-tests/wpt that referenced this pull request Mar 24, 2023
wooorm added a commit to wooorm/commonmark-spec that referenced this pull request Mar 24, 2023
jgm pushed a commit to commonmark/commonmark-spec that referenced this pull request Mar 25, 2023
marcoscaceres pushed a commit to web-platform-tests/wpt that referenced this pull request Mar 28, 2023
cookiecrook pushed a commit to cookiecrook/wpt that referenced this pull request Mar 29, 2023
cookiecrook pushed a commit to cookiecrook/wpt that referenced this pull request Apr 8, 2023
moz-v2v-gh pushed a commit to mozilla/gecko-dev that referenced this pull request Apr 13, 2023
…ment, a=testonly

Automatic update from web-platform-tests
Add rendering tests for the <search> element

See whatwg/html#7320

--

wpt-commits: c49cf0a72fd7278b6f6da0fd19ed37a3d9262bec
wpt-pr: 39163
webkit-commit-queue pushed a commit to annevk/WebKit that referenced this pull request May 16, 2023
https://bugs.webkit.org/show_bug.cgi?id=254327
rdar://107175819

Reviewed by Tim Nguyen.

Adds the new HTML search element as specified in
whatwg/html#7320. Given the code changes are
minimal there is no preferences guard.

It doesn't address the unicode-bidi rendering requirements as they are
not addressed for many elements in WebKit:
https://bugs.webkit.org/show_bug.cgi?id=256829

This change also syncs most of WPT html/syntax/parsing and adds
accessibility test coverage for the main element.

* LayoutTests/accessibility/roles-exposed.html:
* LayoutTests/imported/w3c/web-platform-tests/html/rendering/non-replaced-elements/flow-content-0/search-styles-expected.txt: Added.
* LayoutTests/imported/w3c/web-platform-tests/html/rendering/non-replaced-elements/flow-content-0/search-styles-iso-8859-8-expected.txt: Added.
* LayoutTests/imported/w3c/web-platform-tests/html/rendering/non-replaced-elements/flow-content-0/search-styles-iso-8859-8.html: Added.
* LayoutTests/imported/w3c/web-platform-tests/html/rendering/non-replaced-elements/flow-content-0/search-styles.html: Added.
* LayoutTests/imported/w3c/web-platform-tests/html/rendering/non-replaced-elements/flow-content-0/w3c-import.log:
* LayoutTests/imported/w3c/web-platform-tests/html/syntax/parsing/Element.getElementsByTagName-foreign-02.html:
* LayoutTests/imported/w3c/web-platform-tests/html/syntax/parsing/README:
* LayoutTests/imported/w3c/web-platform-tests/html/syntax/parsing/html-integration-point.html:
* LayoutTests/imported/w3c/web-platform-tests/html/syntax/parsing/html5lib_innerHTML_template-expected.txt: Added.
* LayoutTests/imported/w3c/web-platform-tests/html/syntax/parsing/html5lib_innerHTML_template.html: Added.
* LayoutTests/imported/w3c/web-platform-tests/html/syntax/parsing/html5lib_innerHTML_webkit02-expected.txt:
* LayoutTests/imported/w3c/web-platform-tests/html/syntax/parsing/html5lib_innerHTML_webkit02.html:
* LayoutTests/imported/w3c/web-platform-tests/html/syntax/parsing/html5lib_search-element.html: Added.
* LayoutTests/imported/w3c/web-platform-tests/html/syntax/parsing/html5lib_search-element_run_type=uri-expected.txt: Added.
* LayoutTests/imported/w3c/web-platform-tests/html/syntax/parsing/html5lib_search-element_run_type=write-expected.txt: Added.
* LayoutTests/imported/w3c/web-platform-tests/html/syntax/parsing/html5lib_search-element_run_type=write_single-expected.txt: Added.
* LayoutTests/imported/w3c/web-platform-tests/html/syntax/parsing/html5lib_tables01.html:
* LayoutTests/imported/w3c/web-platform-tests/html/syntax/parsing/html5lib_tables01_run_type=uri-expected.txt:
* LayoutTests/imported/w3c/web-platform-tests/html/syntax/parsing/html5lib_tables01_run_type=write-expected.txt:
* LayoutTests/imported/w3c/web-platform-tests/html/syntax/parsing/html5lib_tables01_run_type=write_single-expected.txt:
* LayoutTests/imported/w3c/web-platform-tests/html/syntax/parsing/html5lib_template.html:
* LayoutTests/imported/w3c/web-platform-tests/html/syntax/parsing/html5lib_template_run_type=uri-expected.txt:
* LayoutTests/imported/w3c/web-platform-tests/html/syntax/parsing/html5lib_template_run_type=write-expected.txt:
* LayoutTests/imported/w3c/web-platform-tests/html/syntax/parsing/html5lib_template_run_type=write_single-expected.txt:
* LayoutTests/imported/w3c/web-platform-tests/html/syntax/parsing/html5lib_tests20.html:
* LayoutTests/imported/w3c/web-platform-tests/html/syntax/parsing/html5lib_tests20_run_type=uri-expected.txt:
* LayoutTests/imported/w3c/web-platform-tests/html/syntax/parsing/html5lib_tests20_run_type=write-expected.txt:
* LayoutTests/imported/w3c/web-platform-tests/html/syntax/parsing/html5lib_tests20_run_type=write_single-expected.txt:
* LayoutTests/imported/w3c/web-platform-tests/html/syntax/parsing/html5lib_webkit01.html:
* LayoutTests/imported/w3c/web-platform-tests/html/syntax/parsing/html5lib_webkit01_run_type=uri-expected.txt:
* LayoutTests/imported/w3c/web-platform-tests/html/syntax/parsing/html5lib_webkit01_run_type=write-expected.txt:
* LayoutTests/imported/w3c/web-platform-tests/html/syntax/parsing/html5lib_webkit01_run_type=write_single-expected.txt:
* LayoutTests/imported/w3c/web-platform-tests/html/syntax/parsing/html5lib_webkit02.html:
* LayoutTests/imported/w3c/web-platform-tests/html/syntax/parsing/html5lib_webkit02_run_type=uri-expected.txt:
* LayoutTests/imported/w3c/web-platform-tests/html/syntax/parsing/html5lib_webkit02_run_type=write-expected.txt:
* LayoutTests/imported/w3c/web-platform-tests/html/syntax/parsing/html5lib_webkit02_run_type=write_single-expected.txt:
* LayoutTests/imported/w3c/web-platform-tests/html/syntax/parsing/math-parse03.html:
* LayoutTests/imported/w3c/web-platform-tests/html/syntax/parsing/test.js:
(test_fragment):
(convert_innerHTML):
* LayoutTests/imported/w3c/web-platform-tests/html/syntax/parsing/w3c-import.log:
* LayoutTests/inspector/css/shadow-scoped-style-expected.txt:
* LayoutTests/platform/mac-wk1/accessibility/roles-exposed-expected.txt:
* LayoutTests/platform/mac-wk2/accessibility/roles-exposed-expected.txt:
* LayoutTests/tests-options.json:
* Source/WebCore/accessibility/AccessibilityNodeObject.cpp:
(WebCore::AccessibilityNodeObject::determineAccessibilityRoleFromNode const):
* Source/WebCore/css/html.css:
(address, article, aside, div, footer, header, hgroup, main, nav, search, section):
(address, article, aside, div, footer, header, hgroup, main, nav, section): Deleted.
* Source/WebCore/html/HTMLTagNames.in:
* Source/WebCore/html/parser/HTMLTreeBuilder.cpp:
(WebCore::HTMLTreeBuilder::processStartTagForInBody):
(WebCore::HTMLTreeBuilder::processEndTagForInBody):

Canonical link: https://commits.webkit.org/264110@main
aarongable pushed a commit to chromium/chromium that referenced this pull request Aug 16, 2023
This was added to the HTML spec here:
whatwg/html#7320

I mostly based on this on the webkit patch:
WebKit/WebKit#13887

Bug: 1294294
Change-Id: Ia34836f7e5172d862a3a1f24f1e5cbcbb10e6a55
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4767222
Reviewed-by: Mason Freed <masonf@chromium.org>
Commit-Queue: Joey Arhar <jarhar@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1184358}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
addition/proposal New features or enhancements impacts documentation Used by documentation communities, such as MDN, to track changes that impact documentation topic: parser
Development

Successfully merging this pull request may close these issues.

Consider creating an HTML search element
9 participants