Skip to content

Clamp

Long content clamped to a few lines, with a button to show the rest.

TS
Tony Stark2h

I reproduced the double charge on staging. When a card needs 3-D Secure, the confirm step retries on the client after the redirect, and the webhook also finalizes the invoice. Both paths call finalizeInvoice, so we bill twice whenever the webhook wins the race.

The fix makes finalizing idempotent on the invoice ID and drops the client retry. It's in #2291, with a test that fires both paths within 50ms of each other. Refunds for the 14 customers affected go out tomorrow.

AP
Ada Park1h

Approved. Ship it behind the billing flag first.

Installation

  1. Add the registryOnce per project
  2. Add clamp

Usage

ClampContent shows the first lines lines, measured in its own line height, and fades out the last one. ClampTrigger shows only when there's more to show. That's measured rather than guessed, so short content gets neither the fade nor the button. Before the page loads in the browser, CSS clamps the content to lines lines, fades the last one and reserves space for the button, so long content already looks right in the server render. Content shorter than that gives the space back once it's measured.

Tabbing to a link in the hidden lines opens the content, so focus never lands on something out of sight. Screen readers read all of the content, whether it's open or not.

Composition

Examples

Lines and labels

lines sets how many lines show while the content is closed. Set more and less on ClampTrigger to change its labels.

What’s new in 4.2

  • Plan changes are self-serve, and take effect at the next invoice.
  • Metered usage is out of beta, with alerts at 80% and 100% of a limit.
  • SSO comes with every paid plan, through Okta, Google or Azure.
  • Audit logs export to your own S3 bucket every night.
  • Invoices come as PDFs in nine languages.
  • Webhooks retry with backoff for up to three days.

Props

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

Clamp

ClampContent

ClampTrigger

ClampTrigger takes the props of Button too, and is a ghost button by default.

useClamp

useClamp() reads the Clamp that your component renders in, and returns its state: