Back to Tamagui

Remove `focusable` prop in favor of `tabIndex`

plans/focusable-remove.md

1.144.43.2 KB
Original Source

Remove focusable prop in favor of tabIndex

Summary

Remove the React Native focusable prop from Tamagui v2 in favor of the web-standard tabIndex. This simplifies the API and aligns with web conventions.

Semantic Mapping

  • focusable={true}tabIndex={0}
  • focusable={false}tabIndex={-1}
  • focusable={!disabled}tabIndex={disabled ? -1 : 0}

Files to Change

Core (remove type + forwarding)

  1. code/core/web/src/interfaces/TamaguiComponentEvents.tsx:8

    • Remove focusable?: any from type
  2. code/core/react-native-web-internals/src/modules/forwardedProps/index.tsx:68

    • Remove focusable: true from forwarded props
  3. code/core/react-native-web-internals/src/modules/createDOMProps/index.tsx

    • Remove focusable handling (lines 110, 310-339)
    • Or just leave it - once removed from forwardedProps it won't reach here
  4. code/core/web/src/createComponent.tsx:1295

    • Remove focusable: viewProps.focusable ?? true
  5. code/core/core/src/createOptimizedView.native.tsx:40,117-119

    • Keep tabIndexfocusable conversion for native (RN still uses focusable)
    • Just remove accepting focusable as input prop

UI Components (change focusable → tabIndex)

  1. code/ui/button/src/v1/Button.tsx

    • Line 84: focusable: truetabIndex: 0
    • Line 295: remove focusable: undefined
  2. code/ui/toggle-group/src/ToggleGroup.tsx:83

    • focusable={!disabled}tabIndex={disabled ? -1 : 0}
  3. code/ui/toast/src/ToastImpl.tsx:34

    • focusable: truetabIndex: 0
  4. code/ui/toast/src/ToastViewport.tsx:293

    • focusable={context.toastCount > 0}tabIndex={context.toastCount > 0 ? 0 : -1}
  5. code/ui/radio-headless/src/useRadioGroup.tsx:235

    • focusable: !isDisabledtabIndex: isDisabled ? -1 : 0
  6. code/ui/create-menu/src/createBaseMenu.tsx:1039

    • focusable={!disabled}tabIndex={disabled ? -1 : 0}
  7. code/ui/tabs/src/createTabs.tsx:142

    • focusable={!disabled}tabIndex={disabled ? -1 : 0}
  8. code/ui/input/src/shared.tsx:20

    • focusable: truetabIndex: 0
  9. code/ui/roving-focus/src/RovingFocusGroup.tsx:172,237

    • Line 172: focusable={focusable}tabIndex={focusable ? 0 : -1}
    • Line 237: Update ItemData type if needed

Tests

  1. code/core/react-native-web-internals/src/modules/createDOMProps/__tests__/index-test.tsx

    • Update or remove focusable tests
  2. code/core/core-test/webAlignment.web.test.tsx:213-220

    • Update test expectations
  3. code/core/core-test/webAlignment.native.test.tsx:188-194

    • Update test expectations
  4. code/compiler/static-tests/tests/webAlignment.web.test.tsx:221

    • Update test

Out of Scope (separate package)

  • code/packages/react-native-web-lite - This is a separate RN-web compatibility layer, keep focusable there

Difficulty

Medium - Straightforward changes but spread across ~15 files. Main risk is missing a usage somewhere.

Testing

  1. Run yarn test in affected packages
  2. Check kitchen-sink for focus behavior
  3. Verify tabIndex works correctly on web and maps to focusable on native