tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

dir-auto-form-associated.window.js (1923B)


      1 // Keep this mostly synchronized with
      2 // html/semantics/forms/attributes-common-to-form-controls/dirname-only-if-applies.html
      3 // except that won't have "reset" and "button" as those don't submit their value
      4 [
      5  "hidden",
      6  "text",
      7  "search",
      8  "tel",
      9  "url",
     10  "email",
     11  "password",
     12  "submit",
     13  "reset",
     14  "button"
     15 ].forEach(type => {
     16  test(t => {
     17    const input = document.createElement("input");
     18    t.add_cleanup(() => input.remove());
     19    input.type = type;
     20    assert_equals(input.type, type);
     21    document.body.append(input);
     22 
     23    input.setAttribute("value", "\u05D0"); // The Hebrew letter Alef (strongly RTL)
     24    assert_true(input.matches(":dir(ltr)"));
     25    input.removeAttribute("value");
     26 
     27    input.dir = "auto";
     28    input.setAttribute("value", "\u05D0");
     29    assert_true(input.matches(":dir(rtl)"));
     30    input.removeAttribute("value");
     31    assert_true(input.matches(":dir(ltr)"));
     32 
     33    input.value = "\u05D0";
     34    assert_true(input.matches(":dir(rtl)"));
     35  }, `<input dir=auto type=${type}> directionality`);
     36 });
     37 
     38 [
     39  "date",
     40  "month",
     41  "week",
     42  "time",
     43  "datetime-local",
     44  "number",
     45  "range",
     46  "color",
     47  "checkbox",
     48  "radio",
     49  // "file" // value setter throws
     50  "image"
     51 ].forEach(type => {
     52  test(t => {
     53    const input = document.createElement("input");
     54    t.add_cleanup(() => input.remove());
     55    input.type = type;
     56    assert_equals(input.type, type);
     57    input.dir = "auto";
     58    input.value = "\u05D0"; // The Hebrew letter Alef (strongly RTL)
     59    document.body.append(input);
     60    assert_true(input.matches(":dir(ltr)"));
     61  }, `<input dir=auto type=${type}> directionality`);
     62 });
     63 
     64 test(t => {
     65  const input = document.createElement("textarea");
     66  t.add_cleanup(() => input.remove());
     67  input.dir = "auto";
     68  input.value = "\u05D0"; // The Hebrew letter Alef (strongly RTL)
     69  document.body.append(input);
     70  assert_true(input.matches(":dir(rtl)"));
     71 }, `<textarea dir=auto> directionality`);