feat(key-value-editor): add React Native key-value-editor
KO
2d ago+1570+1570+0123456789012345678901234567890123456789-71-71-01234567890123456789
First component for the pilot in drift-ui/ui#132.
Depends on drift-ui/ui#146 (and #142 under it). This item lists @drift-ui/key-value-editor-utils in registryDependencies, and that item doesn't exist on drift-ui.dev until #146 merges. Until then the preview app works, because the lib file is checked in here, but shadcn add from this registry fails.
What's in it
registry/default/ui/key-value-editor.tsxhas the same props as the web component:value,defaultValue,onValueChange,secretValues, the labels and placeholders, anddisabled.- Button, input, text and icon come from React Native Reusables, installed with the shadcn CLI and referenced by URL in
registryDependencies.global.cssandtailwind.config.jsuse their theme variables, which are the shadcn neutral palette. - The utils,
use-controllable-stateandkey-value-editor-utilsfiles are installed from@drift-uiand aren't edited here. - Jest with
jest-expoand React Native Testing Library. There are 6 tests: edit, add and remove, Enter on the last row,.envpaste, duplicate keys, and masked values.
Where it differs from web
- React Native has no paste event. When the key field grows by more than one character in a single change, it's treated as a paste and run through
pasteRows. - The key field is
multilinewithsubmitBehavior="submit", so newlines in pasted text survive and Enter still moves on. It has a little extra top padding so it lines up with the value field. - React Native has no
aria-invalid, so a duplicate key is added to the field's label: "Key 1, duplicate key". - After removing the last row, focus doesn't move to the add button.
Screenshot
iOS simulator, Expo Go:

Not checked yet
Dark mode, Android, and a real paste on a device. The paste test fakes the text change.
Summary by cubic
Adds the first React Native component, key-value-editor, to the native drift-ui registry with the same API as the web version.
- Supports
value,defaultValue,onValueChange,secretValues, row labels and placeholders, anddisabled. - Reuses shared parsing logic from
@drift-ui/key-value-editor-utilsand pulls primitives and theme variables from React Native Reusables. - Detects
.envpastes inonChangeTextbecause React Native has no paste event; a newline also counts as a paste so a paste over a selected key is caught even when it shrinks the key, and it replaces the old key. - Marks duplicate keys with a label suffix instead of
aria-invalid, which React Native lacks. - Adds Jest coverage with
jest-expoand React Native Testing Library for editing, adding/removing rows, Enter submission, paste, duplicates, and masked values.
Dependencies
- The registry item lists
@drift-ui/key-value-editor-utilsas a dependency that is not yet published, soshadcn addfails until drift-ui/ui#146 merges.