@constructor-io/constructorio-ui-autocomplete

中文文档
1.30.1发布于 2026/07/14MITTypeScriptESM + CJS零依赖构建来源已验证近 30 天下载 1.2万

Constructor.io Autocomplete UI library for web applications

原始使用文档
文档目录13 节
  1. Documentation
  2. 📌 Table of Contents
  3. Overview
  4. Installation & Quick Start
  5. Basic Usage (React)
  6. Integration Modes
  7. Shopify
  8. Bundle (Vanilla JS)
  9. Customization
  10. Troubleshooting
  11. Complementary Resources
  12. Contributing
  13. License

Autocomplete UI

Lightweight, minimalistic, and fully customizable autocomplete component for fast, accessible, and flexible search experiences with Constructor.io's autosuggest services

minzipped size NPM Version MIT licensed

Autocomplete UI Demonstration

Documentation

View the full component documentation and live examples in Storybook

📌 Table of Contents

Overview

Autocomplete UI provides a lightweight and customizable autocomplete component. It enables developers to quickly implement fast, accessible search experiences with Constructor.io's autosuggest services.

  • 🔌 Easy Integration – Quickly integrate with your app as a plug-and-play React component
  • ⚡ Lightweight & Fast – Tiny bundle size, optimized for speed
  • 🎨 Customizable UI – With minimal styles, and supports for custom markup
  • ⌨️ Keyboard Navigation – Fully supports accessible keyboard navigation
  • ♿ Accessible (a11y) – Built-in ARIA support for screen readers
  • 🛡 Written in TypeScript with type safety

Explore full documentation →

Installation & Quick Start

Install the library

npm i @constructor-io/constructorio-ui-autocomplete

Basic Usage (React)

Import and use the CioAutocomplete component

import { CioAutocomplete } from '@constructor-io/constructorio-ui-autocomplete';
import '@constructor-io/constructorio-ui-autocomplete/styles.css';

function YourComponent() {
  return (
    <div>
      <CioAutocomplete
        apiKey="key_M57QS8SMPdLdLx4x"
        onSubmit={(e) => {console.log(e)}}
      />
    </div>
  );
}

Integration Modes

Shopify

Installation & Quick Start

The Constructor autocomplete component is available as part of the Constructor.io Shopify App

After installing the app, you can use the Constructor autocomplete component by clicking 'Add Section' in your theme editor and adding the Constructor autocomplete liquid component

installation gif

For more in depth instructions, check out the Shopify documentation.

🛍️ Shopify-Specific Defaults

If you are using the Constructor autocomplete component inside Shopify without using the Constructor.io Shopify App, you can use the useShopifyDefaults prop to enable automatic navigation handling:

<CioAutocomplete
  apiKey="your-api-key"
  useShopifyDefaults={true}
  shopifySettings={{ searchUrl: '/search' }}
/>

What it does:

  • Product selections: Automatically redirects to the product detail page
  • Search suggestions: Redirects to the search results page with the selected query
  • Manual search: Redirects to the search results page with the entered query
  • Query parameters: Preserves all existing URL query parameters (e.g., UTM parameters)

Configuration:

  • shopifySettings.searchUrl: The search results page URL (e.g: '{{ block.settings.search_url }}' for Liquid templates)

Note: When useShopifyDefaults={true}, any custom onSubmit handler you provide will override the default behavior.

Bundle (Vanilla JS)

This is a framework agnostic method that can be used in any JavaScript project. The CioAutocomplete function provides a simple interface to inject an entire Autocomplete UI into the provided selector. In addition to Autocomplete component props, this function also accepts a selector and includeCSS.

Installation & Quick Start

Install the library

npm i @constructor-io/constructorio-ui-autocomplete

Import and use the CioAutocomplete component

import CioAutocomplete from '@constructor-io/constructorio-ui-autocomplete/constructorio-ui-autocomplete-bundled';

CioAutocomplete({
  selector: '#autocomplete-container',
  includeCSS: true, // Include the default CSS styles. Defaults to true.
  apiKey: 'key_M57QS8SMPdLdLx4x',
  onSubmit: (submitEvent) => console.dir(submitEvent),
  // ... additional arguments
});
</script>

Customization

CSS styles are not imported by default. Add this to your code to import basic styles

import '@constructor-io/constructorio-ui-autocomplete/styles.css';

All styles are scoped under .cio-autocomplete. You can extend them by targeting that selector.

/* Custom Style Sheet */
.cio-autocomplete .cio-submit-btn {
  border-radius: 10px;
  border: 1px solid red;
}

If you'd like to override or extend the base className, you can do so with the autocompleteClassName argument

import { CioAutocomplete } from '@constructor-io/constructorio-ui-autocomplete';
import '@constructor-io/constructorio-ui-autocomplete/styles.css';

function YourComponent() {
  return (
    <div>
      <CioAutocomplete
        apiKey="key_M57QS8SMPdLdLx4x"
        onSubmit={(e) => { console.log(e)}}
        autocompleteClassName="cio-autocomplete custom-autocomplete-container"
      />
    </div>
  );

Then you can modify styles like so

/* Custom Style Sheet */
.cio-autocomplete.custom-autocomplete-styles .cio-input {
  font-weight: bold;
}

Troubleshooting

Common issues and solutions.

Problem Description Solution
Older JavaScript environments The library provides two different builds. CommonJS (cjs) and ECMAScript Modules (mjs)

For ECMAScript Modules (mjs) build, the JavaScript version is ESNext which might not be supported by your environment. If that's the case and your environment is using an older Javascript version like ES6 (ES2015), you might get this error.

Module parse failed: Unexpected token (15:32) You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file
To solve this you can import the CommonJS (cjs) build which supports ES6 (ES2015) syntax:

import CioAutocomplete from '@constructor-io/constructorio-ui-autocomplete/cjs'
ESLint There is a known issue with ESLint where it fails to resolve the paths exposed in the exports statement of NPM packages.

For ECMAScript Modules (mjs) build. The Javascript version is ESNext which might not be supported by your environment. If that's the case and your environment is using an older Javascript version like ES6 (ES2015), you might get this error.

Unable to resolve path to module '@constructor-io/constructorio-ui-autocomplete/styles.css'

Relevant open issues:
If you are receiving the following error, you can safely disable ESLint using // eslint-disable-line for that line.
Peer Dependencies The library requires a couple of peer dependencies to be installed, so ensure they're installed if not already.

  1. constructorio-client-javascript
  2. downshift
Run npm i downshift @constructor-io/constructorio-client-javascript

💬 Need help? Join our GitHub Discussions

Complementary Resources

Contributing

  1. Fork the repo & create a new branch.
  2. Run npm install to install dependencies.
  3. After making the desired changes, run npm run tests && npm run lint locally.
  4. Submit a PR for review.

License

MIT License

Copyright (c) 2022-present Constructor.io Corporation

版本与发布记录

@constructor-io/constructorio-ui-autocomplete 共发布 123 个版本,首次发布于 2023/02/01;过去 12 个月发布了 16 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
1.30.1latest2026/07/143 个月前
1.30.02026/04/206 个月前
1.29.82026/04/206 个月前
1.29.72026/03/098 个月前
1.29.52026/03/098 个月前
1.29.42026/02/188 个月前

关于 @constructor-io/constructorio-ui-autocomplete 的常见问题

@constructor-io/constructorio-ui-autocomplete 是什么?

Constructor.io Autocomplete UI library for web applications

如何安装 @constructor-io/constructorio-ui-autocomplete?

在项目目录运行 npm install @constructor-io/constructorio-ui-autocomplete,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:react(>=16.12.0)、tslib(^2.5.0)、downshift(^7.2.1)、react-dom(>=16.12.0)、@constructor-io/constructorio-client-javascript(^2.67.6)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@constructor-io/constructorio-ui-autocomplete 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@constructor-io/constructorio-ui-autocomplete 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@constructor-io/constructorio-ui-autocomplete 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >=14。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@constructor-io/constructorio-ui-autocomplete 可以商用吗?

@constructor-io/constructorio-ui-autocomplete 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@constructor-io/constructorio-ui-autocomplete 的下载量有多少?

根据 npm 官方下载统计,@constructor-io/constructorio-ui-autocomplete 在 2026/10/11 – 2026/11/09 这 30 天内被下载 12,242 次,日均约 408 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@constructor-io/constructorio-ui-autocomplete 还在维护吗?

最新版本 1.30.1 发布于 2026/07/14(3 个月前);至今共发布 123 个版本,其中过去 12 个月发布了 16 个;首次发布于 2023/02/01。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。