diff --git a/src/test/unit.js b/src/test/unit.js index 0680fbb11..81da21ac8 100644 --- a/src/test/unit.js +++ b/src/test/unit.js @@ -1,4 +1,5 @@ import "test/unit/attachment_test" +import "test/unit/bidi_test" import "test/unit/block_test" import "test/unit/composition_test" import "test/unit/document_test" diff --git a/src/test/unit/bidi_test.js b/src/test/unit/bidi_test.js new file mode 100644 index 000000000..17d104b97 --- /dev/null +++ b/src/test/unit/bidi_test.js @@ -0,0 +1,9 @@ +import { assert, test, testGroup } from "test/test_helper" +import { getDirection } from "trix/core/helpers" + +testGroup("BIDI", () => { + test("detects text direction", () => { + assert.equal(getDirection("abc"), "ltr") + assert.equal(getDirection("אבג"), "rtl") + }) +}) diff --git a/src/trix/core/helpers/bidi.js b/src/trix/core/helpers/bidi.js index 20efd506d..81fe0e380 100644 --- a/src/trix/core/helpers/bidi.js +++ b/src/trix/core/helpers/bidi.js @@ -6,12 +6,14 @@ const RTL_PATTERN = export const getDirection = (function() { const input = makeElement("input", { dir: "auto", name: "x", dirName: "x.dir" }) + const textArea = makeElement("textarea", { dir: "auto", name: "y", dirName: "y.dir" }) const form = makeElement("form") form.appendChild(input) + form.appendChild(textArea) const supportsDirName = (function() { try { - return new FormData(form).has(input.dirName) + return new FormData(form).has(textArea.dirName) } catch (error) { return false } @@ -27,8 +29,8 @@ export const getDirection = (function() { if (supportsDirName) { return function(string) { - input.value = string - return new FormData(form).get(input.dirName) + textArea.value = string + return new FormData(form).get(textArea.dirName) } } else if (supportsDirSelector) { return function(string) {