Skip to content

onSelect returned value issue with "range" mode in v9 #2463

Answered by gpbl
melkras asked this question in Support
Discussion options

You must be logged in to vote

@melkras not sure I understand correctly your requirements. It looks like you want users click twice on the same day, before confirming the want a range made up of the same day.

in this case you will need to control the selection with the selected prop:

export function Example() {
  const [selected, setSelected] = useState<DateRange | undefined>();

  const handleOnSelect = (range: DateRange | undefined, triggerDate: Date) => {
    if (range?.from && range?.to && isSameDay(range.to, triggerDate)) {
      // 1st click on the same selected day
      setSelected({ from: triggerDate, to: undefined });
    } else if (
      selected?.from &&
      !selected.to &&
      isSameDay(selected.from, t…

Replies: 1 comment 3 replies

Comment options

You must be logged in to vote
3 replies
@melkras
Comment options

@gpbl
Comment options

Answer selected by melkras
@melkras
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants