On iPad, a SwiftUI view using .focusable(interactions: .edit) and .focused($isFocused) cannot acquire focus when a hardware keyboard is already connected. Setting isFocused = true from a button leaves it false. Tapping the view also leaves it unfocused, although the tap is received. Pressing Tab can focus the same view.
struct FocusProbeView: View {
@FocusState private var isFocused: Bool
var body: some View {
VStack {
Text("Target")
.focusable(interactions: .edit)
.focused($isFocused)
.onTapGesture { print("Target tapped") }
Text("isFocused = \(isFocused)")
Button("Focus target") {
isFocused = true
}
}
.defaultFocus($isFocused, true)
}
}
Steps to reproduce:
- Run this view on an iPad with a hardware keyboard connected.
- Tap “Focus target”, then tap “Target”.
- Observe that isFocused remains false.
- Press Tab. The target can receive focus through keyboard navigation.
- Disconnect the keyboard. Restart the app and tap “Focus target” again. isFocused becomes true. Reconnecting the keyboard does not remove that focus.
Expected: A visible custom view marked .focusable(interactions: .edit) can receive focus through @FocusState, including when a hardware keyboard is connected.
Actual: Programmatic focus fails when the keyboard is already connected. A native TextField tested with the same button and @FocusState does receive focus.
Environment:
- iPad model: MU1V2NF/A; iPadOS version: 26.7.2; Xcode version: 27.2; hardware keyboard: Logi Folio Touch.
- iPad model: Device Hub iPad Pro 11-inch (M5); iPadOS version: 27.2; Xcode version: 27.2; hardware keyboard: Device Hub.