Sanity Pioneers: Get early access to betas, extra AI credits, and a direct line to the engineering team. Apply now

Key Value Input

Sanity Studio input component for editing ordered key-value string pairs. Supports add, remove, and reorder operations with real-time patch updates.

Install command

npm i @liiift-studio/sanity-key-value-input

sanity-key-value-input

npm version

Sanity Studio input component for editing ordered key-value string pairs. Supports add, remove, and reorder operations with real-time patch updates.

Preview

Empty / initial state — a single placeholder row with the Add Row button below.

Empty initial state

With entries — once rows exist, the reorder rail appears on the left and a trash icon on the right of each row.

Populated state with reorder rail

Install

npm install @liiift-studio/sanity-key-value-input

Usage

Use KeyValueInput as a custom input component on an array field:

import { KeyValueInput } from '@liiift-studio/sanity-key-value-input'

export const mySchema = defineType({
	name: 'myDocument',
	type: 'document',
	fields: [
		defineField({
			name: 'metadata',
			title: 'Metadata',
			type: 'array',
			of: [
				{
					type: 'object',
					fields: [
						{ name: 'key', type: 'string' },
						{ name: 'value', type: 'string' },
					],
				},
			],
			components: {
				input: KeyValueInput,
			},
		}),
	],
})

The component provides:

  • Add new key-value pairs
  • Remove existing pairs
  • Reorder pairs up and down
  • Inline editing of both key and value fields

Peer Dependencies

PackageVersion
@sanity/icons>=3
@sanity/ui>=3
react>=18
sanity>=3

Related contributions