diff --git a/osu.Framework/Graphics/UserInterface/Dropdown.cs b/osu.Framework/Graphics/UserInterface/Dropdown.cs index bd0fb0f0f56..717d69dae37 100644 --- a/osu.Framework/Graphics/UserInterface/Dropdown.cs +++ b/osu.Framework/Graphics/UserInterface/Dropdown.cs @@ -248,7 +248,8 @@ protected Dropdown() Header.ToggleMenu = Menu.Toggle; Header.ChangeSelection += selectionKeyPressed; - Header.SearchTerm.ValueChanged += t => Menu.SearchTerm = t.NewValue; + if (Header.SearchTerm != null) + Header.SearchTerm.ValueChanged += t => Menu.SearchTerm = t.NewValue; Menu.RelativeSizeAxes = Axes.X; Menu.PreselectionConfirmed += preselectionConfirmed; diff --git a/osu.Framework/Graphics/UserInterface/DropdownHeader.cs b/osu.Framework/Graphics/UserInterface/DropdownHeader.cs index 2fb345636be..28ca116d32a 100644 --- a/osu.Framework/Graphics/UserInterface/DropdownHeader.cs +++ b/osu.Framework/Graphics/UserInterface/DropdownHeader.cs @@ -6,6 +6,7 @@ using osuTK.Graphics; using System; using System.Collections.Generic; +using JetBrains.Annotations; using osu.Framework.Bindables; using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Shapes; @@ -26,15 +27,21 @@ public abstract partial class DropdownHeader : Container, IKeyBindingHandler SearchBar.AlwaysDisplayOnFocus; - set => SearchBar.AlwaysDisplayOnFocus = value; + get => SearchBar?.AlwaysDisplayOnFocus ?? false; + set + { + if (SearchBar != null) + SearchBar.AlwaysDisplayOnFocus = value; + } } + [CanBeNull] protected internal DropdownSearchBar SearchBar { get; } - public Bindable SearchTerm => SearchBar.SearchTerm; + [CanBeNull] + public Bindable SearchTerm => SearchBar?.SearchTerm; - protected internal override IEnumerable AdditionalFocusTargets => new Drawable[] { SearchBar }; + protected internal override IEnumerable AdditionalFocusTargets => SearchBar != null ? new Drawable[] { SearchBar } : Array.Empty(); private Color4 backgroundColour = Color4.DarkGray; @@ -98,10 +105,18 @@ protected DropdownHeader() RelativeSizeAxes = Axes.X, AutoSizeAxes = Axes.Y }, - SearchBar = CreateSearchBar(), }; + + SearchBar = CreateSearchBar(); + + if (SearchBar != null) + AddInternal(SearchBar); } + /// + /// Creates a to attach to this dropdown, or null to not attach any (making this dropdown unsearchable). + /// + [CanBeNull] protected abstract DropdownSearchBar CreateSearchBar(); protected override void LoadComplete()