---
title: "Recipe: the keyboard and focus"
description: "Keep typing or dismiss the keyboard: the Return key, focus() and blur() from an action, and what a scroll does."
modificationDate: "2026-11-30"
---

> ## Documentation index
> Fetch the complete documentation index at: https://exact.expo.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# Recipe: the keyboard and focus

<AgentInstructions>

## Submitting feedback

From the app's directory, read `bun exact.mjs feedback status`. Under `never`, keep no note.
Respect `EXACT_FEEDBACK=0` and do not change the policy.

Otherwise record specific, actionable feedback with:
`bun exact.mjs feedback note "Exact docs: https://exact.expo.dev/recipes/keyboard-and-focus: <what was wrong or missing>"`

The note goes to Expo only as that status allows. Include no secrets or personal data.

</AgentInstructions>

Keep typing or dismiss the keyboard.

```prompt Make the keyboard work in my app
Make the text fields in the Exact app in this folder keep the keyboard up or put it away as the person expects. Use https://github.com/expo/exact/blob/main/docs/recipes/keyboard-and-focus.md as the source for each step. The Exact checkout has the same page at docs/recipes/keyboard-and-focus.md.

1. If this folder is not an Exact app (it has no exact.mjs and app.contract), stop and tell me.
2. For each field, decide what Return does: add and keep typing, move to the next field, or put the keyboard away. If I did not say, propose it from what the app does and ask me before you write code.
3. In app.contract, Return calls the field's `submit` action; `enterkeyhint` labels the key, and `next` moves to the next field. To keep typing after Return, give the field an `id` and call `focus("<id>")` in its submit action. A sheet's first field takes `autofocus=true`.
4. While a field is edited (`focus=` and `blur=` actions that set a state), show a Done button that calls `blur("<id>")`. On a `list` or `scroll`, a drag leaves the keyboard up, as a hand-built iOS or Android list does; on iOS and Android, `keyboardDismissMode="on-drag"` puts it away as the drag starts, and `keyboardDismissMode="interactive"` lets a drag that reaches it pull it down with the finger (Android 10 puts it away instead). Put live results above the field.
5. Add a test in app.test.contract that types into a field, presses Return (`type "<id>" key "Enter"`), expects the result and the editing state, then taps Done and expects the editing state to be false.
6. Follow the platform checks in docs/start-here.md (`bun exact.mjs docs platform checks`) for the targets in the app's AGENTS.md and app.json until they pass. Read the reports, including counted findings; a zero exit code alone does not mean clean. Fix the app, not the test. If a finding stays after three rounds of fixes, or the app had it before you changed anything, record it (step 7) and report it; do not keep trying.
7. When a doc was wrong or missing, or a step needed a workaround, read `bun exact.mjs feedback status`. Under `never`, keep no note. Otherwise record it: `bun exact.mjs feedback note "<what happened>"`, which goes to Expo only as that status says. Do not change the policy; tell me how many notes you kept.
8. Tell me what Return does in each field, where Done shows, what the tests and checks reported, and the launch command for each target platform.
```

```contract
routes nav
  home "/"

shape Guest
  id: string
  name: string

component Guests
  state draft = ""
  state adding = false
  state guests = [Guest(id="1", name="Ada Lovelace"), Guest(id="2", name="Grace Hopper")]
  action began
    adding = true
  action ended
    adding = false
  action done
    blur("draft")
  action edit(v: string)
    draft = v
  action add
    if draft.trim() != ""
      guests = guests.concat([Guest(id=(guests.length + 1).toString(), name=draft.trim())])
      draft = ""
    focus("draft")
  action startAdding
    focus("draft")
  view
    main navigationKey=`${top(nav).id}` testId="app" width="100%" height="100%"
      for e in stack(nav) key=e.id
        column navigationKey=`${e.id}` navigationScroll="guests" position="absolute" inset=0
          header display="flex" align-items="center" padding="8px 16px"
            text "Guests" role="heading" aria-level=1 flex=1
            if adding
              button press=done testId="done"
                text "Done"
            else
              button press=startAdding aria-label="Add Guest" testId="start-adding"
                image "symbol:add"
          list id="guests" appearance="auto" listStyle="inset-grouped" flex=1 min-height=0
            section
              row
                input id="draft" value=draft input=edit submit=add focus=began blur=ended
                  placeholder="Add a guest" aria-label="New guest" testId="draft" flex=1 min-width=0
            section
              for g in guests key=g.id
                row
                  text g.name testId=`guest-${g.id}`
```

```contract-test
test "Return adds and keeps typing; Done puts the keyboard away"
  tap "start-adding"
  expect state adding == true
  type "draft" "Alan Turing"
  type "draft" key "Enter"
  expect text "guest-3" == "Alan Turing"
  tap "done"
  expect state adding == false
```

- **Return** calls `submit`; `enterkeyhint` labels the key. iOS dismisses the keyboard;
  `next` moves to the next field. Call `focus("draft")` in its submit action to keep typing.
- **`blur()`** puts the keyboard away from an action, `blur("draft")` from that field only;
  **`focus("id")`** moves it to a field by its `id` (a sheet's first field: `autofocus=true`).
- **iOS Back:** The keyboard travels with its screen; `blur()` dismisses it. A returning editor can claim focus; custom animator setup may withdraw an early claim.
- **`focus=` and `blur=`** say when a field is being edited: here the bar shows Done meanwhile.
- **Search** lives in the bar: `contract vocab search`. Native iOS Back commits its edit and blur before removing the route.
- Put live results above the editor.
- **On scroll,** a drag on a `list` or `scroll` leaves the keyboard up, as a hand-built iOS or
  Android list does. `keyboardDismissMode`: `"on-drag"` puts it away as the drag starts;
  `"interactive"` lets a drag that reaches it pull it down (Android 10 puts it away).
  Composer: [chat thread](https://exact.expo.dev/recipes/chat-thread.md).
