Skip to content

Commit d5c880d

Browse files
authored
Fix clearing planning mode input (#38)
1 parent 5712010 commit d5c880d

File tree

8 files changed

+358
-313
lines changed

8 files changed

+358
-313
lines changed

.nvmrc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
v22
1+
v24

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
# Changelog
22

3+
## [0.3.1] - 2026-01-01
4+
5+
### Fixed
6+
7+
- Fix planning mode input not clearing on select-all + delete (George Dietrich)
8+
9+
[0.3.1]: https://github.com/blacksmoke16/rebalancer/releases/tag/v0.3.1
10+
311
## [0.3.0] - 2025-12-20
412

513
### Added

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ A privacy-focused portfolio rebalancing tool that helps you optimize your invest
1818

1919
### Prerequisites
2020

21-
- Node.js 22+
21+
- Node.js 24+
2222
- npm
2323

2424
### Getting Started

package-lock.json

Lines changed: 312 additions & 302 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "rebalancer",
33
"private": true,
4-
"version": "0.3.0",
4+
"version": "0.3.1",
55
"type": "module",
66
"license": "MIT",
77
"scripts": {

src/components/ui/FundDataRow.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ export const FundDataRow = memo<FundDataRowProps>(function FundDataRow({
5454
<NumberField
5555
isCurrency
5656
allowNegative
57-
value={pendingChange === 0 ? undefined : pendingChange}
57+
value={pendingChange === 0 ? "" : pendingChange}
5858
placeholder={`Current: $${currentValue.toLocaleString()}`}
5959
data-testid={`${fund.ticker}-${account.name}-pending-value`}
6060
onValueChange={(value) => {

src/components/ui/NumberField.tsx

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { NumberInput, NumberInputProps } from "@mantine/core";
2+
import type { NumberFormatValues } from "react-number-format";
23
import { useCallback } from "react";
34
import { FORMATTING, UI } from "../../constants";
4-
import { validation } from "../../utils/validation";
55

66
interface NumberFieldProps
77
extends Omit<NumberInputProps, "onBlur" | "onValueChange"> {
@@ -22,14 +22,11 @@ export function NumberField({
2222
...props
2323
}: NumberFieldProps) {
2424
const handleValueChange = useCallback(
25-
(value: string | number): void => {
25+
(values: NumberFormatValues): void => {
2626
if (!onValueChange) return;
27-
28-
const parsedValue =
29-
typeof value === "string" ? validation.parseAmount(value) : value || 0;
27+
let finalValue = values.floatValue ?? 0;
3028

3129
// Apply constraints based on field type
32-
let finalValue = parsedValue;
3330
if (!allowNegative && finalValue < 0) {
3431
finalValue = 0;
3532
}
@@ -49,7 +46,7 @@ export function NumberField({
4946
allowDecimal={false}
5047
thousandSeparator={thousandSeparator}
5148
leftSection={finalLeftSection}
52-
onChange={handleValueChange}
49+
onValueChange={handleValueChange}
5350
size={size}
5451
{...props}
5552
/>

tests/planning-mode.spec.ts

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -280,4 +280,34 @@ test.describe("Planning Mode", () => {
280280
await expect(page.getByText("Projected ($)")).toBeVisible();
281281
await expect(page.getByText("Projected (%)")).toBeVisible();
282282
});
283+
284+
test("Clear Input - Select All and Delete clears value completely", async ({
285+
page,
286+
}) => {
287+
// 1. Navigate to Portfolio page and enter planning mode
288+
await page.goto("http://localhost:5173");
289+
await page.getByRole("link", { name: "Portfolio" }).click();
290+
await page.getByRole("button", { name: "Plan Transactions" }).click();
291+
292+
const input = page.getByTestId("VTI-401k-pending-value");
293+
294+
// 2. Type a negative value character by character (to trigger formatting)
295+
await input.click();
296+
await page.keyboard.type("-3210");
297+
await expect(page.getByText("Unaccounted Sales")).toBeVisible();
298+
299+
// 3. Select all (Ctrl+A) and delete
300+
await input.focus();
301+
await page.keyboard.press("Control+a");
302+
await page.keyboard.press("Backspace");
303+
304+
// 4. Verify input is cleared
305+
await expect(input).toHaveValue("");
306+
307+
// 5. Verify state returns to initial (no pending changes)
308+
await expect(page.getByText("Planning Mode Active")).toBeVisible();
309+
await expect(
310+
page.getByRole("button", { name: "Apply Changes" }),
311+
).toBeDisabled();
312+
});
283313
});

0 commit comments

Comments
 (0)