Source code

Revision control

Copy as Markdown

Other Tools

Test Info: Warnings

<!DOCTYPE HTML>
<html>
<head>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/resources/testdriver.js"></script>
<script src="/resources/testdriver-vendor.js"></script>
<script src="/resources/testdriver-actions.js"></script>
<script src="/wai-aria/scripts/aria-utils.js"></script>
</head>
<body>
<button id="toggle-button-1" popovertarget="x-popover-1">Toggle the popover</button>
<x-popover-1 id="x-popover-1">
<template shadowrootmode="open" shadowrootreferencetarget="popover">
<div id="popover" popover>Popover content inside shadow root</div>
</template>
</x-popover-1>
<button id="toggle-button-2" popovertarget="x-popover-2">Toggle the popover</button>
<x-popover-2 id="x-popover-2"></x-popover-2>
<script>
const customPopover2 = document.querySelector('x-popover-2');
customPopover2.attachShadow({ mode: 'open', referenceTarget: 'popover' });
customPopover2.shadowRoot.innerHTML = '<div id="popover" popover>Popover content inside shadow root</div>';
</script>
<button id="toggle-button-3">Toggle the popover</button>
<x-popover-3 id="x-popover-3">
<template shadowrootmode="open" shadowrootreferencetarget="popover">
<div id="popover" popover>Popover content inside shadow root</div>
</template>
</x-popover-3>
<script>
function testPopoverTarget(popoverId, buttonId, name) {
test(function () {
const xPopover = document.getElementById(popoverId);
const popover = xPopover.shadowRoot.getElementById("popover");
let showCount = 0;
popover.addEventListener('beforetoggle', (e) => {
if (e.newState === "open")
++showCount;
});
const toggleButton = document.getElementById(buttonId);
toggleButton.click();
assert_equals(showCount, 1, "showCount");
}, name);
}
testPopoverTarget('x-popover-1', 'toggle-button-1', "Shadow root reference target works with popovertarget attribute.");
testPopoverTarget('x-popover-2', 'toggle-button-2', "Shadow root reference target works with popovertarget attribute via options.");
document.getElementById('toggle-button-3').popoverTargetElement = document.getElementById('x-popover-3');
testPopoverTarget('x-popover-3', 'toggle-button-3', "Shadow root reference target works with .popoverTargetElement property.");
</script>
</body>
</html>