Skip to content

Commit

Permalink
fix: allow dynamic value change for date picker
Browse files Browse the repository at this point in the history
  • Loading branch information
marek-mihok authored and mturoci committed Aug 2, 2023
1 parent 2e8b48b commit 5780ee9
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
7 changes: 7 additions & 0 deletions ui/src/date_picker.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,13 @@ describe('Datepicker.tsx', () => {
expect(wave.args[name]).toBeTruthy()
})

it('Set args when value is updated', () => {
const { rerender } = render(<XDatePicker model={{ name, value: '1999-12-30' }} />)
expect(wave.args[name]).toBe('1999-12-30')
rerender(<XDatePicker model={{ name, value: '1999-12-31' }} />)
expect(wave.args[name]).toBe('1999-12-31')
})

it('Calls sync when trigger specified', () => {
const pushMock = jest.fn()
const { getAllByRole, getAllByText } = render(<XDatePicker model={{ ...datepickerProps, trigger: true }} />)
Expand Down
7 changes: 5 additions & 2 deletions ui/src/date_picker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,11 @@ export const
if (m.trigger) wave.push()
}

// eslint-disable-next-line react-hooks/exhaustive-deps
React.useEffect(() => { wave.args[m.name] = defaultVal }, [])
React.useEffect(() => {
wave.args[m.name] = defaultVal
setValue(parsedVal ? new Date(parsedVal) : undefined)
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [m.value])

return (
<Fluent.DatePicker
Expand Down

0 comments on commit 5780ee9

Please sign in to comment.