Search Bar (React)
Add the Inkeep search bar as a React component.
Overview
The search bar is a great way to add an AI powered search bar to your website.
Quick Start
Install the component library
Define the component
Search Bar Props
Search bar props control the behavior and interaction of the search bar.
Prop | Type | Required | Description |
---|---|---|---|
baseSettings | object | Yes | Core configuration settings. See Base Settings for details. |
aiChatSettings | object | No | AI chat configuration settings. See AI Chat Settings for details. |
modalSettings | object | No | Modal configuration settings. See Modal Settings for details. |
canToggleView | boolean | No | Whether to allow toggling between chat and search views. Defaults to true. |
defaultView | 'search' | 'chat' | No | The default view to show when opened. Defaults to 'chat'. |
Examples
Set the default view
Force the default view
If you want to force the default view to be the search or the chat, you can use the forceDefaultView
property. This is useful to ensure the widget always opens the defaultView instead of last used view.
Refer to the Search Settings and Chat Settings docs for more details on the available properties.
Accessing Component Methods
Exactly how you'd do it in the Embedded Search and Embedded Chat components respectively.
Chat Methods
Method | Description |
---|---|
submitMessage(message?: string) | Programmatically sends a message in chat. If message is omitted, sends the current input value. |
updateInputMessage(message: string) | Updates the text in chat input field |
clearChat() | Resets the chat to its initial state |
openForm(formSettings: FormSettings) | Displays a form overlay in chat interface |
focusInput() | Sets focus to the chat input field |
Refer to the Form Settings reference docs for more details on the available properties for the openForm
method.
Search methods
Method | Description |
---|---|
updateQuery(query: string) | Programmatically updates the search query. |
focusInput() | Sets focus to the search input field |
Widget methods
Method | Description |
---|---|
setView(view: ModalViewTypes) | Set the view of the widget to either search or chat |
FAQ
If you use a webpack
build. You could come across this error.
To fix this you need to create a custom loader for your webpack configuration to disable
this behavior.
Since webpack 5.0.0-beta.30, you're required to specify extensions when using imports in .mjs files or any .js files with a package.json with "type": "module". You can still disable the behavior with resolve.fullySpecified set to false if you see any related errors in your project.
We can add a new rule to our webpack configuration to disable this behavior.
Then add this to your webpack.config.js
file.
If you use docusaurus, you can add this to your docusaurus.config.js
file as a webpack
config override with plugins.