react-admin icon indicating copy to clipboard operation
react-admin copied to clipboard

Add time field and input

Open arnaudvergnet opened this issue 3 years ago • 1 comments

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.

arnaudvergnet avatar Jun 30 '22 14:06 arnaudvergnet

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

fzaninotto avatar Jun 30 '22 14:06 fzaninotto

Has this issue not been resolved? @fzaninotto

ogustavo-pereira avatar Sep 22 '22 02:09 ogustavo-pereira

Right, #7917 implemented that.

fzaninotto avatar Sep 22 '22 06:09 fzaninotto