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

Add time field and input #7914

Closed
arnaudvergnet opened this issue Jun 30, 2022 · 3 comments · Fixed by #7917
Closed

Add time field and input #7914

arnaudvergnet opened this issue Jun 30, 2022 · 3 comments · Fixed by #7917

Comments

@arnaudvergnet
Copy link
Contributor

Is your feature request related to a problem? Please describe.
React admin offers components to display/edit dates and datetimes (<DateField/>, <DateInput/>, <DateTimeInput/>), but nothing for time.

Describe the solution you'd like
HTML <input type="time"> seems to be well supported across browsers, so it should be safe to create a new components to edit time like date and datetime. To display time, JS toLocaleTimeString seems also safe to use.

Describe alternatives you've considered
For the moment, I wrote my own implementations, but it would be nice to see those components by default in react-admin.

To edit times, I use the <DateTimeInput/> with the prop type="time". For the format function, I use convertDateToString but only returning the time part of the string.

To display times, I use the following code:

const timeString = new Date(<RECORD_VALUE>).toLocaleTimeString();
return (
  <Typography component="span" variant="body2">
    {timeString}
  </Typography>

Which is basically the same as <DateField/> but using toLocaleTimeString instead of toLocaleDateString.

If you want I can make PRs to add those new components.

@fzaninotto
Copy link
Member

Nice! Please open a PR with your components. The PR should include the code, unit tests, and the documentation for these components.

@ogustavo-pereira
Copy link
Contributor

Has this issue not been resolved? @fzaninotto

@fzaninotto
Copy link
Member

Right, #7917 implemented that.

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

Successfully merging a pull request may close this issue.

3 participants