react-admin
react-admin copied to clipboard
Add time field and input
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.
Nice! Please open a PR with your components. The PR should include the code, unit tests, and the documentation for these components.
Has this issue not been resolved? @fzaninotto
Right, #7917 implemented that.