Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

178
Views
Set a default pick time in a TextField type=time material ui

I would like to set a default time to a textfield type time of Material UI. My requeriment is that before clicking the picker, no time have been settted up, but when clicking, appears 08:00 as the default time to pick.

Before clicking

After clicking

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Turn your TextField into a controlled component, by giving it a value that is set to state, and update it onChange.

There are no focus or click handler props for that API, but you can wrap the TextField with a span and set a click handler on that.

From there, create a function to update the state to be a string value of "08:00" if there is no value in the event target. This will allow you to reuse the function for onClick and onChange with little overhead.

const [time, setTime] = useState("")

const changeTime = (e) => {
  setTime(e.target.value || "08:00")
}

<span onClick={changeTime}>
  <TextField value={time} type="time" onChange={changeTime}/>
</span>

The onClick works because of event bubbling. You will be clicking the input, but that bubbles up to the span's event listener. There should be no chance of clicking on the span, because it will fit the content, and input will lay over it.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!