UX: closes multi-select on selection when maximum=1 (#15092)

This commit is contained in:
Joffrey JAFFEUX 2021-11-29 14:29:11 +01:00 committed by GitHub
parent 354f88358c
commit 3dc0b9e077
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 76 additions and 1 deletions

View File

@ -67,3 +67,75 @@ discourseModule(
});
}
);
discourseModule(
"Integration | Component | select-kit/multi-select | maximum=1",
function (hooks) {
setupRenderingTest(hooks);
hooks.beforeEach(function () {
this.set("subject", selectKit());
});
componentTest("content", {
template: hbs`
{{multi-select
value=value
content=content
options=(hash maximum=1)
}}
`,
beforeEach() {
setDefaultState(this);
},
async test(assert) {
await this.subject.expand();
await this.subject.selectRowByValue(1);
assert.notOk(this.subject.isExpanded(), "it closes the dropdown");
await this.subject.expand();
await this.subject.deselectItemByValue(1);
assert.ok(
this.subject.isExpanded(),
"it doesnt close the dropdown when no selection has been made"
);
},
});
}
);
discourseModule(
"Integration | Component | select-kit/multi-select | maximum=2",
function (hooks) {
setupRenderingTest(hooks);
hooks.beforeEach(function () {
this.set("subject", selectKit());
});
componentTest("content", {
template: hbs`
{{multi-select
value=value
content=content
options=(hash maximum=2)
}}
`,
beforeEach() {
setDefaultState(this);
},
async test(assert) {
await this.subject.expand();
await this.subject.selectRowByValue(1);
assert.ok(this.subject.isExpanded(), "it doesnt close the dropdown");
},
});
}
);

View File

@ -444,7 +444,10 @@ export default Component.extend(
resolve(items);
}).finally(() => {
if (!this.isDestroying && !this.isDestroyed) {
if (this.selectKit.options.closeOnChange) {
if (
this.selectKit.options.closeOnChange ||
(isPresent(value) && this.selectKit.options.maximum === 1)
) {
this.selectKit.close(event);
}