From 516c8932367fe1233b06bc98472b678336cceda1 Mon Sep 17 00:00:00 2001 From: "L. David Baron" Date: Wed, 25 Oct 2023 07:51:33 -0700 Subject: [PATCH] Implement updated HTML language inheritance rules. This makes two changes to match the HTML spec: * only honor the unnamespaced lang attribute on HTML and SVG elements * have elements in a shadow tree inherit language from the shadow host Note that an update to the HTML specification regarding the SVG elements case is proposed in https://github.com/whatwg/html/pull/9882, but https://www.w3.org/TR/SVG/struct.html#LangAttribute already defines it. These changes match the related changes to the dir attribute, but use a separate feature flag as a killswitch, since they are separable. Fixed: 1490711 Bug: 576815 Change-Id: I6462181e6d4433aa1dcc9a2c42e5c12754830e52 --- .../global-attributes/lang-attribute.window.js | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 html/dom/elements/global-attributes/lang-attribute.window.js diff --git a/html/dom/elements/global-attributes/lang-attribute.window.js b/html/dom/elements/global-attributes/lang-attribute.window.js new file mode 100644 index 000000000000000..de0c03e6f853ecf --- /dev/null +++ b/html/dom/elements/global-attributes/lang-attribute.window.js @@ -0,0 +1,16 @@ +test(() => { + const container = document.createElement("div"); + document.body.append(container); + container.setAttribute("lang", "en-CA"); + + const child = document.createElementNS("div", "test"); + container.append(child); + child.setAttribute("lang", "en-NZ"); + + assert_true(container.matches(":lang(en-CA)"), "container matches en-CA"); + assert_true(child.matches(":lang(en-CA)"), "child matches en-CA"); + assert_false(container.matches(":lang(en-NZ)"), "container does not match en-NZ"); + assert_false(child.matches(":lang(en-NZ)"), "child does not match en-NZ"); + + container.remove(); +}, "unnamespaced lang attribute only works on elements in the HTML namespace");