import { SvelteComponentTyped } from "svelte"; import type { SvelteHTMLElements } from "svelte/elements"; type $RestProps = SvelteHTMLElements["input"]; type $Props = { /** * Specify the tags. * Follows the field when the owning form resets. * @default [] */ value?: string[]; /** * Set the size of the field. Tags scale with it. * Inherits the parent `Form` size when unset. * Also accepts Carbon v11's `"md"` (the 40px default, which overrides a * `Form` size) and `"lg"` (`"xl"`). */ size?: "xs" | "sm" | "md" | "lg" | "xl" | undefined; /** * Specify the placeholder text * @default "" */ placeholder?: string; /** * Set to `true` to disable the field and its tags * @default false */ disabled?: boolean; /** * Set to `true` to show the tags without letting users add or remove any * @default false */ readonly?: boolean; /** * Set to `true` to require at least one tag * @default false */ required?: boolean; /** * Specify the label text * @default "" */ labelText?: string; /** * Set to `true` to visually hide the label text * @default false */ hideLabel?: boolean; /** * Specify the helper text * @default "" */ helperText?: string; /** * Set to `true` to indicate an invalid state * @default false */ invalid?: boolean; /** * Specify the invalid state text * @default "" */ invalidText?: string; /** * Set to `true` to indicate a warning state * @default false */ warn?: boolean; /** * Specify the warning state text * @default "" */ warnText?: string; /** * Where the tags render: `"inline"` inside the field, ahead of the text * input, or `"below"` the field, for long lists. * @default "inline" */ tagPlacement?: "inline" | "below"; /** * Characters (or a pattern) that split typed or pasted text into tags. * Enter always adds the current text; pasted line breaks always split. * @default "," */ delimiter?: string | string[] | RegExp; /** * Set to `false` to paste text as-is instead of splitting it into tags * @default true */ addOnPaste?: boolean; /** * Set to `true` to add the current text as a tag when the field loses focus * @default false */ addOnBlur?: boolean; /** * Transform raw text into a tag before it's checked and added. * Return an empty string to skip it. * @default (raw) => raw.trim() */ normalize?: (raw: string) => string; /** * Set to `true` to allow the same tag more than once * @default false */ allowDuplicates?: boolean; /** * Decide whether two tags are duplicates. * Defaults to a case-insensitive comparison. * @default (a, b) => a.toLowerCase() === b.toLowerCase() */ isDuplicate?: (a: string, b: string) => boolean; /** * Check a tag before it's added. Return `true` to accept it, or a message * to reject it. Returning `false` rejects it with `invalidTagText`. * @default () => true */ validate?: (tag: string) => boolean | string; /** * Maximum number of tags. */ max?: number | undefined; /** * Specify the accessible name prefix of each tag's remove button * @default "Remove" */ removeTagText?: string; /** * Specify the message shown when a duplicate tag is rejected * @default "This tag has already been added" */ duplicateText?: string; /** * Specify the validation message shown when `required` blocks a form * that has text in the field but no tags yet. * @default "Add at least one tag" */ requiredText?: string; /** * Specify the message shown when `validate` rejects a tag without one * @default "This tag isn't valid" */ invalidTagText?: string; /** * Specify the message shown when a tag is rejected at `max` * @default "You've reached the maximum number of tags" */ maxText?: string; /** * Specify the visually hidden keyboard instructions read with the field * @default "Press Enter to add a tag. Press Backspace in an empty field to move to the tags, then Delete to remove one." */ instructionsText?: string; /** * Announcement after tags are added. * @default (tags, count) => `${tags.length === 1 ? tags[0] : `${tags.length} tags`} added. ${count} ${count === 1 ? "tag" : "tags"}.` */ addedText?: (tags: string[], count: number) => string; /** * Announcement after a tag is removed. * @default (tag, count) => `${tag} removed. ${count} ${count === 1 ? "tag" : "tags"}.` */ removedText?: (tag: string, count: number) => string; /** * Set an id for the text input * @default uniqueId() */ id?: string; /** * Specify a name to submit each tag as a hidden input with the form. */ name?: string | undefined; /** * Obtain a reference to the text input element. * @default null */ ref?: null | HTMLInputElement; labelChildren?: (this: void) => void; tag?: (this: void, ...args: [{ tag: string; index: number; props: { filter: boolean; disabled: boolean; value: string; title: string; maxWidth: string; }; }]) => void; [key: `data-${string}`]: unknown; }; export type TagInputProps = Omit<$RestProps, keyof $Props> & $Props; export default class TagInput extends SvelteComponentTyped< TagInputProps, { /** Cancelable. Dispatched before a tag is added; call `preventDefault()` to keep it out. */ add: CustomEvent<{ value: string; source: "enter" | "delimiter" | "paste" | "blur" }>; blur: WindowEventMap["blur"]; /** Dispatched after tags are added or removed. */ change: CustomEvent; focus: WindowEventMap["focus"]; /** Dispatched when a value is rejected. */ invalid: CustomEvent<{ value: string; reason: "duplicate" | "max" | "validate"; message?: string }>; keydown: WindowEventMap["keydown"]; /** Cancelable. Dispatched before a tag is removed; call `preventDefault()` to keep it. */ remove: CustomEvent<{ value: string; index: number }>; }, { labelChildren: Record; tag: { tag: string; index: number; props: { filter: boolean; disabled: boolean; value: string; title: string; maxWidth: string; }; }; } > {}