Lightweight, minimalistic, and fully customizable autocomplete component for fast, accessible, and flexible search experiences with Constructor.io's autosuggest services. π
- Features
- React
- Shopify
- Bundle (Vanilla JS)
- π‘ Code Examples
- π¨ Customization
- π Advanced Features
- π Troubleshooting
- π API Reference
- π Complementary Resources
- π€ Contributing
- π License
- π 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 minmal styles, and supports for custom markup
- β¨οΈ Keyboard Navigation β Fully supports accessible keyboard naviagation
- βΏ Accessible (a11y) β Built-in ARIA support for screen readers
- π‘ Written in TypeScript with type safety
Install the library
npm i @constructor-io/constructorio-ui-autocompleteImport 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>
);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
For more in depth instructions, check out the Shopify documentation.
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.
Install the library
npm i @constructor-io/constructorio-ui-autocompleteImport 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>Ready-to-use, copy-paste examples with explanations.
πΉ For more examples check the full examples
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;
}πΉ For more advanced use cases check the full documentation
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.
|
Run npm i downshift @constructor-io/constructorio-client-javascript
|
π¬ Need help? Join our GitHub Discussions
- Full API docs: Click here
- π Full Documentation: Storybook
- π¦ JS Client: SDK Documentation
- π Shopify App: App Store Link
- π Constructor's REST API: Autocomplete
- Fork the repo & create a new branch.
- Run
npm installto install dependencies. - After making the desired changes, run
npm run tests && npm run lintlocally. - Submit a PR for review.
Copyright (c) 2022-present Constructor.io Corporation

