# Angular SmartPasteButton Component

SmartPasteButton fills a form from the text in the clipboard, such as an email or a signature, with AI. It describes the fields of the closest reactive, template-driven or Signal Forms form to the model, checks and converts the values it returns, and announces the filled fields. It works with any model through a small adapter to your own backend.

## Basic

Put the button in a form. It reads the clipboard, sends the text with a description of the fields of the form to the adapter, and fills the fields with the values of the answer. Copy the signature below, then press Smart paste . When the browser does not give access to the clipboard, a dialog asks to paste the text. The demos of this page answer offline with fakeAIAssistAdapter , which reads the text with a few regular expressions; the Adapter section plugs a real model.

```typescript
import { Component } from '@angular/core';
import { FormControl, FormGroup, ReactiveFormsModule } from '@angular/forms';
import { fakeAIAssistAdapter } from '@exhaustive-ui/core/aiassist';
import { InputTextModule } from '@exhaustive-ui/core/inputtext';
import { SmartPasteButtonModule } from '@exhaustive-ui/core/smartpastebutton';

@Component({
    template: `
        <div class="card flex flex-col gap-6">
            <blockquote class="m-0 p-4 rounded-md bg-surface-100 dark:bg-surface-800 text-sm whitespace-pre-line select-all" aria-label="Sample signature">{{ sample }}</blockquote>
            <form [formGroup]="contact" class="grid grid-cols-1 sm:grid-cols-2 gap-4">
                <div class="flex flex-col gap-2">
                    <label for="sp-name">Full name</label>
                    <input pInputText id="sp-name" formControlName="name" autocomplete="off" />
                </div>
                <div class="flex flex-col gap-2">
                    <label for="sp-company">Company</label>
                    <input pInputText id="sp-company" formControlName="company" autocomplete="off" />
                </div>
                <div class="flex flex-col gap-2">
                    <label for="sp-email">Email</label>
                    <input pInputText id="sp-email" type="email" formControlName="email" autocomplete="off" />
                </div>
                <div class="flex flex-col gap-2">
                    <label for="sp-phone">Phone</label>
                    <input pInputText id="sp-phone" type="tel" formControlName="phone" autocomplete="off" />
                </div>
                <div class="sm:col-span-2">
                    <p-smart-paste-button [adapter]="adapter" />
                </div>
            </form>
        </div>
    `,
    standalone: true,
    imports: [SmartPasteButtonModule, InputTextModule, ReactiveFormsModule]
})
export class SmartpastebuttonBasicDemo {
    sample = `Amy Elsner
Head of Design, Northwind Traders
amy.elsner@northwind.example · +1 555 0134`;

    contact = new FormGroup({
        name: new FormControl(''),
        company: new FormControl(''),
        email: new FormControl(''),
        phone: new FormControl('')
    });

    adapter = fakeAIAssistAdapter({
        respond: ({ text }) => {
            const lines = text.split('\n').map((line) => line.trim());
            return {
                name: lines[0],
                company: lines[1]?.split(',')[1]?.trim(),
                email: text.match(/[\w.+-]+@[\w-]+(\.[\w-]+)+/)?.[0],
                phone: text.match(/\+?\d[\d\s().-]{6,}\d/)?.[0]
            };
        }
    });
}
```

## Adapter

SmartPasteButton sends no request of its own: an adapter connects it to the model of your choice, through an endpoint of your application that holds the API key. Never put the key in the browser. The request has the smart-paste task, the pasted text , instructions that ask for a JSON object, and a context with the described fields and the date of today , to read relative dates such as "next Monday". The answer is an object of values by field name, or its JSON text, even inside a Markdown code block or streamed in chunks. Give the adapter to the button with adapter , or to all the components with provideAIAssist ; the same endpoint serves InlineAIAssist and SmartTextarea. The AbortSignal of the request cancels it when the user presses Stop . The request sent for the form of the Fields section looks like this:

## Fields and Preview

Each field is described to the model by its name, its label (a label element, aria-labelledby or aria-label ), its type, taken from the input or the value of the control, its options for a select , and whether it is required. The pSmartPasteField directive adds a description, for example to tell a date of birth from the date of a message, and can set the smartPasteLabel , the smartPasteType and the smartPasteOptions of a component such as Select, or leave a field out with smartPasteIgnore . The fields property does the same by name, without touching the template. The answer is checked before it is applied: unknown, disabled and read-only fields are skipped, values are converted to the type of the field ("36 years" to 36, "yes" to true, a date written in words to a Date, a label to the value of its option), and a value that cannot be converted is dropped. Fields that hold a value are kept unless overwrite is set. With confirm , a dialog lists the values to apply first.

```typescript
import { Component } from '@angular/core';
import { FormControl, FormGroup, ReactiveFormsModule } from '@angular/forms';
import { fakeAIAssistAdapter } from '@exhaustive-ui/core/aiassist';
import { DatePickerModule } from '@exhaustive-ui/core/datepicker';
import { InputNumberModule } from '@exhaustive-ui/core/inputnumber';
import { InputTextModule } from '@exhaustive-ui/core/inputtext';
import { SelectModule } from '@exhaustive-ui/core/select';
import { SmartPasteButtonModule } from '@exhaustive-ui/core/smartpastebutton';

@Component({
    template: `
        <div class="card flex flex-col gap-6">
            <blockquote class="m-0 p-4 rounded-md bg-surface-100 dark:bg-surface-800 text-sm select-all" aria-label="Sample message">{{ sample }}</blockquote>
            <form [formGroup]="order" class="grid grid-cols-1 sm:grid-cols-2 gap-4">
                <div class="flex flex-col gap-2">
                    <label for="sp-customer">Customer</label>
                    <input pInputText id="sp-customer" formControlName="customer" autocomplete="off" />
                </div>
                <div class="flex flex-col gap-2">
                    <label for="sp-country">Delivery country</label>
                    <p-select
                        inputId="sp-country"
                        formControlName="country"
                        [options]="countries"
                        optionLabel="name"
                        optionValue="code"
                        placeholder="Choose a country"
                        pSmartPasteField
                        [smartPasteOptions]="countries"
                        smartPasteOptionLabel="name"
                        smartPasteOptionValue="code"
                    />
                </div>
                <div class="flex flex-col gap-2">
                    <label for="sp-quantity">Quantity</label>
                    <p-input-number inputId="sp-quantity" formControlName="quantity" [min]="1" pSmartPasteField smartPasteType="number" />
                </div>
                <div class="flex flex-col gap-2">
                    <label for="sp-delivery">Delivery date</label>
                    <p-date-picker inputId="sp-delivery" formControlName="delivery" dateFormat="yy-mm-dd" pSmartPasteField="The date the customer wants the order delivered, not the date of the message" smartPasteType="date" />
                </div>
                <div class="sm:col-span-2">
                    <p-smart-paste-button [adapter]="adapter" [confirm]="true" [fields]="{ customer: { description: 'The company that places the order' } }" />
                </div>
            </form>
        </div>
    `,
    standalone: true,
    imports: [SmartPasteButtonModule, InputTextModule, InputNumberModule, SelectModule, DatePickerModule, ReactiveFormsModule]
})
export class SmartpastebuttonFieldsDemo {
    sample = 'Hello, this is Bernardo from Globex Corporation, sent on 2026-11-30. Could you send us 12 units, delivered in Germany on December 15, 2026? Thanks!';

    countries = [
        { name: 'France', code: 'FR' },
        { name: 'Germany', code: 'DE' },
        { name: 'Italy', code: 'IT' },
        { name: 'Spain', code: 'ES' }
    ];

    order = new FormGroup({
        customer: new FormControl(''),
        country: new FormControl<string | null>(null),
        quantity: new FormControl<number | null>(null),
        delivery: new FormControl<Date | null>(null)
    });

    adapter = fakeAIAssistAdapter({
        respond: ({ text }) => ({
            customer: text.match(/from ([A-Z][\w ]+?)(,|\.| sent)/)?.[1],
            country: this.countries.find((country) => text.includes(country.name))?.name,
            quantity: text.match(/(\d+) units?/)?.[0],
            delivery: text.match(/on ((January|February|March|April|May|June|July|August|September|October|November|December) \d{1,2}, \d{4})/)?.[1]
        })
    });
}
```

## Forms: Template Driven

In a template-driven form, the button fills the ngModel fields of the closest form , and the properties they are bound to.

```typescript
import { Component } from '@angular/core';
import { FormsModule } from '@angular/forms';
import { fakeAIAssistAdapter } from '@exhaustive-ui/core/aiassist';
import { CheckboxModule } from '@exhaustive-ui/core/checkbox';
import { InputTextModule } from '@exhaustive-ui/core/inputtext';
import { SmartPasteButtonModule } from '@exhaustive-ui/core/smartpastebutton';

@Component({
    template: `
        <div class="card flex flex-col gap-6">
            <blockquote class="m-0 p-4 rounded-md bg-surface-100 dark:bg-surface-800 text-sm select-all" aria-label="Sample request">{{ sample }}</blockquote>
            <form class="flex flex-col gap-4">
                <div class="flex flex-col gap-2">
                    <label for="sp-td-city">City</label>
                    <input pInputText id="sp-td-city" name="city" [(ngModel)]="city" autocomplete="off" />
                </div>
                <div class="flex flex-col gap-2">
                    <label for="sp-td-guests">Guests</label>
                    <input pInputText id="sp-td-guests" name="guests" type="number" [(ngModel)]="guests" autocomplete="off" />
                </div>
                <div class="flex items-center gap-2">
                    <p-checkbox inputId="sp-td-parking" name="parking" [(ngModel)]="parking" [binary]="true" />
                    <label for="sp-td-parking">Parking needed</label>
                </div>
                <div><p-smart-paste-button [adapter]="adapter" /></div>
            </form>
        </div>
    `,
    standalone: true,
    imports: [SmartPasteButtonModule, InputTextModule, CheckboxModule, FormsModule]
})
export class SmartpastebuttonTemplatedrivenformsDemo {
    sample = 'We are four colleagues coming to Lyon next week, and we will need a parking space for our car.';

    city = '';

    guests: number | null = null;

    parking = false;

    adapter = fakeAIAssistAdapter({
        respond: ({ text }) => ({
            city: text.match(/to ([A-Z]\w+)/)?.[1],
            guests: ({ two: 2, three: 3, four: 4, five: 5 } as Record<string, number>)[text.match(/(two|three|four|five)/)?.[1] ?? ''],
            parking: /parking/i.test(text)
        })
    });
}
```

## Signal Forms

With Angular Signal Forms , give the field tree to for . The values are written to the fields, which are marked as dirty, so that the validation of the form applies to them as if they had been typed.

```typescript
import { Component, signal } from '@angular/core';
import { email, form, FormField, required } from '@angular/forms/signals';
import { fakeAIAssistAdapter } from '@exhaustive-ui/core/aiassist';
import { InputTextModule } from '@exhaustive-ui/core/inputtext';
import { MessageModule } from '@exhaustive-ui/core/message';
import { SmartPasteButtonModule } from '@exhaustive-ui/core/smartpastebutton';

@Component({
    template: `
        <div class="card flex flex-col gap-6">
            <blockquote class="m-0 p-4 rounded-md bg-surface-100 dark:bg-surface-800 text-sm select-all" aria-label="Sample email">{{ sample }}</blockquote>
            <form novalidate class="flex flex-col gap-4">
                <div class="flex flex-col gap-2">
                    <label for="sp-sf-name">Name</label>
                    <input pInputText id="sp-sf-name" [formField]="signup.name" autocomplete="off" />
                </div>
                <div class="flex flex-col gap-2">
                    @let address = signup.email();
                    <label for="sp-sf-email">Email</label>
                    <input pInputText id="sp-sf-email" type="email" [formField]="signup.email" autocomplete="off" />
                    @if (address.invalid() && address.dirty()) {
                        <p-message severity="error" size="small" variant="simple">Enter a valid email address.</p-message>
                    }
                </div>
                <div><p-smart-paste-button [for]="signup" [adapter]="adapter" /></div>
            </form>
        </div>
    `,
    standalone: true,
    imports: [SmartPasteButtonModule, InputTextModule, MessageModule, FormField]
})
export class SmartpastebuttonSignalformsDemo {
    sample = 'Hi, I am Ioni Bowcher, please register me with ioni.bowcher at example dot com.';

    model = signal({ name: '', email: '' });

    signup = form(this.model, (path) => {
        required(path.name);
        required(path.email);
        email(path.email);
    });

    adapter = fakeAIAssistAdapter({
        respond: ({ text }) => {
            const spelled = text.match(/(\S+) at (\S+) dot (\w+)/);
            return {
                name: text.match(/I am ([A-Z]\w+ [A-Z]\w+)/)?.[1],
                email: spelled ? `${spelled[1]}@${spelled[2]}.${spelled[3]}` : undefined
            };
        }
    });
}
```

## Accessibility

Screen Reader SmartPasteButton is a native button named by its text, "Smart paste", which becomes its aria-label with iconOnly ; its icon is hidden from assistive technologies. While the form is filled, the button reads "Stop" and the component is aria-busy . A polite live region then announces the result, such as "4 fields filled: Full name, Company, Email, Phone", or the error, which is also shown next to the button with a retry button. The paste dialog and the preview dialog are native modal dialogs, named by their title and described by their instructions; the focus moves into them and returns to the button when they close. In the preview, each value is a checkbox labelled by the name of the field and the value, with the value it replaces. The fields that were filled are marked with a data-p-smart-pasted attribute, highlighted until they are edited. The texts are translated with labels , and the smartPaste and smartPasteFilled keys of the aria translation.

## Smart Paste Button

SmartPasteButton fills a form from the text of the clipboard, such as an email, a signature or an invoice, with the model of your choice: it describes the fields of the form, asks the adapter for their values, then writes the values it can check. It works with reactive forms, template-driven forms and Signal Forms.

### Props

| Name | Type | Default | Description |
|------|------|---------|-------------|
| dt | Object | undefined | Defines scoped design tokens of the component. |
| unstyled | boolean | undefined | Indicates whether the component should be rendered without styles. |
| pt | SmartPasteButtonPassThrough | undefined | Used to pass attributes to DOM elements inside the component. |
| ptOptions | PassThroughOptions | undefined | Used to configure passthrough(pt) options of the component. |
| for | SmartPasteTarget | - | The form to fill: a FormGroup, a FormGroupDirective, an NgForm or a Signal Forms FieldTree. Defaults to the form around the button. |
| adapter | AIAssistAdapter \| AIAssistCompleteFn | - | Adapter that asks the model, or its complete function. Defaults to the one given to provideAIAssist. |
| fields | Record<string, SmartPasteFieldSettings> | - | Settings of the fields by name: a label, a description, a type, the allowed values, or ignore to leave a field out. |
| overwrite | boolean | false | Whether the fields that already have a value can be replaced. By default only the empty fields are filled. |
| confirm | boolean | false | Whether the values are shown in a dialog to check before they are written. |
| clipboard | boolean | true | Whether the clipboard is read. When false, or when the browser refuses, a dialog asks to paste the text. |
| highlight | boolean | true | Whether the filled fields are highlighted until they are edited, through a data-p-smart-pasted attribute. |
| maxTextLength | number | 8000 | Maximum length of the text sent to the model. |
| iconOnly | boolean | false | Whether the button only shows the icon. Its text is then its accessible name. |
| severity | ButtonSeverity | 'secondary' | Defines the style of the button, as in Button. |
| variant | "text" \| "outlined" | 'outlined' | Specifies the variant of the button, as in Button. |
| size | "small" \| "large" | - | Defines the size of the button. |
| rounded | boolean | false | Add a circular border radius to the button. |
| disabled | boolean | false | When present, it specifies that the button should be disabled. |
| tabindex | number | - | Index of the button in the tab order. |
| announce | boolean | true | Whether the progress and the result are announced to screen readers through a polite live region. |
| labels | Partial<SmartPasteButtonLabels> | - | Texts of the component, merged with the translation and the defaults. |

### Emits

| Name | Parameters | Description |
|------|------------|-------------|
| onFill | event: SmartPasteFillEvent | Callback to invoke when the values are written in the form. |
| onError | event: SmartPasteErrorEvent | Callback to invoke when the smart paste fails. |

### Methods

| Name | Parameters | Return Type | Description |
|------|------------|-------------|-------------|
| toggle |  | void | Reads the clipboard and fills the form, or stops the request in progress. |
| paste |  | void | Reads the clipboard and fills the form with its text. Opens a dialog to paste the text when the clipboard cannot be read. |
| fill | text: string | void | Fills the form from a text, without the clipboard. |
| retry |  | void | Sends the last text again. |
| stop |  | void | Stops the request in progress. |
| describeFields |  | void | Describes the fields of the form as they are sent to the model. |

## Pass Through Options

| Name | Type | Description |
|------|------|-------------|
| host | PassThroughOption<HTMLElement, I> | Used to pass attributes to the host's DOM element. |
| root | PassThroughOption<HTMLElement, I> | Used to pass attributes to the root's DOM element. |
| pcButton | ButtonPassThrough | Used to pass attributes to the Button component. |
| icon | PassThroughOption<SVGElement, I> | Used to pass attributes to the icon. |
| error | PassThroughOption<HTMLSpanElement, I> | Used to pass attributes to the error message and its retry button. |
| pcRetryButton | ButtonPassThrough | Used to pass attributes to the Retry button. |
| dialog | PassThroughOption<HTMLDialogElement, I> | Used to pass attributes to the dialog, to paste the text when the clipboard cannot be read, or to check the values. |
| dialogTitle | PassThroughOption<HTMLHeadingElement, I> | Used to pass attributes to the title of the dialog. |
| dialogDescription | PassThroughOption<HTMLParagraphElement, I> | Used to pass attributes to the text under the title of the dialog. |
| pasteInput | PassThroughOption<HTMLTextAreaElement, I> | Used to pass attributes to the textarea where the text is pasted. |
| previewList | PassThroughOption<HTMLUListElement, I> | Used to pass attributes to the list of values to check. |
| previewItem | PassThroughOption<HTMLLIElement, I> | Used to pass attributes to a value to check. |
| dialogFooter | PassThroughOption<HTMLDivElement, I> | Used to pass attributes to the buttons of the dialog. |
| pcDialogButton | ButtonPassThrough | Used to pass attributes to the buttons of the dialog. |
| liveRegion | PassThroughOption<HTMLSpanElement, I> | Used to pass attributes to the live region. |

## Theming

### CSS Classes

| Class | Description |
|-------|-------------|
| p-smartpastebutton | Class name of the root element |
| p-smartpastebutton-busy | Class name of the root element while the form is filled |
| p-smartpastebutton-error | Class name of the root element after an error |
| p-smartpastebutton-button | Class name of the button element |
| p-smartpastebutton-icon | Class name of the icon element |
| p-smartpastebutton-error-message | Class name of the error message |
| p-smartpastebutton-dialog | Class name of the dialog |
| p-smartpastebutton-dialog-title | Class name of the title of the dialog |
| p-smartpastebutton-dialog-description | Class name of the text under the title of the dialog |
| p-smartpastebutton-paste-input | Class name of the textarea where the text is pasted |
| p-smartpastebutton-preview-list | Class name of the list of values to check |
| p-smartpastebutton-preview-item | Class name of a value to check |
| p-smartpastebutton-preview-label | Class name of the label of a value to check |
| p-smartpastebutton-preview-value | Class name of a value to check |
| p-smartpastebutton-dialog-footer | Class name of the buttons of the dialog |

### Design Tokens

| Token | CSS Variable | Description |
|-------|--------------|-------------|
| smartpastebutton.gap | --p-smartpastebutton-gap | Gap of root |
| smartpastebutton.transition.duration | --p-smartpastebutton-transition-duration | Transition duration of root |
| smartpastebutton.icon.size | --p-smartpastebutton-icon-size | Size of the icon |
| smartpastebutton.error.color | --p-smartpastebutton-error-color | Color of the error message |
| smartpastebutton.dialog.width | --p-smartpastebutton-dialog-width | Width of the dialog |
| smartpastebutton.dialog.padding | --p-smartpastebutton-dialog-padding | Padding of the dialog |
| smartpastebutton.dialog.gap | --p-smartpastebutton-dialog-gap | Gap of the dialog |
| smartpastebutton.dialog.background | --p-smartpastebutton-dialog-background | Background of the dialog |
| smartpastebutton.dialog.border.color | --p-smartpastebutton-dialog-border-color | Border color of the dialog |
| smartpastebutton.dialog.border.radius | --p-smartpastebutton-dialog-border-radius | Border radius of the dialog |
| smartpastebutton.dialog.color | --p-smartpastebutton-dialog-color | Color of the dialog |
| smartpastebutton.dialog.shadow | --p-smartpastebutton-dialog-shadow | Shadow of the dialog |
| smartpastebutton.dialog.backdrop | --p-smartpastebutton-dialog-backdrop | Backdrop of the dialog |
| smartpastebutton.dialog.title.font.size | --p-smartpastebutton-dialog-title-font-size | Title font size of the dialog |
| smartpastebutton.dialog.title.font.weight | --p-smartpastebutton-dialog-title-font-weight | Title font weight of the dialog |
| smartpastebutton.dialog.description.color | --p-smartpastebutton-dialog-description-color | Description color of the dialog |
| smartpastebutton.paste.input.padding | --p-smartpastebutton-paste-input-padding | Padding of the textarea where the text is pasted |
| smartpastebutton.paste.input.background | --p-smartpastebutton-paste-input-background | Background of the textarea where the text is pasted |
| smartpastebutton.paste.input.border.color | --p-smartpastebutton-paste-input-border-color | Border color of the textarea where the text is pasted |
| smartpastebutton.paste.input.border.radius | --p-smartpastebutton-paste-input-border-radius | Border radius of the textarea where the text is pasted |
| smartpastebutton.paste.input.color | --p-smartpastebutton-paste-input-color | Color of the textarea where the text is pasted |
| smartpastebutton.paste.input.focus.border.color | --p-smartpastebutton-paste-input-focus-border-color | Focus border color of the textarea where the text is pasted |
| smartpastebutton.paste.input.focus.ring.width | --p-smartpastebutton-paste-input-focus-ring-width | Focus ring width of the textarea where the text is pasted |
| smartpastebutton.paste.input.focus.ring.style | --p-smartpastebutton-paste-input-focus-ring-style | Focus ring style of the textarea where the text is pasted |
| smartpastebutton.paste.input.focus.ring.color | --p-smartpastebutton-paste-input-focus-ring-color | Focus ring color of the textarea where the text is pasted |
| smartpastebutton.preview.gap | --p-smartpastebutton-preview-gap | Gap of the list of values to check |
| smartpastebutton.preview.check.color | --p-smartpastebutton-preview-check-color | Check color of the list of values to check |
| smartpastebutton.preview.label.font.weight | --p-smartpastebutton-preview-label-font-weight | Label font weight of the list of values to check |
| smartpastebutton.preview.value.color | --p-smartpastebutton-preview-value-color | Value color of the list of values to check |
| smartpastebutton.filled.ring.width | --p-smartpastebutton-filled-ring-width | Ring width of the filled fields |
| smartpastebutton.filled.ring.color | --p-smartpastebutton-filled-ring-color | Ring color of the filled fields |

