1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134
|
<!DOCTYPE html>
<meta charset="utf-8">
<title>summary element: activation behavior</title>
<link rel="author" title="Domenic Denicola" href="mailto:d@domenic.me">
<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>
<div id="log"></div>
<details id="happy-path-starts-closed">
<summary id="happy-path-starts-closed-summary">Summary</summary>
<p>Contents</p>
</details>
<details id="happy-path-starts-open" open>
<summary id="happy-path-starts-open-summary">Summary</summary>
<p>Contents</p>
</details>
<details id="details-not-being-rendered" style="display: none">
<summary id="details-not-being-rendered-summary">Summary</summary>
<p>Contents</p>
</details>
<details id="summary-not-being-rendered">
<summary id="summary-not-being-rendered-summary" style="display: none">Summary</summary>
<p>Contents</p>
</details>
<details id="has-preceding-element">
<span></span>
<summary id="has-preceding-element-summary">Summary</summary>
<p>Contents</p>
</details>
<details id="has-preceding-summary">
<summary>Summary 1</summary>
<summary id="has-preceding-summary-summary">Summary 2</summary>
<p>Contents</p>
</details>
<details id="has-preceding-summary-descendant">
<span><summary>Summary 1</summary></span>
<summary id="has-preceding-summary-descendant-summary">Summary 2</summary>
<p>Contents</p>
</details>
<details id="summary-nested">
<span><summary id="summary-nested-summary">Summary</summary></span>
<p>Contents</p>
</details>
<details id="toggle-tester">
<summary>Summary</summary>
<p>Contents</p>
</details>
<script>
"use strict";
testSummary(
"happy-path-starts-closed", false, true,
"Should open a closed details if all conditions are met"
);
testSummary(
"happy-path-starts-open", true, false,
"Should close an open details if all conditions are met"
);
testSummary(
"details-not-being-rendered", false, true,
"Should open a closed details even if the details is not being rendered"
);
testSummary(
"summary-not-being-rendered", false, true,
"Should open a closed details even if the summary is not being rendered"
);
testSummary(
"has-preceding-element", false, true,
"Should open a closed details if a span element precedes the summary"
);
testSummary(
"has-preceding-summary", false, false,
"Should stay closed if another summary element precedes the summary"
);
testSummary(
"has-preceding-summary-descendant", false, true,
"Should open a closed details if another summary element *nested inside a span* precedes the summary"
);
testSummary(
"summary-nested", false, false,
"Should stay closed if the summary element is nested inside a span element"
);
async_test(t => {
const details = document.getElementById("toggle-tester");
const summary = details.firstElementChild;
let timesToggleFired = 0;
details.addEventListener("toggle", t.step_func(() => {
++timesToggleFired;
}));
t.step_timeout(() => {
assert_equals(timesToggleFired, 1, "Expected toggle to fire exactly once");
t.done();
}, 200);
summary.click();
summary.click();
summary.click();
summary.click();
Promise.resolve().then(() => summary.click());
}, "toggle events should be coalesced even when using the activation behavior of a summary");
function testSummary(detailsId, expectedBefore, expectedAfter, name) {
test(() => {
const details = document.getElementById(detailsId);
const summary = document.getElementById(detailsId + "-summary");
assert_equals(details.open, expectedBefore, "Before activation: expected open to be " + expectedBefore);
summary.click();
assert_equals(details.open, expectedAfter, "After activation: expected open to be " + expectedAfter);
}, name);
}
</script>
|