# Keyboard Focusable (Mobile)

> In mobile apps, every operable element must be reachable and operable with a keyboard.

Source: https://knowledge.evinced.com/mobile/mobile-validations/keyboard-focusable

Every operable element must be reachable and operable with a keyboard.

Some people use a hardware keyboard, or an assistive technology that sends keyboard events, on their mobile device. Every interactive element must be reachable with the keyboard and operable with it. Most native controls are keyboard-focusable by default, such as `Button` and `EditText` on Android. Don't override the properties that make them focusable. Make sure custom interactive views can receive keyboard focus, and give them a visible focus indicator.

**Keyboard focus on iOS**

On iOS, native controls such as `UIButton` and SwiftUI's `Button` can receive keyboard focus by default when Full Keyboard Access is on. Custom interactive views need to opt in: in UIKit, by overriding `canBecomeFocused`, and in SwiftUI, with the `focusable()` modifier. Test custom views with a keyboard, as described in [Try It Yourself](https://knowledge.evinced.com/mobile/mobile-validations/keyboard-focusable#try-it-yourself).

## Pass Patterns

### Android

XML Views

The button keeps its default focusability, so keyboard focus can reach it.

```xml
<Button
    android:id="@+id/saveButton"
    android:layout_width="..."
    android:layout_height="..."
    android:text="Save" />
```

The clickable image is also focusable, so keyboard users can reach and activate it.

```xml
<ImageView
    android:id="@+id/shareImage"
    android:layout_width="..."
    android:layout_height="..."
    android:src="@drawable/..."
    android:contentDescription="Share"
    android:clickable="true"
    android:focusable="true" />
```

### Cross Platform

Flutter (Android)

The button keeps its default focusability, so keyboard focus can reach it.

```dart
ElevatedButton(
  onPressed: save,
  child: const Text('Save'),
),
```

## Fail Patterns

### Android

XML Views

`android:focusable="false"` removes the button from keyboard focus, although it can still be tapped.

```xml
<Button
    android:id="@+id/saveButton"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:focusable="false"
    android:text="Save" />
```

The image can be tapped, but `android:focusable="false"` prevents keyboard focus from reaching it.

```xml
<ImageView
    android:id="@+id/shareImage"
    android:layout_width="..."
    android:layout_height="..."
    android:src="@drawable/..."
    android:contentDescription="Share"
    android:clickable="true"
    android:focusable="false" />
```

### Cross Platform

Flutter (Android)

`ExcludeFocus` prevents the button from receiving keyboard focus.

```dart
ExcludeFocus(
  child: ElevatedButton(
    onPressed: save,
    child: const Text('Save'),
  ),
),
```

## Try It Yourself

### Using a keyboard

1.  Connect an external keyboard to the device. On iOS, also turn on **Settings > Accessibility > Keyboards > Full Keyboard Access**.
2.  Press Tab, or use the arrow keys, to move keyboard focus through the screen.
3.  Check whether every interactive element receives focus, and activate each one with the keyboard.

**Expected results:** Every interactive element receives a visible keyboard focus and can be activated with the keyboard.

**Actual results:** Some interactive elements are skipped and never receive keyboard focus.

## FAQ

**How does this issue relate to 2.1.1 Keyboard?**

SC 2.1.1 requires all functionality to be operable through a keyboard interface. When an interactive element cannot receive keyboard focus, keyboard users cannot reach or activate it, so the criterion is not met.

**Why is this issue marked as Critical?**

People who rely on a hardware keyboard, or on an assistive technology that sends keyboard events, cannot use an element that keyboard focus cannot reach. They may be blocked from completing key tasks, so it is rated critical.

## Standards and Regulations

| Standard | Success Criterion | Reference |
| --- | --- | --- |
| WCAG 2.2 | [2.1.1 Keyboard](https://www.w3.org/TR/WCAG22/#keyboard) (A) | All functionality of the content is operable through a keyboard interface without requiring specific timings for individual keystrokes, except where the underlying function requires input that depends on the path of the user's movement and not just the endpoints. |
| EN 301 549 | [11.2.1.1 Keyboard](https://www.etsi.org/standards/etsi-301-549) | Same as the WCAG text. |
| Section 508 | [1194.21(a)](https://www.federalregister.gov/documents/2018/01/18/2018-00712/section-508-standards-update#d21) | When software is designed to run on a system that has a keyboard, product functions shall be executable from a keyboard where the function itself or the result of performing a function can be discerned textually. |

## Personas impacted by this issue

-   [Motor and Mobility](https://knowledge.evinced.com/a11y-essentials/personas#motor-and-mobility)
-   [Keyboard](https://knowledge.evinced.com/a11y-essentials/personas#keyboard)

## Learn More

-   [Understanding Success Criterion 2.1.1: Keyboard](https://www.w3.org/WAI/WCAG22/Understanding/keyboard.html)
-   [Android: Support keyboard navigation (Views)](https://developer.android.com/develop/ui/views/touch-and-input/keyboard-input/navigation)
-   [Android: Focus in Jetpack Compose](https://developer.android.com/develop/ui/compose/touch-input/focus)
-   [Apple: Focus-based navigation (UIKit)](https://developer.apple.com/documentation/uikit/focus-based-navigation)
-   [Apple: Focus (SwiftUI)](https://developer.apple.com/documentation/swiftui/focus)
-   [Flutter: Understanding focus](https://docs.flutter.dev/ui/interactivity/focus)

## Related Issues

-   [focus-order](https://knowledge.evinced.com/mobile/mobile-validations/focus-order)
-   [focus-trap](https://knowledge.evinced.com/mobile/mobile-validations/focus-trap)
-   [non-interactive-in-focus-sequence](https://knowledge.evinced.com/mobile/mobile-validations/non-interactive-in-focus-sequence)
-   [on-focus](https://knowledge.evinced.com/mobile/mobile-validations/on-focus)
-   [visible-focus-indication](https://knowledge.evinced.com/mobile/mobile-validations/visible-focus-indication)
