diff --git a/Ooui/Select.cs b/Ooui/Select.cs index 885de9b..e0b1b7e 100644 --- a/Ooui/Select.cs +++ b/Ooui/Select.cs @@ -1,12 +1,21 @@ using System; +using System.Linq; namespace Ooui { public class Select : FormControl { + bool gotValue = false; + public string Value { - get => GetStringAttribute ("value", ""); - set => SetAttributeProperty ("value", value ?? ""); + get { + if (gotValue) return GetStringAttribute ("value", ""); + return GetDefaultValue (); + } + set { + gotValue = true; + SetAttributeProperty ("value", value ?? ""); + } } public event TargetEventHandler Change { @@ -23,28 +32,29 @@ namespace Ooui : base ("select") { // Subscribe to the change event so we always get up-to-date values - Change += (s, e) => { }; + Change += (s, e) => { gotValue = true; }; } public void AddOption (string label, string value) { - AppendChild (new Option { Label = label, Value = value }); + AppendChild (new Option { Text = label, Value = value }); } - protected override void OnChildInsertedBefore (Node newChild, Node referenceChild) + string GetDefaultValue () { - base.OnChildInsertedBefore (newChild, referenceChild); - var val = Value; - if (string.IsNullOrEmpty (val) && newChild is Option o && !string.IsNullOrEmpty (o.Value)) { - val = o.Value; - } + var options = Children.OfType