Skip to content

fix(connection-dialog): prevent number input default value override on clear - #62

Merged
GOODBOY008 merged 1 commit into
GOODBOY008:mainfrom
sunxiaobin89:fix/port-input-default-override
Jul 26, 2026
Merged

fix(connection-dialog): prevent number input default value override on clear#62
GOODBOY008 merged 1 commit into
GOODBOY008:mainfrom
sunxiaobin89:fix/port-input-default-override

Conversation

@sunxiaobin89

Copy link
Copy Markdown
Contributor

Summary

When clearing a number input field in the connection dialog (port, proxy port, etc.), the value immediately snaps back to its default (22, 8080, etc.) instead of allowing the user to type a new value.

Root Cause

In handlers using the pattern parseInt(e.target.value) || 22, clearing the field produces NaN || 22 = 22, which updateConfig() immediately writes back — React controlled input then renders 22.

Changes

  • src/components/connection-dialog.tsx — Added a unified displayValues state object (number | '') that tracks what each number input should visually display, separate from ConnectionConfig's strict number type. Introduced a generic handleNumberInput() helper to handle all 4 affected inputs (port, proxyPort, keepAliveInterval, serverAliveCountMax) with the same logic.

Testing

  • 494 tests pass, 0 new failures
  • Manually verified in real app: clearing port now stays empty, typing a valid number works, protocol switching resets port to default

…n clear

- Add displayValues state to track number input values as number | ''
  so React controlled inputs can render empty when user clears the field
- Introduce handleNumberInput() to decouple display values from
  ConnectionConfig's strict number types
- Fix port, proxyPort, keepAliveInterval, serverAliveCountMax inputs
  that would immediately snap back to their defaults when cleared

Before: onChange used || fallback (parseInt('') || 22 = 22)
After:  empty input sets display to ''; valid numbers update config
        via onValid callback; defaults still apply at connect time

Test: 494 tests pass, 0 new failures

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR fixes a UX issue in ConnectionDialog where clearing controlled number inputs (e.g., port/proxy port) immediately reverts to a default value, by separating the displayed value from the strictly-typed numeric config.

Changes:

  • Introduces a displayValues state to allow number inputs to render as empty ('') while editing without overwriting config.
  • Adds a shared handleNumberInput() helper and routes the affected numeric inputs through it.
  • Ensures protocol switching updates both config.port and the displayed port value.

Comment on lines +112 to +126
const handleNumberInput = (
field: keyof typeof initialDisplayValues,
rawValue: string,
onValid: (n: number) => void,
) => {
if (rawValue === '') {
setDisplayValues(prev => ({ ...prev, [field]: '' }));
return;
}
const parsed = parseInt(rawValue, 10);
if (!Number.isNaN(parsed)) {
setDisplayValues(prev => ({ ...prev, [field]: parsed }));
onValid(parsed);
}
};
Comment on lines +103 to +108
const initialDisplayValues = {
port: 22 as number | '',
proxyPort: 8080 as number | '',
keepAliveInterval: 60 as number | '',
serverAliveCountMax: 3 as number | '',
};
Comment on lines +163 to +168
syncDisplayValues({
port: editingConnection.port ?? 22,
proxyPort: editingConnection.proxyPort ?? 8080,
keepAliveInterval: editingConnection.keepAliveInterval ?? 60,
serverAliveCountMax: editingConnection.serverAliveCountMax ?? 3,
});

@GOODBOY008 GOODBOY008 left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

@sunxiaobin89 Great catch! LGTM~

@GOODBOY008
GOODBOY008 merged commit 7afb505 into GOODBOY008:main Jul 26, 2026
4 checks passed
Copilot AI added a commit that referenced this pull request Jul 26, 2026
PR #61:
- Add aria-label and aria-expanded to folder chevron button for accessibility
- Restore activeConnectionIds memoization to prevent unnecessary re-renders
- Fix expand/collapse state preservation using flat map for deep tree support

PR #62:
- Replace parseInt with Number() + integer floor for number inputs
- Reset to protocol-specific default port when field is cleared
- Use getDefaultPort(protocol) for port fallback when editing connections
Copilot AI added a commit that referenced this pull request Jul 26, 2026
…icts

Resolved conflicts in:
- src/App.tsx: kept typeof guard for folderPath parameter
- src/__tests__/connection-dialog-folder.test.tsx: kept proper ComponentProps import
- src/components/connection-dialog.tsx: kept main's displayValues/handleNumberInput
  pattern from PR #62, re-applied dedicated initialFolder effect fix
- src/components/connection-manager.tsx: kept main's mergeExpanded from PR #61,
  re-applied conditional onNewConnection rendering and aria-label fixes
@sunxiaobin89
sunxiaobin89 deleted the fix/port-input-default-override branch July 27, 2026 03:22
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.

3 participants