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

[@mantine/dates] fix timeInputProps defaultValue not working #6959

Conversation

Cuzart
Copy link
Contributor

@Cuzart Cuzart commented Oct 10, 2024

Fixes #6958 and is self-explanatory

@rtivital
Copy link
Member

This won't work, if the default value is set on the TimeInput and then not modified by the user, it will not be treated as part of the date object passed to onChange handler.

@rtivital rtivital closed this Oct 16, 2024
@Cuzart
Copy link
Contributor Author

Cuzart commented Oct 17, 2024

Yes you are right I missed that point. Out of interest I tested an approach in the handleDateChange function if we check if the formattedTime is different from the timeInputProps?.defaultValue we get the expected behaviour. But this could add a bit of complexity depending on the format of the defaultValue and as you mentioned you are not planing to support this any time soon I will try to fix this outside of the component via JavaScript. Anyhow it could be misleading that the type of timeInputProps is supporting defaultValue then.

const handleDateChange = (date: DateValue) => {
    if (date) {
      if (timeInputProps?.defaultValue && formatTime(date) !== timeInputProps?.defaultValue) {
        date.setHours(parseInt(timeInputProps?.defaultValue?.split(':')[0]));
        date.setMinutes(parseInt(timeInputProps?.defaultValue?.split(':')[1]));
      }
      setValue(assignTime(_value, date));
    }
    timeInputRef.current?.focus();
  };

@rtivital
Copy link
Member

Okay, I'll remove defaultValue and value props from this type

rtivital added a commit that referenced this pull request Oct 17, 2024
…ops from `timeInputProps` types to avoid confusion (#6959)
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.

DateTimePicker timeInputProps defaultValue does not get applied
2 participants