Skip to content

fix input clearing ux#106

Open
v-i-s-h-n-u-ps wants to merge 1 commit into
mainfrom
NO-REF/fix-question-disappearing
Open

fix input clearing ux#106
v-i-s-h-n-u-ps wants to merge 1 commit into
mainfrom
NO-REF/fix-question-disappearing

Conversation

@v-i-s-h-n-u-ps
Copy link
Copy Markdown
Contributor

Pull Request Checklist

Before you submit a pull request, please make sure you have to following:

  • I have added or updated TypeScript types for my changes, ensuring they are compatible with the existing codebase.
  • I have added JSDoc comments to my TypeScript definitions for improved documentation.
  • I have added tests that prove my fix is effective or that my feature works.
  • I have added any necessary documentation (if appropriate).
  • I have made sure my PR is up-to-date with the main branch.

PR Type

What kind of change does this PR introduce?

  • Bugfix
  • Feature
  • Code style update (formatting, local variables)
  • Refactoring (no functional changes, no API changes)
  • Documentation content changes
  • TypeScript type definitions update
  • Other... Please describe:

@v-i-s-h-n-u-ps v-i-s-h-n-u-ps requested a review from a team as a code owner June 2, 2026 12:28
Copy link
Copy Markdown

@constructor-claude-bedrock constructor-claude-bedrock Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This PR fixes the UX behavior where the Input field was always cleared after submission, adding logic to retain the pre-filled value when the user submits it unchanged — the implementation is mostly correct but has two subtle bugs that could cause unexpected behavior.

Inline comments: 4 discussions added

Overall Assessment: ⚠️ Needs Work

if (value.trim()) {
onSubmit(value.trim());
setValue('');
if (value.trim() !== providedValue) {
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Important Issue: value is trimmed before comparison but providedValue is not. If providedValue has any leading/trailing whitespace (e.g. " blue? "), value.trim() will never equal it, causing the field to clear on every submit even when the user typed nothing new. Conversely, if the user pads the pre-filled text with spaces, value.trim() would equal an un-padded providedValue, preventing the expected clear.

Fix: trim both sides:

if (value.trim() !== providedValue?.trim()) {

expect(button).toBeDisabled();
});

it('retains value after submit when it matches providedValue (default mode)', () => {
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggestion: The test description says "default mode" but the behavior being tested is actually specific to the case where value prop is provided. Consider renaming to 'retains value after submit when input matches the provided value prop' to make the condition explicit and avoid ambiguity with "default" (no value prop at all).

expect(input.value).toBe('Does this come in blue?');
});

it('clears value after submit when it differs from providedValue', () => {
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggestion: The new tests don't cover the scenario where no value prop is supplied (i.e. providedValue is undefined). In that case, value.trim() !== providedValue is always true, so the clear path is always taken — but this is incidental rather than explicit. Adding a test like 'clears value after submit when no value prop is provided' would make that contract explicit and guard against regressions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant