Lightpanda: the headless browser designed for AI and automation
ensure custom will validate in CSS element internal check
Karl Seguinddfed9621f04
diff --git a/src/browser/tests/custom_elements/element_internals.html b/src/browser/tests/custom_elements/element_internals.htmlindex d15907433..e0b638985 100644--- a/src/browser/tests/custom_elements/element_internals.html+++ b/src/browser/tests/custom_elements/element_internals.html@@ -211,6 +211,20 @@const datalist = document.createElement('datalist');datalist.appendChild(control);testing.expectFalse(control.i.willValidate);++ // barred without ever attaching internals+ customElements.define('ei-bare', class extends HTMLElement {+ static formAssociated = true;+ });+ const bare = document.createElement('ei-bare');+ testing.expectTrue(bare.matches(':valid'));+ bare.setAttribute('disabled', '');+ testing.expectFalse(bare.matches(':valid'));+ testing.expectFalse(bare.matches(':invalid'));+ bare.removeAttribute('disabled');+ bare.setAttribute('readonly', '');+ testing.expectFalse(bare.matches(':valid'));+ testing.expectFalse(bare.matches(':invalid'));}</script>diff --git a/src/browser/webapi/ElementInternals.zig b/src/browser/webapi/ElementInternals.zigindex 879d080cd..01d9a78bb 100644--- a/src/browser/webapi/ElementInternals.zig+++ b/src/browser/webapi/ElementInternals.zig@@ -207,23 +207,8 @@ fn getLabels(self: *const ElementInternals, frame: *Frame) !js.Array {return Label.getControlLabels(self.asElement(), frame);}-// Barred from constraint validation: disabled, readonly, or inside a datalist.-pub fn willValidate(self: *const ElementInternals) bool {- const element = self.asElement();- if (element.isDisabled()) {- return false;- }- if (element.hasAttributeSafe(comptime .wrap("readonly"))) {- return false;- }- var node = element.asNode()._parent;- while (node) |n| : (node = n._parent) {- const el = n.is(Element) orelse continue;- if (el.getTag() == .datalist) {- return false;- }- }- return true;+fn willValidate(self: *const ElementInternals) bool {+ return self._host.willValidate();}fn getWillValidate(self: *const ElementInternals) !bool {diff --git a/src/browser/webapi/element/html/Custom.zig b/src/browser/webapi/element/html/Custom.zigindex e52cb61cf..ed548015e 100644--- a/src/browser/webapi/element/html/Custom.zig+++ b/src/browser/webapi/element/html/Custom.zig@@ -61,6 +61,25 @@ pub fn isFormAssociated(self: *const Custom) bool {return definition.form_associated;}+// Barred from constraint validation: disabled, readonly, or inside a datalist.+pub fn willValidate(self: *Custom) bool {+ const element = self.asElement();+ if (element.isDisabled()) {+ return false;+ }+ if (element.hasAttributeSafe(comptime .wrap("readonly"))) {+ return false;+ }+ var node = element.asNode()._parent;+ while (node) |n| : (node = n._parent) {+ const el = n.is(Element) orelse continue;+ if (el.getTag() == .datalist) {+ return false;+ }+ }+ return true;+}+// Reactions are queued via enqueue* and fired via fireReaction at the outer// CEReactions boundary (set up by the JS bridge, the parser pump, etc.).//diff --git a/src/browser/webapi/selector/List.zig b/src/browser/webapi/selector/List.zigindex bf383af54..8a85f607a 100644--- a/src/browser/webapi/selector/List.zig+++ b/src/browser/webapi/selector/List.zig@@ -771,11 +771,11 @@ fn isCustomValid(custom: *Node.Element.Html.Custom) ?bool {// matches neither:valid nor :invalidreturn null;}- const internals = custom._internals orelse return true;- if (internals.willValidate() == false) {+ if (custom.willValidate() == false) {// matches neither:valid nor :invalidreturn null;}+ const internals = custom._internals orelse return true;return internals._flags.any() == false;}