Bug 1655503 - Remove clear search button from a11y tree. r=accessibility-frontend-reviewers,desktop-theme-reviewers,emilio,smaug

The clear search button is not exposed to assistive technologies
and is not able to receive focus. This is to ensure a positive user
experience when navigating through the search input.

Move prefs to default section in test/forms/chrome.toml

Differential Revision: https://phabricator.services.mozilla.com/D240396
This commit is contained in:
Tim Giles
2025-05-01 15:11:51 +00:00
committed by tgiles@mozilla.com
parent f2ef109b4b
commit cad8dc1154
4 changed files with 100 additions and 2 deletions

View File

@@ -3947,7 +3947,6 @@ nsresult HTMLInputElement::PostHandleEvent(EventChainPostVisitor& aVisitor) {
aVisitor.mEventStatus = nsEventStatus_eConsumeNoDefault;
}
}
} break; // eKeyPress
case eMouseDown:

View File

@@ -1,6 +1,9 @@
[DEFAULT]
support-files = ["submit_invalid_file.sjs"]
prefs = ["layout.forms.input-type-search.enabled=true"]
["test_autocompleteinfo.html"]
["test_input_search.html"]
["test_submit_invalid_file.html"]

View File

@@ -0,0 +1,94 @@
<!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 children = SpecialPowers.InspectorUtils.getChildrenForNode(input, true, false);
let clearButton = children.find(e => e.localName == "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>

View File

@@ -47,7 +47,9 @@ nsresult nsSearchControlFrame::CreateAnonymousContent(
// Create the ::-moz-search-clear-button pseudo-element:
mButton = MakeAnonElement(PseudoStyleType::mozSearchClearButton, nullptr,
nsGkAtoms::button);
mButton->SetAttr(kNameSpaceID_None, nsGkAtoms::tabindex, u"-1"_ns, false);
mButton->SetAttr(kNameSpaceID_None, nsGkAtoms::aria_hidden, u"true"_ns,
false);
aElements.AppendElement(mButton);
return NS_OK;