Skip to content

Value Field

A read-only monospace value with a copy button, which can be masked like an API key.

Invite link

Installation

  1. Add the registryOnce per project
  2. Add value-field

Usage

Long values scroll sideways. The copy button confirms the copy, including to screen readers.

masked hides the value, such as a secret key, until someone presses the eye button. Copying always copies the whole value.

The field's children are the buttons at the end of the row. Without children, it renders a ValueFieldCopy, after a ValueFieldReveal when masked is set. Pass your own buttons to change their order, leave one out or add a ValueFieldRegenerate.

display shows something in place of the value, such as the same text with its parts colored, as Package Command's PackageCommandText does. The field still copies value.

For password entry, use a Password Input. If the browser should never see a secret at all, don't send it to the page.

Composition

Examples

Without a label

Leave out label when the surrounding context makes clear what the value is.

Sizes

size sets the row's height: sm, default or lg. The buttons scale with it.

Copying on click

copyOnClick copies the value when someone clicks anywhere in the row, as long as no text in it is selected. The copy button still copies from the keyboard.

Confirming a copy

ValueFieldCopy's onCopy runs after the value is copied, such as to show a Toast.

Install

Masked

Secret key

Visible characters

visibleSuffix and visiblePrefix set how many characters stay visible at each end while the value is masked.

Webhook signing secret
Publishable key
Database password

Regenerate

ValueFieldRegenerate is a button for generating a new value. If its onClick returns a promise, the button stays pending until the promise settles: its icon spins and it ignores presses. If that takes more than a second, screen readers announce "Regenerating value". Set pendingAnnouncement to change the message, or to an empty string to silence it.

This example asks for confirmation first with an Alert Dialog's createAlertDialogConfirm. Once the new key is generated, it sets revealed to show the key, and onRevealedChange keeps revealed in sync with the eye button.

Secret key

With a switch

Use revealed to control whether a masked value is shown from outside the field, such as with a Switch. In this example, the field's only child is a ValueFieldCopy, so the switch is the only way to show the value.

Secret key

Copy button

To copy a value shown some other way, use Copy Button on its own.

Props

ValueFieldReveal and ValueFieldRegenerate take the props of a Button. ValueFieldCopy takes the props of a CopyButton except value and size, which come from the field. Each button's aria-label sets its accessible name, and its Tooltip shows the same text. ValueFieldReveal keeps the same name whether the value is shown or hidden, and is marked as pressed while the value is shown.

The file also exports maskValue(value, visiblePrefix, visibleSuffix), which returns a masked value as a string, such as for a Table of keys.

Base UI's styling (opens in a new tab) and composition (opens in a new tab) guides say more about className, style and render.

ValueField

ValueFieldReveal

ValueFieldCopy

ValueFieldRegenerate