fix: show red border for invalid history size input#1328
fix: show red border for invalid history size input#1328claudeaceae wants to merge 2 commits intop0deje:masterfrom
Conversation
Replace the NumberFormatter-based TextField with a text-based one that validates input in real-time and shows a red border when the value is outside the valid range (1-999). On submit (Return key), invalid values revert to the last valid value. Fixes p0deje#1292 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
prabhavagrawal7
left a comment
There was a problem hiding this comment.
Added some suggestions for cleaner code.
| @State private var viewModel = ViewModel() | ||
| @State private var storageSize = Storage.shared.size | ||
| @State private var sizeText = "" | ||
| @State private var isSizeValid = true |
There was a problem hiding this comment.
much better to use isSizeValid as a method to perform checks.
| @State private var isSizeValid = true | |
| private func isSizeValid() -> Bool { | |
| if sizeText.isEmpty { return true } | |
| guard let value = Int(sizeText) else { return false } | |
| return Self.sizeRange.contains(value) | |
| } |
| Stepper("", value: $size, in: 1...999) | ||
| .border(isSizeValid ? Color.clear : Color.red) | ||
| .onAppear { sizeText = "\(size)" } | ||
| .onChange(of: sizeText) { |
There was a problem hiding this comment.
remove the redundent logic in onChange and onSubmit or atleast reuse them by creating another method.
|
Thanks for the review suggestions @prabhavagrawal7! On converting On the duplicated validation — good catch. I can extract a |
|
Let me share the snippet for much cleaner approach, where the states will be well defined: |
|
@prabhavagrawal7 thanks for the detailed snippet! The computed You're right that this eliminates the explicit state tracking. One thing I want to preserve is the revert behavior on submit — when the user presses Enter with invalid input, the field should snap back to the last good value (so the red border resolves). The current code does That said, I'll hold off on changes until the maintainer weighs in — they may have their own preferences on the approach. No point iterating between us if they want something different entirely. |
|
I like the approach of @prabhavagrawal7. You can restore the text content on |
Replace explicit state tracking with a computed method per reviewer suggestion. Keeps revert-on-submit behavior for invalid input. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
|
Thanks @weisJ! Pushed an update adopting the computed |
Summary
NumberFormatter-based TextField with a text-based TextField that validates input in real-timeThis addresses the silent failure where typing a value above 999 appeared to be accepted but was actually ignored.
Fixes #1292
Test plan
🤖 Generated with Claude Code