fix: reset Custom Style draft on reopen

The modal is kept mounted by its parent (only `open` toggles), so Radix
onOpenChange never fires for a parent-driven open and the draft-reset
branch was dead code — abandoned edits leaked into the next open. Reset
on the `open` prop edge via effect instead. Also pass radix 10 to
parseInt for the size inputs. Adds a reopen-after-cancel regression test.

ha-relevant: yes
This commit is contained in:
Pouzor
2026-06-26 16:20:30 +02:00
parent ecf3cbdfe4
commit f749b38edc
2 changed files with 35 additions and 8 deletions
@@ -134,4 +134,23 @@ describe('CustomStyleModal', () => {
fireEvent.change(widthInputs[0], { target: { value: '250' } })
expect((widthInputs[0] as HTMLInputElement).value).toBe('250')
})
it('resets abandoned edits when reopened after cancel (mounted parent)', () => {
// Parent keeps the modal mounted and only toggles `open`, so the reset must
// happen on the open-prop edge, not via Radix onOpenChange.
const { rerender } = render(<CustomStyleModal open onClose={vi.fn()} />)
fireEvent.click(screen.getByRole('button', { name: 'Router' }))
const widthInput = screen.getAllByRole('spinbutton')[0]
fireEvent.change(widthInput, { target: { value: '250' } })
expect((widthInput as HTMLInputElement).value).toBe('250')
// Cancel = parent flips open → false, then later → true again.
rerender(<CustomStyleModal open={false} onClose={vi.fn()} />)
rerender(<CustomStyleModal open onClose={vi.fn()} />)
fireEvent.click(screen.getByRole('button', { name: 'Router' }))
const reopenedWidth = screen.getAllByRole('spinbutton')[0]
// Draft was reset to saved style (default width 0) — edit did not leak.
expect((reopenedWidth as HTMLInputElement).value).toBe('0')
})
})