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

Controlled range date picker bug when clearing the dates after selecting just one #6092

Closed
1 of 2 tasks
FerranMontoliu opened this issue Apr 16, 2024 · 1 comment
Closed
1 of 2 tasks
Labels
Fixed patch Completed issues that will be published with next patch (1.0.X)

Comments

@FerranMontoliu
Copy link

Dependencies check up

  • I have verified that I use latest version of all @mantine/* packages

What version of @mantine/* packages do you have in package.json?

7.8.0

What package has an issue?

@mantine/dates

What framework do you use?

create-react-app (CRA)

In which browsers you can reproduce the issue?

All

Describe the bug

Brief explanation

I have a controlled DatePicker with type="range". In my component, I have a button for users to clear the selection they are performing. The issue is that, if a user has selected the start date and not the end date, even if you set the value to [null, null], the calendar still has the start date selected.

Steps to reproduce:

  1. Open the stackblitz url provided.
    image

  2. Select one date in the calendar.
    image

  3. Click the button to clear the dates.
    image

  4. Move the cursor around the calendar. You will see that the start date does not appear to be selected, but the blue shadow is still there when you hover over the calendar.
    image

  5. Click on another day. Now your selection will take the first date (which should have been cleared), and the second date (the one you just selected).
    image

Minimal example used

export default function App() {
  const [value, setValue] = useState([null, null]);

  const handleChange = (val) => {
    setValue(val);
  };

  const clearRange = () => {
    setValue([null, null]);
  };

  return (
    <Stack>
      <DatePicker
        type="range"
        value={value}
        onChange={handleChange}
        allowSingleDateInRange
      />

      <Button onClick={clearRange}>CLEAR</Button>
    </Stack>
  );
}

If possible, include a link to a codesandbox with a minimal reproduction

https://stackblitz.com/edit/react-ojxzj7?file=src%2FApp.js

Possible fix

When setting the value to [null, null], the dates should be cleared.

Self-service

  • I would be willing to implement a fix for this issue
rtivital added a commit that referenced this issue Apr 23, 2024
…state when controlled state changes to an empty value (#6092)
@rtivital rtivital added the Fixed patch Completed issues that will be published with next patch (1.0.X) label Apr 23, 2024
@rtivital
Copy link
Member

Fixed in 7.8.1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Fixed patch Completed issues that will be published with next patch (1.0.X)
Projects
None yet
Development

No branches or pull requests

2 participants