Custom Trigger for a modal (React)
Use the "Custom Trigger" if you want to use a custom button, search bar, link, or any other UI element for opening and closing Inkeep's modal components.
Overview
Modal components are extensions of their embedded counterparts, providing the same functionality in a modal interface. Examples:
Quick Start
Install the component library
Define the component
Let's use the Modal version of the Search and Chat component as an example.
Modal Settings
Modal settings control the behavior and interaction of modal components. These settings are passed in the modalSettings
prop.
Setting | Type | Default | Description |
---|---|---|---|
isOpen | boolean | false | Controls the visibility of the modal. Set to true to show the modal, false to hide it. |
onOpenChange | (isOpen: boolean) => void | - | Callback function triggered when the modal's open state changes. Useful for syncing state with your application. |
shortcutKey | string | null | 'k' | The keyboard key that triggers the modal when pressed with Cmd (Mac) or Ctrl (Windows). Set to null to disable the shortcut. |
Modal Types
Basically means the modal extensions of the following components:
Modal Search
A modal version of the embedded search component. For detailed information about search functionality and available settings, see Embedded Search.
Modal Chat
A modal version of the embedded chat component. For detailed information about chat functionality and available settings, see Embedded Chat.
Modal Search and Chat
A modal version of the embedded search and chat component. For detailed information about search and chat functionality and available settings, see Embedded Search and Chat.
Component Methods
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.