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

Issue 1937 | Pass invalid date string to date change handlers #1941

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

marcgarygray
Copy link

@marcgarygray marcgarygray commented Mar 6, 2020

Add invalidDateString to args for date change handlers (onDateChange and onDatesChange) whenever the date string is invalid. Add storybook stories and unit tests to support changes.

Resolves #1937

@marcgarygray
Copy link
Author

marcgarygray commented Mar 6, 2020

I think the CI tests collided because one was running while I merged master into my branch. My branch itself appears to have passed CI but the merge commit has a cancelled travis-ci job and that's the one that's linked in the review summary box. Not sure what the steps are to re-run the build.
image

@renaudl
Copy link

renaudl commented Apr 1, 2020

Hey, Looks good to me but not enough of an expert to fully review.

@amast09
Copy link

amast09 commented Aug 26, 2020

Having this merged would be AMAZING. Based on the current SingleDatePicker props, there is no way to distinguish between an invalid date and an empty date. This means we are unable to have an "optional" date input because we won't be able to tell if the user has a true invalid date or they just cleared the input. To overcome this we are using the following hack to determine whether or not the user has "cleared" the input or not,

useEffect(() => {
  const input = document.getElementById(props.id);

  const changeHandler = (e: Event) => {
    if (e.target) {
      setCurrentInputValue((e.target as HTMLInputElement).value);
    }
  };

  if (input) {
    input.addEventListener('change', changeHandler);
  }

  return () => {
    const inputToRemoveHandlerFrom = document.getElementById(props.id);

    if (inputToRemoveHandlerFrom) {
      inputToRemoveHandlerFrom.removeEventListener('change', changeHandler);
    }
  };
}, []);

which is admittedly fragile and prone to insidious bugs because we are operating outside of React. We felt this approach was better as opposed to completely forking this repository.

Not sure who the official maintainers are of this repo but it would be wonderful if they merged this PR or something close to it that enables this sort of "optional" behavior.

@pranjaljately
Copy link

Any updates on this? Seems to be something highly sought after...

@AndyxWood
Copy link

Bumping this - would love to see more information returning from date change handlers in all relevant DateChangePicker components.

Copy link
Member

@ljharb ljharb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems reasonable. It'll need to be rebased.

@marcgarygray
Copy link
Author

Seems reasonable. It'll need to be rebased.

Sure! To which branch?

@G07cha
Copy link

G07cha commented May 7, 2021

Bumping, the PR has been hanging for quite a while awaiting for feedback.

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

Successfully merging this pull request may close these issues.

Pass invalid values to the onDateChange prop
9 participants