Skip to content

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

DEV: adds expandedOnInsert option to sk (#19870)

Joffrey JAFFEUXf525f722ea51
diff --git a/app/assets/javascripts/discourse/tests/integration/components/select-kit/single-select-test.js b/app/assets/javascripts/discourse/tests/integration/components/select-kit/single-select-test.js
index cc8a13006d4..14874b0b93e 100644
--- a/app/assets/javascripts/discourse/tests/integration/components/select-kit/single-select-test.js
+++ b/app/assets/javascripts/discourse/tests/integration/components/select-kit/single-select-test.js
@@ -411,4 +411,17 @@ module("Integration | Component | select-kit/single-select", function (hooks) {
assert.ok(header.bottom > body.top, "it correctly offsets the body");
});
+
+ test("options.expandedOnInsert", async function (assert) {
+ setDefaultState(this);
+ await render(hbs`
+ <SingleSelect
+ @value={{this.value}}
+ @content={{this.content}}
+ @options={{hash expandedOnInsert=true}}
+ />
+ `);
+
+ assert.dom(".single-select.is-expanded").exists();
+ });
});
diff --git a/app/assets/javascripts/select-kit/addon/components/select-kit.js b/app/assets/javascripts/select-kit/addon/components/select-kit.js
index 304b6c3f5be..95f8d8cd55d 100644
--- a/app/assets/javascripts/select-kit/addon/components/select-kit.js
+++ b/app/assets/javascripts/select-kit/addon/components/select-kit.js
@@ -188,6 +188,14 @@ export default Component.extend(
this.handleDeprecations();
},
+ didInsertElement() {
+ this._super(...arguments);
+
+ if (this.selectKit.options.expandedOnInsert) {
+ this._open();
+ }
+ },
+
click(event) {
event.preventDefault();
event.stopPropagation();
@@ -296,6 +304,7 @@ export default Component.extend(
desktopPlacementStrategy: null,
hiddenValues: null,
disabled: false,
+ expandedOnInsert: false,
},
autoFilterable: computed("content.[]", "selectKit.filter", function () {