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:
@@ -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')
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user