summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/custom-elements/form-associated/disabled-delegatesFocus.html
diff options
context:
space:
mode:
Diffstat (limited to 'testing/web-platform/tests/custom-elements/form-associated/disabled-delegatesFocus.html')
-rw-r--r--testing/web-platform/tests/custom-elements/form-associated/disabled-delegatesFocus.html56
1 files changed, 56 insertions, 0 deletions
diff --git a/testing/web-platform/tests/custom-elements/form-associated/disabled-delegatesFocus.html b/testing/web-platform/tests/custom-elements/form-associated/disabled-delegatesFocus.html
new file mode 100644
index 0000000000..3f2b765a63
--- /dev/null
+++ b/testing/web-platform/tests/custom-elements/form-associated/disabled-delegatesFocus.html
@@ -0,0 +1,56 @@
+<!DOCTYPE html>
+<meta charset="utf8">
+<title>delegatesFocus on disabled form-associated custom elements</title>
+<link rel="author" href="mailto:avandolder@mozilla.com">
+<script src="/resources/testharness.js"></script>
+<script src="/resources/testharnessreport.js"></script>
+<script>
+ class CustomControl extends HTMLElement {
+ static get formAssociated() {return true;}
+
+ constructor() {
+ super();
+ this.internals = this.attachInternals();
+
+ this.attachShadow({mode: "open", delegatesFocus: true});
+ this.shadowRoot.append(
+ document.querySelector("template").content.cloneNode(true)
+ );
+
+ this.eventFired = false;
+ this.addEventListener("focus", () => this.eventFired = true);
+ }
+ }
+
+ customElements.define("custom-control", CustomControl)
+</script>
+
+<template>
+ <div tabindex=0 id="target">
+ <slot></slot>
+ </div>
+</template>
+
+<form>
+ <custom-control disabled>Text</custom-control>
+</form>
+
+<script>
+ let focusinPropagated = false;
+ let focusoutPropagated = false;
+
+ const form = document.querySelector("form");
+ form.addEventListener("focusin", () => focusinPropagated = true);
+ form.addEventListener("focusout", () => focusoutPropagated = true);
+
+ test(() => {
+ const element = document.querySelector("custom-control");
+ element.focus();
+
+ assert_true(element.eventFired, "Focus event fired on custom control");
+ assert_true(focusinPropagated, "FocusIn event propagated through control");
+
+ element.blur();
+ assert_true(focusoutPropagated, "FocusOut event propagated through control");
+ }, "Focus events fire on disabled form-associated custom elements with delegatesFocus");
+</script>