# On Focus (Mobile)

> In mobile apps, an element receiving focus must not change the context, for example by opening a new screen or a modal, or by changing the element's state.

Source: https://knowledge.evinced.com/mobile/mobile-validations/on-focus

When an element receives focus, it must not trigger a change of context, such as navigating to a new screen, opening a modal, or changing the element's state.

The focus state shows that an element is ready for user input. When focus alone causes a change of context, such as navigating to a new screen, opening a modal, submitting a form, or checking a checkbox, the interface becomes unpredictable. Keyboard users, screen reader users, and people with cognitive disabilities can lose their place, and people with motor disabilities may struggle to undo an action they did not intend. Make sure significant changes happen only when the user actively triggers them, for example by activating a button with Enter or Space, and never as the result of an element simply receiving focus.

## Pass Patterns

### Android

**XML Views**

The guests selector opens only when the field is activated, not when it receives focus.

```kotlin
guestsField.setOnClickListener {
    showGuestsSheet()
}
```

**Jetpack Compose**

The guests selector opens only when the field is activated, not when it receives focus.

```kotlin
Text(
    text = "Guests",
    modifier = Modifier.clickable { showGuestsSheet = true },
)
```

### Cross Platform

React Native (Android)

The dialog opens only when the field is activated, not when it receives focus.

```tsx
<Pressable accessibilityRole="button" onPress={showDialog}>
  <Text style={styles.bodyLarge}>Show dialog</Text>
</Pressable>
```

## Fail Patterns

### Modal opens on focus

![Two screenshots of a travel app. In the first, before focus, the search form shows Destination, Dates, and Guests fields. In the second, the Guests field receives focus, and a sheet for choosing the number of rooms, adults, and children opens over the screen.](https://knowledge.evinced.com/images/mobile/mobile-validations/on-focus/on-focus-modal-on-focus.png)

### Checkbox checked on focus

![Two screenshots of a screen titled “Selectable List”, asking to select your favorite fruits. In the first, before focus, the “Apple” checkbox is unchecked. In the second, the checkbox receives focus and becomes checked.](https://knowledge.evinced.com/images/mobile/mobile-validations/on-focus/on-focus-checkbox-on-focus.png)

### Android

**XML Views**

The guests selector opens as soon as the field receives focus.

```kotlin
guestsField.setOnFocusChangeListener { _, hasFocus ->
    if (hasFocus) showGuestsSheet()
}
```

The checkbox becomes checked as soon as it receives focus.

```kotlin
appleCheckBox.setOnFocusChangeListener { _, hasFocus ->
    if (hasFocus) appleCheckBox.isChecked = true
}
```

**Jetpack Compose**

The guests selector opens as soon as the field receives focus.

```kotlin
Text(
    text = "Guests",
    modifier = Modifier
        .onFocusChanged { if (it.isFocused) showGuestsSheet = true }
        .focusable(),
)
```

### Cross Platform

React Native (Android)

The dialog opens as soon as the field receives focus.

```tsx
<Pressable accessibilityRole="button" focusable onFocus={showDialog}>
  <Text style={styles.bodyLarge}>Show dialog</Text>
</Pressable>
```

## 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.  Watch what happens each time an element receives focus.

**Expected results:** The focused element shows that it has focus, and nothing else on the screen changes.

**Actual results:** Moving focus to an element opens a modal, navigates to another screen, changes the layout, or changes the element's state.

## FAQ

**How does this issue relate to 3.2.1 On Focus?**

SC 3.2.1 requires that when any user interface component receives focus, it does not initiate a change of context. Opening a modal, navigating to a new screen, or changing an element's state just because it received focus is such a change, so the criterion is not met.

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

Unexpected changes on focus make the interface unpredictable. Users can lose their place, trigger actions they did not intend, and struggle to undo them, which can interrupt critical tasks, so it is rated serious.

## Standards and Regulations

| Standard | Success Criterion | Reference |
| --- | --- | --- |
| WCAG 2.2 | [3.2.1 On Focus](https://www.w3.org/TR/WCAG22/#on-focus) (A) | When any user interface component receives focus, it does not initiate a change of context. |
| EN 301 549 | [11.3.2.1 On Focus](https://www.etsi.org/standards/etsi-301-549) | Same as the WCAG text. |
| Section 508 | [1194.21(l)](https://www.federalregister.gov/documents/2018/01/18/2018-00712/section-508-standards-update#d21) | When electronic forms are used, the form shall allow people using assistive technology to access the information, field elements, and functionality required for completion and submission of the form, including all directions and cues. |

## Personas impacted by this issue

-   [Low Vision](https://knowledge.evinced.com/a11y-essentials/personas#low-vision)
-   [Keyboard](https://knowledge.evinced.com/a11y-essentials/personas#keyboard)
-   [Cognitive](https://knowledge.evinced.com/a11y-essentials/personas#cognitive)

## Learn More

-   [Understanding Success Criterion 3.2.1: On Focus](https://www.w3.org/WAI/WCAG22/Understanding/on-focus.html)

## Related Issues

-   [focus-order](https://knowledge.evinced.com/mobile/mobile-validations/focus-order)
-   [keyboard-focusable](https://knowledge.evinced.com/mobile/mobile-validations/keyboard-focusable)
-   [visible-focus-indication](https://knowledge.evinced.com/mobile/mobile-validations/visible-focus-indication)
