Skip to content

A platform for community discussion. Free, open, simple.

FIX: Keep select-kit fallback onChange per instance (#44845)

Jarek Radoszb81ea37a5975
diff --git a/frontend/discourse/select-kit/components/select-kit.js b/frontend/discourse/select-kit/components/select-kit.js
index 9980c7650e0..f0317f766ab 100644
--- a/frontend/discourse/select-kit/components/select-kit.js
+++ b/frontend/discourse/select-kit/components/select-kit.js
@@ -1358,17 +1358,19 @@ export default class SelectKit extends Component {
}
_deprecateMutations() {
- this.actions ??= {};
-
- if (!this.onChange && !this.actions.onChange) {
+ if (!this.onChange && !this.actions?.onChange) {
this._deprecated(
"Implicit mutation has been deprecated, please use `onChange` handler"
);
- this.actions.onChange =
- this.onSelect ||
- this.actions.onSelect ||
- ((value) => this.set("value", value));
+ // `actions` may come from the class prototype, shared by all instances
+ this.actions = {
+ ...this.actions,
+ onChange:
+ this.onSelect ||
+ this.actions?.onSelect ||
+ ((value) => this.set("value", value)),
+ };
}
}
diff --git a/frontend/discourse/tests/integration/components/select-kit/combo-box-test.gjs b/frontend/discourse/tests/integration/components/select-kit/combo-box-test.gjs
index 44dcb6eea68..691ac31345d 100644
--- a/frontend/discourse/tests/integration/components/select-kit/combo-box-test.gjs
+++ b/frontend/discourse/tests/integration/components/select-kit/combo-box-test.gjs
@@ -1,4 +1,5 @@
import { hash } from "@ember/helper";
+import { action } from "@ember/object";
import { click, render } from "@ember/test-helpers";
import { module, test } from "qunit";
import ComboBox from "discourse/select-kit/components/combo-box";
@@ -166,4 +167,40 @@ module("Integration | Component | SelectKit | ComboBox", function (hooks) {
assert.dom(".other-input").isFocused();
});
+
+ test("implicit mutation updates its own instance", async function (assert) {
+ // An `@action` gives the class an `actions` object on its prototype
+ class ActionComboBox extends ComboBox {
+ @action
+ noop() {}
+ }
+
+ setDefaultState(this, { firstValue: 1, secondValue: 1 });
+
+ await render(
+ <template>
+ <ActionComboBox
+ class="first"
+ @content={{this.content}}
+ @value={{this.firstValue}}
+ />
+ <ActionComboBox
+ class="second"
+ @content={{this.content}}
+ @value={{this.secondValue}}
+ />
+ </template>
+ );
+
+ const first = selectKit(".first");
+ const second = selectKit(".second");
+
+ await first.expand();
+ await first.selectRowByValue(2);
+ await second.expand();
+ await second.selectRowByValue(3);
+
+ assert.strictEqual(first.header().value(), "2", "keeps the first value");
+ assert.strictEqual(second.header().value(), "3", "updates the second");
+ });
});