@@ -272,7 +272,12 @@ struct SingleChoiceList<Value>: View where Value: Equatable {
272
272
// this is not a valid value, so we fall back to the
273
273
// initial value, showing the invalid-value state if
274
274
// the field is not empty
275
- if let initialValue {
275
+ // As `customValueIsFocused` takes a while to propagate, we
276
+ // only reset the field to the initial value if it was previously
277
+ // a custom value. Otherwise, blanking this field when the user
278
+ // has selected another field will cause the user's choice to be
279
+ // overridden.
280
+ if let initialValue, fromValue ( value. wrappedValue) != nil {
276
281
value. wrappedValue = initialValue
277
282
}
278
283
customValueInputIsInvalid = !customValueInput. isEmpty
@@ -355,18 +360,23 @@ struct SingleChoiceList<Value>: View where Value: Equatable {
355
360
case three
356
361
case someNumber( Int )
357
362
}
358
- return StatefulPreviewWrapper ( ExampleValue . two) { SingleChoiceList (
359
- title: " Test " ,
360
- options: [ . two, . three] ,
361
- value: $0,
362
- parseCustomValue: { Int ( $0) . flatMap { $0 > 3 ? ExampleValue . someNumber ( $0) : nil } } ,
363
- formatCustomValue: { if case let . someNumber( n) = $0 { " \( n) " } else { nil } } ,
364
- customLabel: " Custom " ,
365
- customPrompt: " Number " ,
366
- customLegend: " The legend goes here " ,
367
- customInputMinWidth: 120 ,
368
- customInputMaxLength: 6 ,
369
- customFieldMode: . numericText
370
- )
363
+ return StatefulPreviewWrapper ( ExampleValue . two) { value in
364
+ VStack {
365
+ let vs = " Value = \( value. wrappedValue) "
366
+ Text ( vs)
367
+ SingleChoiceList (
368
+ title: " Test " ,
369
+ options: [ . two, . three] ,
370
+ value: value,
371
+ parseCustomValue: { Int ( $0) . flatMap { $0 > 3 ? ExampleValue . someNumber ( $0) : nil } } ,
372
+ formatCustomValue: { if case let . someNumber( n) = $0 { " \( n) " } else { nil } } ,
373
+ customLabel: " Custom " ,
374
+ customPrompt: " Number " ,
375
+ customLegend: " The legend goes here " ,
376
+ customInputMinWidth: 120 ,
377
+ customInputMaxLength: 6 ,
378
+ customFieldMode: . numericText
379
+ )
380
+ }
371
381
}
372
382
}
0 commit comments