Skip to content

Commit 66b1be4

Browse files
committed
fix(dropdown): Toggle buttons on page now work correctly
Closes #122
1 parent 3c6ac7d commit 66b1be4

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

components/dropdown/dropdown.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@ export class SuiDropdown implements AfterContentInit {
3737
return this.service.isOpen && !this.service.isNested;
3838
}
3939

40+
// Tracks dropdown open state between `mousedown` and `click`.
41+
private _isOpenOnMouseDown:boolean;
42+
4043
@Input()
4144
public get isOpen():boolean {
4245
return this.service.isOpen;
@@ -115,9 +118,14 @@ export class SuiDropdown implements AfterContentInit {
115118
}
116119
}
117120

121+
@HostListener("document:mousedown", ["$event"])
122+
public onDocumentMouseDown(e:MouseEvent):void {
123+
this._isOpenOnMouseDown = this.isOpen;
124+
}
125+
118126
@HostListener("document:click", ["$event"])
119127
public onDocumentClick(e:MouseEvent):void {
120-
if (!this._element.nativeElement.contains(e.target)) {
128+
if (!this._element.nativeElement.contains(e.target) && this._isOpenOnMouseDown) {
121129
if (this.service.autoCloseMode === DropdownAutoCloseType.ItemClick ||
122130
this.service.autoCloseMode === DropdownAutoCloseType.OutsideClick) {
123131
// No need to reflect in parent since they are also bound to document.

0 commit comments

Comments
 (0)