Skip to content

Commit 4421718

Browse files
authored
fix: close() and onClose() functions should only be called w/open drop (#442)
1 parent 25091b4 commit 4421718

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

packages/multiple-select-vanilla/src/MultipleSelectInstance.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ const OPTIONS_HIGHLIGHT_LIST_SELECTOR = '.ms-select-all.highlighted, ul li[data-
2929

3030
export class MultipleSelectInstance {
3131
protected _bindEventService: BindingEventService;
32+
protected _isOpen = false;
3233
protected isAllSelected = false;
3334
protected isPartiallyAllSelected = false;
3435
protected fromHtml = false;
@@ -275,11 +276,9 @@ export class MultipleSelectInstance {
275276
return;
276277
}
277278

278-
if (
279-
(this.getEventTarget(e) === this.dropElm ||
280-
(findParent(this.getEventTarget(e), '.ms-drop') !== this.dropElm && this.getEventTarget(e) !== this.elm)) &&
281-
this.options.isOpen
282-
) {
279+
const eventTarget = this.getEventTarget(e);
280+
const fpDropElm = findParent(this.getEventTarget(e), '.ms-drop');
281+
if (this._isOpen && (eventTarget === this.dropElm || (fpDropElm !== this.dropElm && eventTarget !== this.elm))) {
283282
this.close('body.click');
284283
}
285284
}) as EventListener,
@@ -1306,6 +1305,7 @@ export class MultipleSelectInstance {
13061305
this.highlightCurrentOption();
13071306
}
13081307

1308+
this._isOpen = true;
13091309
this.options.onOpen();
13101310
}
13111311

@@ -1460,6 +1460,7 @@ export class MultipleSelectInstance {
14601460
}
14611461

14621462
close(reason?: CloseReason) {
1463+
this._isOpen = false;
14631464
this.options.isOpen = false;
14641465
this.parentElm.classList.remove('ms-parent-open');
14651466
this.choiceElm?.querySelector('div.ms-icon-caret')?.classList.remove('open');

0 commit comments

Comments
 (0)