mantinedev / mantine

A fully featured React components library
https://mantine.dev
MIT License
26.83k stars 1.9k forks source link

DateTimePicker not respecting minDate for the TimeInput #4596

Closed manuel-rw closed 8 months ago

manuel-rw commented 1 year ago

What package has an issue

@mantine/dates

Describe the bug

DateTimePicker does not respect minDate and maxDate for the TimeInput component. You can select a time outside the allowed range.

What version of @mantine/hooks page do you have in package.json?

6.0.8

If possible, please include a link to a codesandbox with the reproduced problem

https://codesandbox.io/s/twilight-darkness-pkdmwq?file=/src/App.tsx

Do you know how to fix the issue

Yes

Are you willing to participate in fixing this issue and create a pull request with the fix

No

Possible fix

rajeevdodda commented 1 year ago

@rtivital I would like to work on this issue.

rtivital commented 1 year ago

@rajeevdodda You are welcome to submit a PR with a fix

chewhx-dev commented 10 months ago

The codesandbox link is not found (https://codesandbox.io/s/twilight-darkness-pkdmwq?file=/src/App.tsx)

@manuel-rw are you able to provide a new replication. I would like to look into this issue.

chewhx commented 10 months ago

What I understand about the problem from my own experience trying out the component.

Example:

 const minDateTime = new Date('2024-01-01T01:00:00.000Z');  
 const maxDateTime = new Date('2024-01-02T01:00:00.000Z'); 

    <DateTimePicker
        placeholder="Date time picker"
        clearable
        minDate={minDateTime} // This is 01 Jan 2024, 9:00 AM on my local time (GMT+8)
        maxDate={maxDateTime} // This is 02 Jan 2024, 9:00 AM on my local time (GMT+8)
      />

Expectations:

Actual behaviour:


The <TimeInput /> component uses the native html input tag with type="time".

As I understand from MDN docs:


Using <datalist> to provide suggestions

On Arc Browser:

Screenshot 2024-01-18 at 4 50 16 PM
function Demo() {
  const ref = React.useRef<HTMLInputElement>(null);

  const pickerControl = (
    <ActionIcon variant="subtle" color="gray" onClick={() => ref.current?.showPicker()}>
      <IconClock style={{ width: rem(16), height: rem(16) }} stroke={1.5} />
    </ActionIcon>
  );

  return (
    <>
      <TimeInput
        list="time"
        label="Click icon to show browser picker"
        ref={ref}
        rightSection={pickerControl}
      />
      <datalist id="time">
        <option value="09:00">09:00</option>
        <option value="10:00">10:00</option>
        <option value="11:00">11:00</option>
        <option value="12:00">12:00</option>
      </datalist>
    </>
  );
}

Possible solution:

snturk commented 8 months ago

I'm currently developing a solution to that issue. Will push a PR soon.