Skip to main content
🎉 A11y Issue Detection Agent is now live! Detect accessibility issues like a WCAG expert with AI. Try now!
No Result Found
Connect & Get help from fellow developers on our Discord community. Ask the CommunityAsk the Community

Keyboard focus for interactive elements

The keyboard focus for interactive elements rule ensures all interactive elements in your app are reachable and operable using an external keyboard. This ensures that users who rely on a keyboard for navigation can access every feature without needing to use touch or mouse input.

  • Rule Category: Focus and Navigation
  • WCAG 2.1 & 2.2 SC: 2.1.1 (A), 2.1.3 (AAA)
  • Rule Severity: Critical
  • Supported Platforms and Frameworks: Android, iOS, React Native, Flutter

Success criteria

The specific criterion for success is:

  • Every interactive element is reachable and operable using an external keyboard.

How to fix

To ensure keyboard operability for assistive technology users, follow these steps:

  • Use native controls, such as Button, EditText, CheckBox, Switch, etc. These controls are focusable by default.
  • For custom controls, set the following attributes to manually define focus behavior:
    • android:focusable="true"
    • android:focusableInTouchMode="true"
    • android:importantForAccessibility="yes"
  • Ensure focus can move logically between elements and is not blocked or trapped.
  • Use standard UIKit or SwiftUI controls, such as UIButton, UITextField, UISwitch, etc. These controls are focusable by default.
  • For custom controls:
    • Ensure the element is accessible by setting isAccessibilityElement = YES.
    • Expose proper accessibility traits, such as .button, .adjustable, etc.
  • Support keyboard activation by handling:
    • UIKeyCommand in UIKit.
    • Keyboard shortcuts or focus activation in SwiftUI.
  • Ensure focus can move logically between elements and is not blocked or trapped.

Although isAccessibilityElement = YES ensures screen reader access, it does not guarantee keyboard operability. You must explicitly support keyboard focus and activation for custom controls.

  • Use accessible components, such as Pressable, TouchableOpacity, Button, instead of plain View.
  • Set accessible={true}
  • Set the correct accessibilityRole. For example, button, checkbox, link.
  • Support keyboard interaction by handling onKeyPress for Enter or Space where needed.
  • Use built-in widgets, such as ElevatedButton, TextField, Switch, etc. These widgets are focusable by default.
  • For custom widgets:
    • Wrap them in Focus or FocusableActionDetector.
    • Ensure actions are mapped to keyboard inputs. For example, ActivateIntent.

Example

The following Android example scan report highlights a keyboard focus for interactive elements violation for a button that is marked as important for accessibility but is not focusable.

The App Accessibility issue details window with a keyboard focus for interactive elements violation.

Error

  • The button has the android:importantForAccessibility attribute set to yes, but the android:focusable attribute is set to false. As a result, the button is not reachable via keyboard navigation.

Fix

To fix this violation:

  • Set the android:focusable attribute to true for the button in your layout XML file to make it focusable via keyboard navigation.

The following iOS example scan report highlights a keyboard focus for interactive elements violation for a button that is marked as an accessibility element but does not respond to user interaction.

The App Accessibility issue details window with a keyboard focus for interactive elements violation.

Error

  • The button has the isAccessibilityElement property set to 1, or true, but the accessibilityRespondsToUserInteraction property is set to 0, or false. As a result, the button is not reachable via keyboard navigation.

Fix

To fix this violation:

  • Set the accessibilityRespondsToUserInteraction property to true for the button to make it focusable via keyboard navigation.

References

We're sorry to hear that. Please share your feedback so we can do better

Contact our Support team for immediate help while we work on improving our docs.

We're continuously improving our docs. We'd love to know what you liked





Thank you for your valuable feedback

Is this page helping you?

Yes
No

We're sorry to hear that. Please share your feedback so we can do better

Contact our Support team for immediate help while we work on improving our docs.

We're continuously improving our docs. We'd love to know what you liked





Thank you for your valuable feedback!

Talk to an Expert
Download Copy Check Circle