From a3fc53ccf7b9a37dd85c1a3905a1be1fa7b89aee Mon Sep 17 00:00:00 2001 From: Anne van Kesteren Date: Mon, 9 Oct 2023 17:09:00 +0200 Subject: [PATCH] HTML: make dir=auto and dirname apply to more form controls For https://github.com/whatwg/html/pull/9689. Helps with https://github.com/web-platform-tests/wpt/issues/25569 as this area was barely tested. (Also correct some typos while here.) --- .../dir-auto-form-associated.window.js | 60 +++++++++++++++++++ .../lang-xmllang-01-ref.html | 2 +- .../global-attributes/lang-xmllang-01.html | 2 +- .../global-attributes/lang-xyzzy.html | 2 +- .../dirname-only-if-applies.html | 8 ++- 5 files changed, 68 insertions(+), 6 deletions(-) create mode 100644 html/dom/elements/global-attributes/dir-auto-form-associated.window.js diff --git a/html/dom/elements/global-attributes/dir-auto-form-associated.window.js b/html/dom/elements/global-attributes/dir-auto-form-associated.window.js new file mode 100644 index 00000000000000..c426417bcfaef8 --- /dev/null +++ b/html/dom/elements/global-attributes/dir-auto-form-associated.window.js @@ -0,0 +1,60 @@ +// Keep this synchronized with +// html/semantics/forms/attributes-common-to-form-controls/dirname-only-if-applies.html +[ + "hidden", + "text", + "search", + "tel", + "url", + "email", + "password", + "submit", + "reset", + "button" +].forEach(type => { + test(t => { + const input = document.createElement("input"); + t.add_cleanup(() => input.remove()); + input.type = type; + assert_equals(input.type, type); + input.dir = "auto"; + input.value = "\u05D0"; // The Hebrew letter Alef (strongly RTL) + document.body.append(input); + assert_true(input.matches(":dir(rtl)")); + }, ` directionality`); +}); + +[ + "date", + "month", + "week", + "time", + "datetime-local", + "number", + "range", + "color", + "checkbox", + "radio", + // "file" // value setter throws + "image" +].forEach(type => { + test(t => { + const input = document.createElement("input"); + t.add_cleanup(() => input.remove()); + input.type = type; + assert_equals(input.type, type); + input.dir = "auto"; + input.value = "\u05D0"; // The Hebrew letter Alef (strongly RTL) + document.body.append(input); + assert_true(input.matches(":dir(ltr)")); + }, ` directionality`); +}); + +test(t => { + const input = document.createElement("textarea"); + t.add_cleanup(() => input.remove()); + input.dir = "auto"; + input.value = "\u05D0"; // The Hebrew letter Alef (strongly RTL) + document.body.append(input); + assert_true(input.matches(":dir(rtl)")); +}, `