Files
sousa-gecko/dom/html/test/forms/test_input_search.html
T
Emilio Cobos Álvarez 34b249c82e Bug 2031757 - Rejigger text input / textarea rendering to make field-sizing easier. r=layout-reviewers,devtools-reviewers,fxview-reviewers,firefox-style-system-reviewers,ochameau,jsudiaman,dshin
This also should fix bug 1881942 (placeholder is now scrollable
alongside the textarea).

This makes nsTextControlFrame a subclass of ScrollContainerFrame (with
an inner block), and tweaks layout to match.

It lays out the inner content using block layout and align-content,
rather than bespoke reflow primitives. This makes field-sizing trivial
to implement on top.

This is a bit scary, but simpler in most ways. In particular, it needs
to teach ScrollContainerFrame of the button, because that goes outside
the scrollable area, like scrollbars. That said it needs less
special-cases added than those removed, and it should also be faster
(needs less frames to layout an input with placeholder etc), and match
other browsers better.

The general set-up is:

  <text-control-editing-root/>
  <placeholder/>
  <autofill-preview/>

text-control-editing-root is always inline-block and always displayed
(since it's what grabs the focus / shows the caret). If the
autofill-preview or placeholder are displayed, the editing-root is
zero-width and clipped (note that for placeholder that's guaranteed
because placeholder is only shown with an empty value, but
autofill-preview needs it).

placeholder and autofill-preview are hidden via `display` rather than
visibility. This doesn't make a difference with this patch but it
matters for bug 1977176.

Caret painting needs an extra hop to paint atop the placeholder (no
observable behavior change, but worth calling out).

There is one subtle behavior change, which is that single-line inputs
never report scrollable overflow in the block axis. This matches other
browsers (see the tweak in nsBlockFrame's overflow computation) and is
needed to avoid regressing scrollable-overflow-padding-input.html.

The changes in window_composition_text_querycontent.xhtml are needed
because before this patch, the height of the control editing root was
always the height of the whole textarea. The characters you're composing
might legitimately be taller than the line. Bump the line height so that
that doesn't happen in this test.

Differential Revision: https://phabricator.services.mozilla.com/D293666
2026-04-16 17:09:40 +00:00

95 lines
2.8 KiB
HTML

<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<title>Test for &lt;input type='search'&gt; clear search button</title>
<script src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
<script src="chrome://mochikit/content/tests/SimpleTest/EventUtils.js"></script>
<link rel="stylesheet" href="chrome://mochikit/content/tests/SimpleTest/test.css"/>
</head>
<body>
<p id="display"></p>
<div id="content">
<form>
<input type="search" name="search" id="searchInput">
</form>
</div>
<pre id="test">
<script class="testbody" type="application/javascript">
const { BrowserTestUtils } = ChromeUtils.importESModule(
"resource://testing-common/BrowserTestUtils.sys.mjs");
add_task(async function testClearSearchButton() {
let input = document.getElementById("searchInput");
let clearButton = SpecialPowers.getInputButton(input);
isnot(clearButton, null, "Should find the clear button");
is(searchInput.value, "",
"Search input should be blank at the start of test");
ok(!BrowserTestUtils.isVisible(clearButton),
"Clear button is hidden when there is no value in the input");
is(clearButton.getAttribute("tabindex"), "-1", "Clear button should not be focusable");
is(clearButton.getAttribute("aria-hidden"), "true", "Clear button should be hidden from the accessibility tree");
searchInput.value = "abc";
ok(
BrowserTestUtils.isVisible(clearButton),
"Clear button should be visible when text is present"
);
is(
clearButton.getAttribute("tabindex"),
"-1",
"Clear button should not be focusable when visible"
);
is(
clearButton.getAttribute("aria-hidden"),
"true",
"Clear button should be hidden from accessibilty tree when visible"
);
// Clear text input by clicking the clear button
synthesizeMouseAtCenter(clearButton, {});
ok(
!BrowserTestUtils.isVisible(clearButton),
"Clear button should be hidden after clicking the clear button"
);
is(
searchInput.value,
"",
"Search input should be blank after using the clear button"
);
is(
clearButton.getAttribute("tabindex"),
"-1",
"Clear button should not be focusable when hidden again"
);
is(
clearButton.getAttribute("aria-hidden"),
"true",
"Clear button should be hidden from accessibilty tree when button is hidden again"
);
searchInput.value = "foo";
ok(
BrowserTestUtils.isVisible(clearButton),
"Clear button should be visible when text is present"
);
is(
clearButton.getAttribute("tabindex"),
"-1",
"Clear button should not be focusable when visible"
);
is(
clearButton.getAttribute("aria-hidden"),
"true",
"Clear button should be hidden from accessibilty tree when visible"
);
});
</script>
</pre>
</body>
</html>