From cb8fed87e507e1a2f3371dae9c516297d70f37bb Mon Sep 17 00:00:00 2001 From: Ellpeck Date: Thu, 10 Mar 2022 13:50:47 +0100 Subject: [PATCH] Automatically select the first element when a dropdown is opened in auto nav mode --- CHANGELOG.md | 1 + MLEM.Ui/Elements/Dropdown.cs | 7 +++++++ 2 files changed, 8 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1f86062..b737ea7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -45,6 +45,7 @@ Improvements - Automatically update all elements when changing a ui system's viewport - Allow setting a default color for clickable links in UiStyle - Allow ElementHelper's KeybindButton to query a combination at a given index +- Automatically select the first element when a dropdown is opened in auto nav mode Fixes - Fixed paragraph links having incorrect hover locations when using special text alignments diff --git a/MLEM.Ui/Elements/Dropdown.cs b/MLEM.Ui/Elements/Dropdown.cs index 185c1c5..c49c2c6 100644 --- a/MLEM.Ui/Elements/Dropdown.cs +++ b/MLEM.Ui/Elements/Dropdown.cs @@ -22,6 +22,13 @@ namespace MLEM.Ui.Elements { set { this.Panel.IsHidden = !value; this.OnOpenedOrClosed?.Invoke(this); + + // select the first dropdown element in auto nav mode + if (value && this.Controls.IsAutoNavMode) { + var firstChild = this.Panel.GetChildren().FirstOrDefault(c => c.CanBeSelected); + if (firstChild != null) + this.Root.SelectElement(firstChild, true); + } } } ///