Skip to content
EspañolEnglish
All components (283)

Tax ID

Fields · TaxIdField

What it is and when to use it

A company's tax ID, the one that applies in the customer's country: NIF in Spain, EIN in the United States, CNPJ or CPF in Brazil, ABN in Australia, GSTIN in India… These are the 160 types Stripe accepts in 120 countries, each with its example.

When to use it

  • A company's purchase: place it below the billing address with country={address.country} and the field changes on its own when the country changes. Where nothing is asked, it renders nothing.
  • If the country has several types (the national one and the EU VAT number, the CNPJ and the CPF), a type picker appears first. types keeps only the accepted ones.
  • onChange delivers { type, value }, the same pair Stripe's API asks for.

When not to

  • Only an EU VAT number: VatField. Only a Spanish NIF, NIE or CIF: DocumentField.
  • Knowing whether the number is registered: the field says whether it can exist, not whether it does; that check belongs to the server and its error is passed through error.

What is checked: the EU VAT number, with each State's shape and check digit (it is VatField inside); the Spanish NIF, the Australian ABN, the Brazilian CNPJ and CPF, the Norwegian number and the Chilean RUT, with their check digit; the EIN, the Canadian BN and GST/HST, the UK VAT, the GSTIN, the RFC and the CUIT, by their shape. The rest, only that they are letters, digits and separators: rejecting a valid number is worse than letting an odd one through.

Keyboard: Tab goes from the type to the number. The error appears on leaving the field, not while typing.

Accessibility: each piece has its label, with the type's acronym (“Tax ID (EIN)”), and the example goes in the hint, not only as a placeholder.

Fine-tuning: no variables of its own: they are the field's, --amset-field-*. The block is positioned with amset-taxid.

What it looks like

import { TaxIdField } from "@amset/ui";

<TaxIdField country="ES" size="md" variant="outline" />

Props

Import it with import { TaxIdField } from '@amset/ui'. Required props are marked.

PropTypeWhat it does
countryrequiredstringThe customer's country (ISO code), usually the one from their billing address. It decides what is asked: the NIF in Spain, the EIN in the United States, the CNPJ or CPF in Brazil... In a country where nothing is asked, the field renders nothing.
classNamestringMerged with the library classes; it does not replace them.
defaultValueTaxId | nullThe type and the number to start with, uncontrolled.
disabledboolean—
errorstringAn external error (the server's). It takes precedence over the field's own check.
hintstring—
labelstringThe field name. By default, “Tax ID” with the type's acronym.
onChange(value: TaxId) => voidReports each change with the type and the number, in capitals: the same `{ type, value }` that Stripe asks for.
requiredboolean—
size"sm" | "md" | "lg"—
typesreadonly string[]Only these types (`['es_cif']` so as not to offer the EU VAT number). By default, all of the country's types.
valueTaxId | nullThe type and the number, controlled from outside.
variantFieldVariant—

It also accepts the attributes of the element it renders: className, style, data-*, aria-* and its events.

In the test bench

Every state and variant, to try one at a time, on its page at storybook.amsetui.com: