material-ui-time-picker icon indicating copy to clipboard operation
material-ui-time-picker copied to clipboard

Disable range of time

Open etairi opened this issue 7 years ago • 3 comments

I would like to suggest a possible feature for the TimePicker. I would like to have the option to disable hours and minutes like in Material-UI DatePicker with "minDate" and "maxDate" parameters. It would be useful to set the available time range.

For example, <TimePicker from={'9:50'} to={'16:33'} />

etairi avatar Nov 23 '17 19:11 etairi

A fully flexible approach that works more like DatePicker's shouldDisableDate option:

const allowHours   = ({hours})=> hours >=9 && hours <= 16

const allowMinutes = ({hours, minutes})=> (
  (hours==9 && minutes>=50) ||
  (hours==16 && minutes<=33) ||
  true
)

return <TimePicker allowHours={allowHours} allowMinutes={allowMinutes}/>

Or a better compromise:

const allowedTimes = [{from: '9:50', to: '16:33'}]

return <TimePicker allowedTimes={allowedTimes}/>

gunn avatar Dec 26 '17 04:12 gunn

@etairi Good idea! :+1:

@gunn Your first option is far too complicated imho, and the second option is just a more complicated way to configure what @etairi suggested. :wink:

leMaik avatar Dec 26 '17 13:12 leMaik

@leMaik agreed on the first option. The point of the second option is to allow this:

const officeHours = [{from: '9:00', to: '12:00'}, {from: '13:00', to: '17:00'}]
return <TimePicker allowedTimes={officeHours}/>

gunn avatar Dec 28 '17 09:12 gunn