Skip to content

Commit 010b43b

Browse files
dizhang168chromium-wpt-export-bot
authored andcommitted
Fix ListedElement is focusable pre-check for host with delegatesFocus
The function calls are as follow: HTMLFormElement::reportValidity() HTMLFormElement::ValidateInteractively() ListedElement::ValidationAnchorOrHostIsFocusable() This means a custom element inside a form element will call the above functions to check validity of the form input and show the validation message accordingly. In ListedElement::ValidationAnchorOrHostIsFocusable, the function checks whether the anchor element or the host is focusable. If the anchor is specified, it checks the correct element. If not, it will check the host. However, in the case of a custom element with delegatesFocus, we should not check the host, but instead check its focusable area. Change-Id: Ie331a17c3622ac949ce70cfcacbf035efd73ae89 Fixed: 389587444 Bug: 40726105 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6174381 Reviewed-by: Joey Arhar <[email protected]> Commit-Queue: Di Zhang <[email protected]> Cr-Commit-Position: refs/heads/main@{#1413006}
1 parent 344a03b commit 010b43b

File tree

2 files changed

+63
-0
lines changed

2 files changed

+63
-0
lines changed
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<!DOCTYPE html>
2+
<title>Custom element with delegatesFocus in Form should show validation message on focus delegated element</title>
3+
<link rel=help href=https://html.spec.whatwg.org/C/#report-validity-steps>
4+
5+
<form>
6+
<input-custom-element></input-custom-element>
7+
</form>
8+
9+
<script>
10+
class InputCustomElement extends HTMLElement {
11+
constructor() {
12+
super();
13+
14+
this.attachShadow({
15+
mode: "open",
16+
delegatesFocus: true
17+
});
18+
this.shadowRoot.innerHTML = '<input>';
19+
this.elementInternals = this.attachInternals();
20+
this.elementInternals.setValidity({valueMissing: true}, 'value missing');
21+
}
22+
23+
static get formAssociated() {
24+
return true;
25+
}
26+
}
27+
28+
customElements.define("input-custom-element", InputCustomElement);
29+
30+
</script>
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<!DOCTYPE html>
2+
<title>Custom element with delegatesFocus in Form should show validation message on focus delegated element</title>
3+
<link rel=mismatch href=ElementInternals-reportValidity-delegatesFocus-notref.html>
4+
<link rel=help href=https://html.spec.whatwg.org/C/#report-validity-steps>
5+
6+
<form>
7+
<input-custom-element></input-custom-element>
8+
</form>
9+
10+
<script>
11+
class InputCustomElement extends HTMLElement {
12+
constructor() {
13+
super();
14+
15+
this.attachShadow({
16+
mode: "open",
17+
delegatesFocus: true
18+
});
19+
this.shadowRoot.innerHTML = '<input>';
20+
this.elementInternals = this.attachInternals();
21+
this.elementInternals.setValidity({valueMissing: true}, 'value missing');
22+
}
23+
24+
static get formAssociated() {
25+
return true;
26+
}
27+
}
28+
29+
customElements.define("input-custom-element", InputCustomElement);
30+
31+
document.querySelector("form").reportValidity();
32+
33+
</script>

0 commit comments

Comments
 (0)