A platform for community discussion. Free, open, simple.
DEV: Modernise mixed test direction text-field to avoid deprecation (#19056)
David Taylorcf51a4ea849c
diff --git a/app/assets/javascripts/discourse/app/components/text-field.js b/app/assets/javascripts/discourse/app/components/text-field.jsindex d3fd889b123..9044d9c1ced 100644--- a/app/assets/javascripts/discourse/app/components/text-field.js+++ b/app/assets/javascripts/discourse/app/components/text-field.js@@ -53,12 +53,13 @@ export default TextField.extend({next(() => this.onChange(this.value));},- @discourseComputed- dir() {+ get dir() {if (this.siteSettings.support_mixed_text_direction) {- let val = this.value;- if (val) {- return isRTL(val) ? "rtl" : "ltr";+ const val = this.get("value");+ if (val && isRTL(val)) {+ return "rtl";+ } else if (val && isLTR(val)) {+ return "ltr";} else {return siteDir();}@@ -70,21 +71,6 @@ export default TextField.extend({cancel(this._timer);},- keyUp(event) {- this._super(event);-- if (this.siteSettings.support_mixed_text_direction) {- let val = this.value;- if (isRTL(val)) {- this.set("dir", "rtl");- } else if (isLTR(val)) {- this.set("dir", "ltr");- } else {- this.set("dir", siteDir());- }- }- },-@discourseComputed("placeholderKey")placeholder: {get() {diff --git a/app/assets/javascripts/discourse/tests/integration/components/text-field-test.js b/app/assets/javascripts/discourse/tests/integration/components/text-field-test.jsindex 88fcd1ae229..7793f816e80 100644--- a/app/assets/javascripts/discourse/tests/integration/components/text-field-test.js+++ b/app/assets/javascripts/discourse/tests/integration/components/text-field-test.js@@ -40,6 +40,20 @@ module("Integration | Component | text-field", function (hooks) {assert.strictEqual(query("input").getAttribute("dir"), "ltr");});+ test("updates the dir attribute when value changes", async function (assert) {+ this.siteSettings.support_mixed_text_direction = true;++ await render(+ hbs`<TextField id="mytextfield" @value="This is a ltr title" />`+ );++ assert.strictEqual(query("input").getAttribute("dir"), "ltr");++ await fillIn("#mytextfield", "זהו שם עברי עם מקום עברי");++ assert.strictEqual(query("input").getAttribute("dir"), "rtl");+ });+test("supports onChange", async function (assert) {this.called = false;this.newValue = null;