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

244
Views
Material UI Checkbox controlled by keyboard

we are developing a web application using react and material ui and we need to take care of accessibility which means our web application shall be used by persons with disabilities.

Therefore, the web application needs to by operable by keyboard.

It is necessary that one can tab through the forms and use enter to trigger some action. For inputs and buttons this works fine. However, for checkboxes there is a problem. I can focus on a checkbox using tab but I cannot check the checkbox using enter.

When I use onChange/onClick the checkbox gets checked only when I use the mouse:

<Checkbox
     checked={this.state.statementNecessary}
     onChange={() => {
              this.setState({ statementNecessary: !this.state.statementNecessary })}} />

When I use onChange/Onclick + onKeyDown I can focus the checkbox with tab but when I use tab another time the checkbox gets checked even if I just want to go to the next input element.

<Checkbox
     checked={this.state.statementNecessary}
     onKeyDown={() => {
              this.setState({ statementNecessary: !this.state.statementNecessary })}}
     onChange={() => {
              this.setState({ statementNecessary: !this.state.statementNecessary })}} />     

Any hints are appreciated.

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

0

I just found out that checkboxes are supposed to get checked by using space: https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Roles/checkbox_role

So, this is the desired behavior which is working with material ui.

about 4 years ago · Juan Pablo Isaza Report

0

you must check which key is pressed and check for example if Enter Key is pressed then change the state of CheckBox

onKeyDown={(e) => {
          if (e.key === "Enter" )this.setState({ statementNecessary: !this.state.statementNecessary })}}
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!