diff --git a/CHANGELOG.md b/CHANGELOG.md index 47ac492..62b68c9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -20,6 +20,7 @@ Additions Improvements - Allow elements to auto-adjust their size even when their children are aligned oddly +- Close other dropdowns when opening a dropdown ## 6.0.0 ### MLEM diff --git a/MLEM.Ui/Elements/Dropdown.cs b/MLEM.Ui/Elements/Dropdown.cs index 636bf35..3c1b46e 100644 --- a/MLEM.Ui/Elements/Dropdown.cs +++ b/MLEM.Ui/Elements/Dropdown.cs @@ -42,7 +42,16 @@ namespace MLEM.Ui.Elements { }); this.OnAreaUpdated += e => this.Panel.PositionOffset = new Vector2(0, e.Area.Height / this.Scale); this.OnOpenedOrClosed += e => this.Priority = this.IsOpen ? 10000 : 0; - this.OnPressed += e => this.IsOpen = !this.IsOpen; + this.OnPressed += e => { + this.IsOpen = !this.IsOpen; + // close other dropdowns in the same root when we open + if (this.IsOpen) { + this.Root.Element.AndChildren(o => { + if (o != this && o is Dropdown d && d.IsOpen) + d.IsOpen = false; + }); + } + }; this.GetGamepadNextElement = (dir, usualNext) => { // Force navigate down to our first child if we're open if (this.IsOpen && dir == Direction2.Down)