Skip to content

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

Open
@mschipperheyn

Description

@mschipperheyn

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}
        />
    )
  },
)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions