Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Editing value manually doesn't update widget if done at the start #219

Open
mschipperheyn opened this issue Nov 21, 2023 · 0 comments
Open

Comments

@mschipperheyn
Copy link

I see a weird behavior that updating the content of the input field manually normally does update the state of the widget and the date it displays. But not if the first thing you do is edit that value manually (and not selecting it in the widget). In that scenario, it doesn't update the value.

I see this behavior also on the demo pages. Where I see also something I don't see locally: that the even after first selecting a date in the widget, you can update it manually with it impacting the displayed date in the widget.

export const DateInput = React.forwardRef<HTMLInputElement, DateInputProps>(
  (
    {
      name,
      value,
      onChange,
    },
    ref,
  ) => {
    const val = value as string
    const [date, setDate] = React.useState<{
      startDate: DateType
      endDate: DateType
    }>(
      !val?.length
        ? { startDate: new Date(), endDate: '' }
        : { startDate: new Date(val), endDate: '' },
    )

    const handleChange = React.useCallback(
      (value: DateValueType) => {
        const val = value?.startDate as string | undefined
        onChange!(val || '')
        setDate(value)
      },
      [onChange],
    )
    return (
        <Datepicker
          inputName={name}
          value={date}
          useRange={false}
          asSingle
          onChange={handleChange}
        />
    )
  },
)
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

No branches or pull requests

1 participant