shadcn.io is not affiliated with official shadcn/ui
URL Input with Paste Cleanup Form Block for React
A website field with a fixed https:// in front that cleans what you paste, then reads the address with the browser's URL parser into Host, Path and Secure cells.
Installation
Overview
Take a web address the way people paste it, with this URL input form for React with Base UI. A compact header sits over a hairline frame with a plus mark on each corner: a field band and a band that shows how the address was read. The field is an Input Group with a fixed "https://" in front. Paste a whole address and a scheme is taken off (an http one is remembered), a trailing slash after the path goes, and the status line says what it did ("Removed http:// and a trailing slash."). The browser's own URL parser then reads what remains into three cells under the field: Host, Path with any query, and whether the address is secure ("Not secure: it will be saved as https."). Spaces are called out as you type; a missing dot, an empty field or something that is not an address waits until you leave the field or press Save, which puts focus back in it. It's built from Input Group, Input, Field, Shine Button and Guides, with a CSS entrance only. For a website, a portfolio, a link-in-bio or any field that takes an address.
FAQ
What exactly does the paste cleanup change?
When you paste a whole address (or the field is empty), it takes off a leading http:// or https:// and any trailing slash on the path, before a query or fragment, and trims the spaces around it; the query and the path are kept as they are. Typing is left alone except that a scheme you type in full is taken off, since a slash at the end may be the start of a path you are still typing. Leaving the field tidies it the same way, and the status line says what changed. A fragment pasted into the middle of a field is inserted as usual.
How is the address read?
By the browser's URL class, given https:// plus what is in the field. The Host cell shows its hostname (lower case, and punycode for an international domain), the Path cell the path with its query and fragment, and the Secure cell is about the scheme you pasted. The block also asks for a dot in the host and an ending of two letters or more, which URL alone does not. The cells hold their space, so they never move the panel.
Which problems are shown while I type, and which wait?
A space is certain to be wrong, so it is called out as you type. An empty field, a host without a dot and something that is not an address wait until you leave the field or press Save, since nobody is wrong halfway through typing a domain; after that the field re-checks as it changes. The message line is always in place, so it never moves the button, and the field points to it and is marked invalid while a problem shows.
Why a text input and not type=url?
A type="url" field trims what it holds and, on some browsers, quietly refuses what it dislikes, which would hide the very mistakes this block names (a space in the middle of a paste). The field is plain text with inputmode="url", so phones show a keyboard with a slash and a dot, autocomplete="url", no automatic capitals and no spell check.
Is the address checked or saved?
No. Nothing is fetched or sent, so a well-formed address that does not exist still passes: the block checks the shape, not that the site is there. For a real app, check reachability on your server if it matters, store the address as https only, and treat an http:// paste as the reason to say so, as this block does.
How do I connect it to react-hook-form or TanStack Form?
Store the cleaned value, without the scheme, or https:// plus it. With react-hook-form, use Controller, call field.onChange with the cleaned value from the paste and blur handlers, move issueOf into a resolver and use mode: "onBlur" for the same timing. With TanStack Form, give the field onBlur and onChange validators and use field.handleChange for the cleaned value.
Related
- Pro
Text Input with Address Preview Form
Text fieldsA form panel with one required project-name field that shows the web address it will get as you type, flags a name that is taken or past 50 characters, and offers the next free address.
- Pro
Phone Input with Country Code Form
Numbers and pickersA national-number field joined to a country menu that formats the digits for the chosen country as you type, checks the count per country and shows how the number would be stored.
- Pro
Email and Password Form
Text fieldsThe sign-in pair done well: an email named for password managers, a password with a reveal button and a Caps Lock warning, one generic failure that never says which half was wrong, and a quiet band with the demo account.
- Pro
Resume Drop Contact
ApplicationsA robotics hiring form that starts with a single PDF dropzone, then a role combobox, a start date and an optional LinkedIn field.
- Pro
Minimal Single Question Form
Text fieldsThe calmest form: one page with a mark, a heading that asks one question, one field with a hidden label and one full-width button, with the answer or the one problem shown under the field.
- Pro
Password Strength Form
Text fieldsA master-password form with advice instead of a checklist: a four-segment meter, one sentence that names the weakest thing about what is typed, a polite confirm field and a side cell that explains the four segments.