{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "search",
  "type": "registry:ui",
  "title": "<ui-search>",
  "description": "Carbon-style search field (`Search`): a `role=\"search\"` landmark holding a visually hidden label, a magnifier, an `<input type=\"search\">` and a clear button that appears once there is text. Esc clears the text (and keeps focus), as in Carbon. The clear button is reachable with Tab. Copied from @purpurabog/ui 2.3.0; the package is the maintained source, this copy is yours to change. Icons from the Carbon Design System (Apache-2.0, © IBM Corp.; see THIRD-PARTY-NOTICES.md in the package).",
  "dependencies": [
    "lit@^3.3.0"
  ],
  "registryDependencies": [
    "@kanok-ui/shared-element",
    "@kanok-ui/shared-field",
    "@kanok-ui/shared-form-control",
    "@kanok-ui/shared-localize",
    "@kanok-ui/shared-skeleton",
    "@kanok-ui/tooltip",
    "@kanok-ui/tokens"
  ],
  "files": [
    {
      "path": "src/primitives/search/search-skeleton.ts",
      "type": "registry:ui",
      "target": "components/ui/primitives/search/search-skeleton.ts",
      "content": "import { html } from 'lit';\nimport { customElement, property } from 'lit/decorators.js';\nimport { fieldSkeletonStyles, fluidSkeletonBox, skeletonStyles, UiSkeletonElement } from '../shared/skeleton.ts';\nimport { hasData, syncFluid } from '../shared/field.ts';\n\n/**\n * Carbon `SearchSkeleton` (`cds-search-skeleton`): the shape of a `<ui-search>` while its data loads — one bar at the\n * field's height (sm 32 / md 40 / lg 48px); `fluid` (or inside `<ui-fluid-form>`) Carbon `FluidSearchSkeleton`: a 64px\n * box with two bars. Hidden from assistive tech.\n *\n * @csspart field - The bar (fluid: the box)\n * @csspart label - Fluid: the 25% bar\n * @csspart value - Fluid: the 50% bar\n */\n@customElement('ui-search-skeleton')\nexport class UiSearchSkeleton extends UiSkeletonElement {\n    static override readonly styles = [skeletonStyles, fieldSkeletonStyles];\n\n    @property({ reflect: true }) size: 'sm' | 'md' | 'lg' = 'md';\n\n    /** Carbon `FluidSearchSkeleton`. */\n    @property({ type: Boolean, reflect: true }) fluid = false;\n\n    override connectedCallback() {\n        super.connectedCallback();\n        syncFluid(this, this.fluid);\n    }\n\n    protected override willUpdate() {\n        syncFluid(this, this.fluid);\n    }\n\n    override render() {\n        if (hasData(this, 'fluid')) return fluidSkeletonBox;\n        return html`<div class=\"bone field\" part=\"field\"></div>`;\n    }\n}\n\ndeclare global {\n    interface HTMLElementTagNameMap {\n        'ui-search-skeleton': UiSearchSkeleton;\n    }\n}\n"
    },
    {
      "path": "src/primitives/search/search.styles.ts",
      "type": "registry:ui",
      "target": "components/ui/primitives/search/search.styles.ts",
      "content": "import { css } from 'lit';\n\n/** Styles of `<ui-search>`. */\nexport const searchStyles = css`\n    :host {\n        --_h: var(--ui-field-height-lg, 48px);\n\n        display: block;\n        font-family: var(--ui-font-family);\n    }\n\n    :host([size='sm']) {\n        --_h: var(--ui-field-height-sm, 32px);\n    }\n\n    :host([size='md']) {\n        --_h: var(--ui-field-height-md, 40px);\n    }\n\n    .search {\n        position: relative;\n        display: flex;\n        align-items: center;\n        width: 100%;\n    }\n\n    input {\n        box-sizing: border-box;\n        width: 100%;\n        height: var(--_h);\n        margin: 0;\n        padding: 0 var(--_h);\n        /* Carbon: an underline only; --ui-field-border (all sides), --ui-field-radius and --ui-field-background let a design outline the box */\n        border: var(--ui-field-border, none);\n        border-bottom: 1px solid var(--ui-field-underline-color, var(--ui-ink-subtle));\n        border-radius: var(--ui-field-radius, var(--ui-radius-none));\n        background-color: var(--ui-field-background, var(--ui-surface-1));\n        color: var(--ui-ink);\n        font: var(--ui-font-body-sm);\n        font-size: var(--ui-field-font-size, 14px);\n        letter-spacing: var(--ui-tracking-body);\n        text-overflow: ellipsis;\n        appearance: none;\n        outline: var(--ui-field-focus-width, 2px) solid transparent; /* the ring's width (Kanok: 1.5px, on the field's own border) */\n        outline-offset: calc(-1 * var(--ui-field-focus-width, 2px));\n        /* Carbon search-input: fast-02 (110ms), not the text input's fast-01 */\n        transition:\n            background-color var(--ui-duration-moderate) var(--ui-easing),\n            outline-color var(--ui-duration-moderate) var(--ui-easing);\n    }\n\n    input:hover:not(:disabled):not(:focus) {\n        border-color: var(--ui-field-hover-border-color, var(--ui-border-strong-1));\n        border-bottom-color: var(--ui-field-hover-border-color, var(--ui-border-strong-1));\n    }\n\n    input::-webkit-search-decoration,\n    input::-webkit-search-cancel-button,\n    input::-webkit-search-results-button,\n    input::-webkit-search-results-decoration {\n        display: none;\n        appearance: none;\n    }\n\n    input::placeholder {\n        color: var(--ui-ink-placeholder);\n        opacity: 1;\n    }\n\n    input:focus {\n        border-color: var(--ui-field-focus-border-color, inherit);\n        border-bottom-color: var(--ui-field-focus-border-color, var(--ui-ink-subtle));\n        outline-color: var(--ui-focus);\n        box-shadow: var(--ui-field-focus-halo, none); /* a design's halo outside the ring (Kanok: none) */\n    }\n\n    input:disabled {\n        border-color: var(--ui-field-disabled-border-color, currentColor currentColor transparent);\n        color: var(--ui-ink-disabled);\n        cursor: not-allowed;\n    }\n\n    input:disabled::placeholder {\n        color: var(--ui-ink-disabled);\n    }\n\n    .magnifier {\n        position: absolute;\n        z-index: 1;\n        inset-inline-start: calc((var(--_h) - 16px) / 2);\n        width: 16px;\n        height: 16px;\n        fill: var(--ui-ink-muted);\n        pointer-events: none;\n    }\n\n    input:disabled ~ .magnifier {\n        fill: var(--ui-ink-disabled);\n    }\n\n    .clear {\n        position: absolute;\n        inset-block: 0;\n        inset-inline-end: 0;\n        display: flex;\n        align-items: center;\n        justify-content: center;\n        width: var(--_h);\n        padding: 0;\n        border: 1px solid transparent;\n        background: transparent;\n        color: var(--ui-ink);\n        cursor: pointer; /* no transition: Carbon's search-close appears and tints at once */\n        border-radius: var(--ui-icon-control-radius, 0); /* round in a design that rounds icon controls (Kanok) */\n    }\n\n    .clear svg {\n        width: 16px;\n        height: 16px;\n        fill: currentColor;\n    }\n\n    .clear:hover {\n        background-color: var(--ui-ghost-hover);\n    }\n\n    .clear:focus-visible {\n        outline: var(--ui-focus-width, 2px) solid var(--ui-focus);\n        outline-offset: -2px;\n    }\n\n    .clear:active {\n        background-color: var(--ui-ghost-active);\n    }\n\n    /*\n     * Carbon: the field focused (it keeps focus while × is pressed), a hovered or pressed × keeps the field's 2px\n     * focus line — its fill is drawn inside it, 2px in from the top, bottom and end, under the icon\n     */\n    .clear svg {\n        position: relative;\n        z-index: 1;\n    }\n\n    input:focus ~ .clear:hover,\n    input:focus ~ .clear:active {\n        background-color: transparent;\n    }\n\n    input:focus ~ .clear:hover::after,\n    input:focus ~ .clear:active::after {\n        content: '';\n        position: absolute;\n        inset-block: 2px;\n        inset-inline: 0 2px;\n        background-color: var(--ui-ghost-hover);\n        pointer-events: none;\n    }\n\n    input:focus ~ .clear:active::after {\n        background-color: var(--ui-ghost-active);\n    }\n\n    /* Carbon search-close--hidden: present for layout, invisible and unreachable while empty */\n    .clear.hidden {\n        opacity: 0;\n        visibility: hidden;\n    }\n\n    input:disabled ~ .clear {\n        color: var(--ui-ink-disabled);\n        cursor: not-allowed;\n        background: transparent;\n    }\n\n    /* ---- expandable (Carbon cds--search--expandable) ---- */\n    :host([expandable]) {\n        transition: inline-size var(--ui-duration-fast) var(--ui-easing);\n    }\n\n    :host([expandable]:not([expanded])) {\n        inline-size: var(--_h);\n    }\n\n    :host([expandable]:not([expanded])) input {\n        padding: 0;\n        border: 0;\n        background: none;\n        transition: none; /* Carbon: transform (fast-01), which this input never changes */\n    }\n\n    /* Carbon search--expandable.search--expanded: only the padding moves in, at fast-01 */\n    :host([expandable][expanded]) input {\n        transition: padding var(--ui-duration-fast) var(--ui-easing);\n    }\n\n    :host([expandable]) input::placeholder {\n        opacity: 0;\n        transition: opacity var(--ui-duration-fast) var(--ui-easing);\n    }\n\n    :host([expandable][expanded]) input::placeholder {\n        opacity: 1;\n    }\n\n    .magnifier-tip {\n        position: absolute;\n        z-index: 1;\n        inset-block-start: 0;\n        inset-inline-start: 0;\n    }\n\n    :host([expanded]) .magnifier-tip,\n    :host([disabled]) .magnifier-tip {\n        pointer-events: none;\n    }\n\n    .magnifier-button {\n        display: flex;\n        align-items: center;\n        justify-content: center;\n        box-sizing: border-box;\n        inline-size: var(--_h);\n        block-size: var(--_h);\n        margin: 0;\n        padding: 0;\n        border: none;\n        border-radius: var(--ui-icon-control-radius, 0);\n        background: transparent;\n        color: inherit;\n        cursor: pointer;\n        outline: var(--ui-focus-width, 2px) solid transparent;\n        outline-offset: -2px;\n    }\n\n    .magnifier-button:hover {\n        background-color: var(--ui-canvas-hover);\n    }\n\n    .magnifier-button:focus {\n        outline-color: var(--ui-focus);\n    }\n\n    /* a mouse or touch focus shows no ring in a design that sets --ui-pointer-focus (Kanok: keyboard only) */\n    .magnifier-button:focus:not(:focus-visible) {\n        outline-color: var(--ui-pointer-focus, var(--ui-focus));\n    }\n\n    .magnifier-button .magnifier {\n        position: static;\n        fill: var(--ui-icon-primary);\n    }\n\n    :host([expanded]) .magnifier-button .magnifier {\n        fill: var(--ui-icon-secondary);\n    }\n\n    :host([disabled]) .magnifier-button {\n        cursor: not-allowed;\n    }\n\n    :host([disabled]) .magnifier-button:hover {\n        background-color: transparent;\n    }\n\n    :host([disabled]) .magnifier-button .magnifier {\n        fill: var(--ui-icon-disabled);\n    }\n\n    @media (prefers-reduced-motion: reduce) {\n        :host([expandable]),\n        :host([expandable]) input::placeholder {\n            transition: none;\n        }\n    }\n\n    @media (forced-colors: active) {\n        input {\n            border: 1px solid FieldText;\n        }\n        input:focus {\n            outline-color: Highlight;\n        }\n    }\n`;\n\n/** Styles of `<ui-search>` when fluid (`fluid`, or inside a `<ui-fluid-form>`): the 64px box with the label inside. */\nexport const searchFluidStyles = css`\n    :host([data-fluid]) {\n        --_h: 64px;\n    }\n\n    :host([data-fluid]) .label {\n        font: var(--ui-font-caption);\n        letter-spacing: var(--ui-tracking-caption);\n        color: var(--ui-ink-muted);\n    }\n\n    /* Carbon fluid search: visible label, magnifier at the end, clear button before it */\n    :host([data-fluid]) input {\n        padding: 32px 88px 13px var(--ui-space-md);\n    }\n\n    :host([data-fluid]) .magnifier {\n        inset-block-start: 35px;\n        inset-inline: auto var(--ui-space-md);\n    }\n\n    :host([data-fluid]) .clear {\n        inset-block: 24px auto;\n        block-size: 40px;\n        inline-size: 40px;\n        inset-inline-end: 48px;\n    }\n`;\n"
    },
    {
      "path": "src/primitives/search/search.ts",
      "type": "registry:ui",
      "target": "components/ui/primitives/search/search.ts",
      "content": "import { LitElement, html, nothing } from 'lit';\nimport { customElement, property, query } from 'lit/decorators.js';\nimport { srOnlyStyles, uid, submitOnEnter, barWhenDisabled, syncFluid, fluidFieldStyles, hasData } from '../shared/field.ts';\nimport { FormControlController } from '../shared/form-control.ts';\nimport { LocalizeController } from '../shared/localize.ts';\nimport { UiElement } from '../shared/element.ts';\nimport '../tooltip/tooltip.ts';\nimport { searchStyles, searchFluidStyles } from './search.styles.ts';\n\nexport type SearchSize = 'sm' | 'md' | 'lg';\n\nconst magnifierIcon = html`<svg class=\"magnifier\" part=\"magnifier\" viewBox=\"0 0 16 16\" aria-hidden=\"true\">\n    <path d=\"M15 14.3 10.7 10a5.5 5.5 0 1 0-.7.7l4.3 4.3.7-.7ZM2 6.5a4.5 4.5 0 1 1 9 0 4.5 4.5 0 0 1-9 0Z\" />\n</svg>`;\nconst closeIcon = html`<svg viewBox=\"0 0 16 16\" aria-hidden=\"true\"><path d=\"m12 4.7-.7-.7L8 7.3 4.7 4l-.7.7L7.3 8 4 11.3l.7.7L8 8.7l3.3 3.3.7-.7L8.7 8z\" /></svg>`;\n\n/**\n * Carbon-style search field (`Search`): a `role=\"search\"` landmark holding a visually hidden label,\n * a magnifier, an `<input type=\"search\">` and a clear button that appears once there is text.\n * Esc clears the text (and keeps focus), as in Carbon. The clear button is reachable with Tab.\n *\n * Geometry follows Carbon `_search.scss`: the field is as tall as its size (sm 32 / md 40 / lg 48),\n * icons are 16px, the input is padded by one field height on each side, the clear button is a\n * square of the field height at the end.\n *\n * Form-associated: submits `value` under `name`, resets with the form.\n *\n * `expandable` (Carbon `ExpandableSearch`): collapsed to its magnifier — a button named by a tooltip above it that shows\n * `label` (else the translation's \"Search\") — until clicked or Enter / Space, then it widens to the full width with the text box focused. Esc\n * clears the text, then collapses it and focuses the magnifier (as Carbon's web components); leaving it empty\n * collapses it too. `expanded` is the state (set it to open it yourself).\n *\n * State on the host for styling: `data-has-value` while there is text (read-only too).\n *\n * @cssstate has-value - While it holds a value (also `[data-has-value]`)\n * @fires input - On every keystroke\n * @fires change - When the value is committed (blur / Enter) or cleared\n * @fires ui-clear - After the clear button or Esc emptied the field\n * @fires ui-toggle - detail: { expanded } when an expandable search opens or collapses\n * @csspart base - The role=search wrapper\n * @csspart input - The native search input\n * @csspart label - The label (visually hidden, as in Carbon; shown inside the box when `fluid`)\n * @csspart magnifier - The search icon\n * @csspart clear-button - The clear button\n * @csspart magnifier-button - The magnifier of an expandable search\n * @cssprop --ui-field-border - Border on every side of the box (default none: Carbon's underline only; Kanok: a 1px outline)\n * @cssprop --ui-field-disabled-border-color - Border colour when disabled (default: the underline transparent)\n * @cssprop --ui-field-readonly-border-color - Border colour when read-only (default: a hairline underline)\n * @cssprop --ui-field-radius - Corner radius of the box (default 0; Kanok: 6px)\n * @cssprop --ui-field-background - Fill of the box (default `--ui-surface-1`; Kanok: transparent)\n * @cssprop --ui-label-font - Font of the label (default `--ui-font-caption`; Kanok: 14px semibold)\n * @cssprop --ui-label-color - Colour of the label (default `--ui-ink-muted`; Kanok: `--ui-ink`)\n * @cssprop --ui-icon-control-radius - Corners of its small icon buttons, their hover fill and ring (default 0; Kanok: round)\n */\n@customElement('ui-search')\nexport class UiSearch extends UiElement {\n    static override hostStates: readonly string[] = ['has-value'];\n\n    static readonly formAssociated = true;\n\n    static override readonly shadowRootOptions: ShadowRootInit = {\n        ...LitElement.shadowRootOptions,\n        delegatesFocus: true,\n    };\n\n    static override readonly styles = [\n        srOnlyStyles,\n        searchStyles,\n        fluidFieldStyles,\n        searchFluidStyles,\n    ];\n\n    /** Accessible name of the field (visually hidden, as in Carbon). */\n    @property() label = '';\n\n    private readonly localize = new LocalizeController(this);\n    @property() placeholder = '';\n    @property() value = '';\n    /** Reflected: form-associated elements submit under the `name` attribute. */\n    @property({ reflect: true }) name = '';\n    /** Field height: sm 32px, md 40px, lg 48px (tokens `--ui-field-height-*`). */\n    @property({ reflect: true }) size: SearchSize = 'md'; // Carbon default (40px)\n    /** Disables the control; a disabled `<fieldset>` ancestor does the same. */\n    @property({ type: Boolean, reflect: true }) disabled = false;\n    @property() autocomplete = 'off';\n\n    /** Passed to the text box: the virtual keyboard to show (`numeric`, `decimal`, `email`, `tel`, `url`, `search`…). */\n    @property() inputmode = '';\n\n    /** Passed to the text box: the label of the virtual keyboard's Enter key (`search`, `send`, `next`, `done`…). */\n    @property() enterkeyhint = '';\n    /** Accessible name of the clear button. */\n    @property({ attribute: 'clear-label' }) clearLabel = '';\n\n    /** Constraint validation like `<input type=\"search\">`: blocks submit and reports in the browser's bubble (Carbon Search has no error line). */\n    @property({ type: Boolean, reflect: true }) required = false;\n\n    @property() pattern = '';\n\n    @property({ type: Number }) minlength?: number;\n\n    @property({ type: Number }) maxlength?: number;\n\n    /** Value can be selected and submitted but not changed; no clear button. */\n    @property({ type: Boolean, reflect: true }) readonly = false;\n\n    /** Carbon `FluidSearch`: the label inside a 64px box. `<ui-fluid-form>` sets it for every field inside. */\n    @property({ type: Boolean, reflect: true }) fluid = false;\n\n    /** Carbon `ExpandableSearch`: collapsed to its magnifier until opened. */\n    @property({ type: Boolean, reflect: true }) expandable = false;\n\n    /** Whether an expandable search is open. */\n    @property({ type: Boolean, reflect: true }) expanded = false;\n\n    /** Disabled, reset defaults, validation on submit and the name given from outside (shared by the form fields). */\n    private readonly formControl = new FormControlController(this, { implicitSubmission: true });\n\n    @query('input') private readonly input!: HTMLInputElement;\n\n\n    /** Message from `setCustomValidity()`; '' = none. */\n    private customValidityMessage = '';\n\n    /** Like `<input>.setCustomValidity()`: a non-empty message makes the field invalid until cleared with ''. */\n    setCustomValidity(message: string) {\n        this.customValidityMessage = message;\n        if (this.hasUpdated) this.syncFormState();\n    }\n\n    private readonly ids = uid('ui-search');\n    private defaultValue = '';\n\n    /** Enter in the text box submits the form, like a native input. */\n    private readonly onEnterKey = (event: KeyboardEvent) => submitOnEnter(this, event);\n\n    protected override willUpdate() {\n        syncFluid(this, this.fluid);\n    }\n\n    override connectedCallback() {\n        super.connectedCallback();\n        syncFluid(this, this.fluid);\n        this.addEventListener('keydown', this.onEnterKey);\n        this.addEventListener('focusout', this.onFocusOut);\n        // first connection only: moving the element must not change what reset goes back to\n        this.formControl.captureDefaults(() => {\n            this.defaultValue = this.value;\n        });\n    }\n\n    override disconnectedCallback() {\n        super.disconnectedCallback();\n        this.removeEventListener('keydown', this.onEnterKey);\n        this.removeEventListener('focusout', this.onFocusOut);\n    }\n\n    get form() {\n        return this.internals.form;\n    }\n\n    get validity() {\n        return this.internals.validity;\n    }\n\n    get validationMessage() {\n        return this.internals.validationMessage;\n    }\n\n    /** Whether the field takes part in constraint validation (not while disabled), as natively. */\n    get willValidate() {\n        return this.internals.willValidate;\n    }\n\n    /** The `<label>`s that point at this field. */\n    get labels() {\n        return this.internals.labels;\n    }\n\n    checkValidity() {\n        return this.internals.checkValidity();\n    }\n\n    reportValidity() {\n        return this.formControl.reportValidity(this.internals);\n    }\n\n    protected override updated() {\n        this.syncFormState();\n        this.toggleAttribute('data-has-value', this.value !== '');\n    }\n\n    private syncFormState() {\n        if (barWhenDisabled(this.internals, this.isDisabled)) return;\n        this.internals.setFormValue(this.value);\n        if (this.customValidityMessage) this.internals.setValidity({ customError: true }, this.customValidityMessage, this.input);\n        else if (this.input.validity.valid) this.internals.setValidity({});\n        else this.internals.setValidity(this.input.validity, this.input.validationMessage, this.input);\n    }\n\n    formResetCallback() {\n        this.value = this.defaultValue;\n    }\n\n    formStateRestoreCallback(state: string | File | FormData | null) {\n        if (typeof state === 'string') this.value = state;\n    }\n\n    formDisabledCallback(disabled: boolean) {\n        this.formControl.setFieldsetDisabled(disabled);\n    }\n\n    private get isDisabled() {\n        return this.formControl.disabled;\n    }\n\n    private onInput(event: Event) {\n        this.value = (event.target as HTMLInputElement).value;\n    }\n\n    private onChange() {\n        this.dispatchEvent(new Event('change', { bubbles: true }));\n    }\n\n    /** Carbon: Esc clears while there is text and keeps the focus in the field; an empty expandable one collapses to its magnifier. */\n    private onKeydown(event: KeyboardEvent) {\n        if (event.key !== 'Escape') return;\n        if (this.value !== '' && !this.readonly) {\n            event.stopPropagation();\n            this.clear();\n        } else if (this.expandable && this.expanded) {\n            event.stopPropagation();\n            this.setExpanded(false);\n            void this.updateComplete.then(() => this.magnifierButton?.focus());\n        }\n    }\n\n    @query('.magnifier-button') private readonly magnifierButton?: HTMLElement;\n\n    private setExpanded(expanded: boolean) {\n        if (this.expanded === expanded) return;\n        this.expanded = expanded;\n        this.dispatchEvent(new CustomEvent('ui-toggle', { detail: { expanded }, bubbles: true, composed: true }));\n    }\n\n    /** Opens an expandable search and focuses its text box. */\n    private expand() {\n        if (!this.expandable || this.expanded || this.isDisabled) return;\n        this.setExpanded(true);\n        void this.updateComplete.then(() => this.input.focus());\n    }\n\n    private onMagnifierKeydown(event: KeyboardEvent) {\n        if (event.key !== 'Enter' && event.key !== ' ') return;\n        event.preventDefault();\n        event.stopPropagation(); // not the form's Enter\n        this.expand();\n    }\n\n    /**\n     * Leaving an empty expandable search collapses it. Checked once focus has settled: focus moving between the parts\n     * inside (the magnifier, the text box) reaches the host as a focusout with no relatedTarget too.\n     */\n    private readonly onFocusOut = () => {\n        if (!this.expandable || !this.expanded) return;\n        setTimeout(() => {\n            if (this.expanded && this.value === '' && !this.matches(':focus-within')) this.setExpanded(false);\n        });\n    };\n\n    private renderMagnifier() {\n        if (!this.expandable) return magnifierIcon;\n        const name = this.label || this.localize.t.field.search;\n        const collapsed = !this.expanded;\n        // a native button (Carbon draws a div with role=button); tabindex as Carbon's buttons, so Safari's Tab stops on it\n        return html`<ui-tooltip class=\"magnifier-tip\" as-label text=${name} placement=\"top\">\n            <button\n                class=\"magnifier-button\"\n                part=\"magnifier-button\"\n                type=\"button\"\n                tabindex=${collapsed ? '0' : '-1'}\n                aria-expanded=${this.expanded ? 'true' : 'false'}\n                aria-controls=${this.ids}\n                ?disabled=${this.isDisabled}\n                @click=${this.expand}\n                @keydown=${this.onMagnifierKeydown}\n            >\n                ${magnifierIcon}\n            </button>\n        </ui-tooltip>`;\n    }\n\n    /** Empties the field, keeps focus in it and announces the change (`input`, `change`, `ui-clear`). */\n    clear() {\n        if (this.isDisabled || this.readonly || this.value === '') return;\n        this.value = '';\n        this.input.focus();\n        this.dispatchEvent(new Event('input', { bubbles: true, composed: true }));\n        this.dispatchEvent(new Event('change', { bubbles: true }));\n        this.dispatchEvent(new CustomEvent('ui-clear', { bubbles: true, composed: true }));\n    }\n\n    /** No text to clear: the clear button hides. */\n    private get empty() {\n        return this.value === '' || this.readonly; // read-only: nothing to clear\n    }\n\n    override render() {\n        const empty = this.empty;\n        return html`\n            <div class=\"search\" part=\"base\" role=\"search\" aria-labelledby=\"${this.ids}-label\">\n                <label class=${hasData(this, 'fluid') ? 'label' : 'sr-only'} part=\"label\" id=\"${this.ids}-label\" for=${this.ids}>${this.label || this.formControl.fallbackName(this.label, this.internals) || this.localize.t.field.search}</label>\n                <input\n                    part=\"input\"\n                    id=${this.ids}\n                    type=\"search\"\n                    .value=${this.value}\n                    name=${this.name || nothing}\n                    placeholder=${(this.placeholder || this.localize.t.field.search) || nothing}\n                    autocomplete=${this.autocomplete}\n                    inputmode=${this.inputmode || nothing}\n                    enterkeyhint=${this.enterkeyhint || nothing}\n                    ?disabled=${this.isDisabled}\n                    ?readonly=${this.readonly}\n                    ?required=${this.required}\n                    tabindex=${this.expandable && !this.expanded ? '-1' : nothing}\n                    pattern=${this.pattern || nothing}\n                    minlength=${this.minlength ?? nothing}\n                    maxlength=${this.maxlength ?? nothing}\n                    @input=${this.onInput}\n                    @change=${this.onChange}\n                    @keydown=${this.onKeydown}\n                />\n                ${this.renderMagnifier()}\n                <!-- mousedown is cancelled so the input keeps focus: no stray native change before the clear -->\n                <button\n                    class=\"clear ${empty ? 'hidden' : ''}\"\n                    part=\"clear-button\"\n                    type=\"button\"\n                    aria-label=${this.clearLabel || this.localize.t.field.clearSearch}\n                    ?disabled=${this.isDisabled}\n                    tabindex=${empty ? -1 : nothing}\n                    @mousedown=${(e: Event) => e.preventDefault()}\n                    @click=${this.clear}\n                >\n                    ${closeIcon}\n                </button>\n            </div>\n        `;\n    }\n}\n\nexport interface UiSearchEventMap extends HTMLElementEventMap {\n    'ui-clear': CustomEvent<null>;\n    'ui-toggle': CustomEvent<{ expanded: boolean }>;\n}\n\n/** Typed listeners for UiSearch's events (declaration merging with the class). */\nexport interface UiSearch {\n    addEventListener<K extends keyof UiSearchEventMap>(type: K, listener: (this: UiSearch, event: UiSearchEventMap[K]) => unknown, options?: boolean | AddEventListenerOptions): void;\n    addEventListener(type: string, listener: EventListenerOrEventListenerObject, options?: boolean | AddEventListenerOptions): void;\n    removeEventListener<K extends keyof UiSearchEventMap>(type: K, listener: (this: UiSearch, event: UiSearchEventMap[K]) => unknown, options?: boolean | EventListenerOptions): void;\n    removeEventListener(type: string, listener: EventListenerOrEventListenerObject, options?: boolean | EventListenerOptions): void;\n}\n\ndeclare global {\n    interface HTMLElementTagNameMap {\n        'ui-search': UiSearch;\n    }\n}\n"
    }
  ]
}
