Bug 1599415 trigger `focus` when details summary element is clicked r=TYLin,smaug

Differential Revision: https://phabricator.services.mozilla.com/D72603
This commit is contained in:
Keith Cirkel 2020-05-05 21:09:42 +00:00
Родитель fcc5266a9e
Коммит 3b9cc2e96b
2 изменённых файлов: 40 добавлений и 8 удалений

Просмотреть файл

@ -106,15 +106,8 @@ bool HTMLSummaryElement::IsHTMLFocusable(bool aWithMouse, bool* aIsFocusable,
return disallowOverridingFocusability;
}
#ifdef XP_MACOSX
// The parent does not have strong opinion about the focusability of this main
// summary element, but we'd like to override it when mouse clicking on Mac OS
// like other form elements.
*aIsFocusable = !aWithMouse || nsFocusManager::sMouseFocusesFormControl;
#else
// The main summary element is focusable on other platforms.
// The main summary element is focusable.
*aIsFocusable = true;
#endif
// Give a chance to allow the subclass to override aIsFocusable.
return false;

Просмотреть файл

@ -0,0 +1,39 @@
<!DOCTYPE html>
<meta charset="utf-8">
<title>summary element: click behavior</title>
<link rel="author" title="Mu-An Chiou" href="mailto:hi@muan.co">
<link rel="help" href="https://html.spec.whatwg.org/multipage/#the-summary-element">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/resources/testdriver.js"></script>
<script src="/resources/testdriver-actions.js"></script>
<script src="/resources/testdriver-vendor.js"></script>
<body>
<div id="log"></div>
<details id="details">
<summary id="summary">Summary</summary>
<p>Contents</p>
</details>
</body>
<script>
// This behavior is not specified by HTML standards, but setting focus on
// clicked summary tag is the current behavior on Chrome, Safari, and Firefox
// in both Windows and macOS.
async_test(t => {
const details = document.getElementById("details")
const summary = document.getElementById("summary")
t.step_timeout(() => {
details.addEventListener("toggle", t.step_func_done(function () {
assert_equals(details.open, true, "details should be open")
assert_equals(document.activeElement, summary, "active element should be summary")
t.done()
}))
new test_driver.click(summary)
}, 200)
}, "clicking on summary should open details and set focus on summary")
</script>