Skip to content
shadcn.io

shadcn.io is not affiliated with official shadcn/ui

Button Group examples Β· Advanced

Button Group with Select for React

Compound fields that join a select to fixed text, a country before a phone number and a protocol before a domain.

Framework
UI library

A select joined to a piece of text, for values that come in two parts. The first group picks a country, πŸ‡ΊπŸ‡Έ US, πŸ‡¬πŸ‡§ UK or πŸ‡ͺπŸ‡Ί EU, in front of a phone number; the second picks https:// or http:// in front of a domain. The first select is controlled, the second keeps its own value.

Preview

Preview width

Installation

Sign in to get your install command
Free with an account. It carries your token, so the CLI installs everything in one go.

FAQ

How is the country select controlled?

The demo keeps the country, starting at us, and updates it when the select changes.

Why does the protocol select have no state?

It starts on https with a default value and keeps its own selection. Read it on submit, or control it like the country select.

Is the phone number editable?

No. ButtonGroupText is fixed text that shares the group's border. Put an Input in its place for a real phone or domain field.

How are the selects named?

With aria-label, Country and Protocol, since they have no visible label. The label goes on SelectTrigger.

Will the flags show everywhere?

They're emoji. Some systems, such as Windows, show letter pairs instead of flags. Use flag images if that matters.

How wide is the select?

The trigger sizes to its value inside the group. Set a width class on SelectTrigger to fix it.