Documentation Index
Fetch the complete documentation index at: https://cometchat-22654f5b-react-uikit-v7.mintlify.app/llms.txt
Use this file to discover all available pages before exploring further.
AI Integration Quick Reference
AI Integration Quick Reference
Where It Fits
CometChatSearchBar is a base component used inside feature components like CometChatConversations, CometChatUsers, and CometChatGroups to provide search and filter functionality. It renders a search icon, a text input, and an optional clear button. Wire it into any list component to enable filtering.
Minimal Render
.cometchat-search-bar
Sub-Components
CometChatSearchBar is a compound component with four sub-components:
| Sub-component | Purpose |
|---|---|
Root | Container that provides context, manages state, and supports controlled/uncontrolled modes with optional debounce. |
Icon | Decorative search icon. Hidden from assistive technology. |
Input | The <input> element with role="searchbox", aria-label, and Escape-to-clear. |
ClearButton | Clear/reset button. Only visible and focusable when the input has a value. |
Root
The outermost wrapper. Manages search state and provides it to child sub-components via React context. Supports controlled mode (value + onChange), uncontrolled mode (defaultValue), and optional debounce.
Icon
Renders the search icon. Decorative by default (aria-hidden="true"). Pass a custom icon prop to replace the built-in icon.
Input
The text input. Readsvalue, placeholder, and disabled from context. Supports Escape key to clear. Forwards additional HTML input attributes like autoFocus and maxLength.
ClearButton
A button that clears the search value. Hidden from the tab order when the input is empty. Pass a customicon prop to replace the default × icon.
Actions and Events
Callback Props
onChange
Fires when the search value changes. Receives the new value as a plain string.Custom View Slots
| Slot | Prop | Signature | Replaces |
|---|---|---|---|
| Search icon | Icon.icon | ReactNode | Built-in CSS mask search icon |
| Clear icon | ClearButton.icon | ReactNode | Built-in CSS mask × icon |
Custom search icon
- TypeScript
- CSS
Common Patterns
Debounced search
Prevent excessive API calls during rapid typing by settingdebounceMs.
Controlled vs uncontrolled
Controlled mode gives you full control over the value. Uncontrolled mode lets the component manage its own state.Without clear button
Just don’t render theClearButton sub-component.
Keyboard Navigation
| Key | Behavior |
|---|---|
Tab | Moves focus to the input, then to the clear button (if visible), then out |
Shift+Tab | Reverse focus order |
Escape | Clears the input value and keeps focus on the input |
Enter | No default action (consumers can attach onKeyDown for submit behavior) |
tabIndex={-1}. The input itself does not show a focus outline — the container’s pill shape provides sufficient visual context.
CSS Architecture
The component uses CSS custom properties (design tokens) defined in@cometchat/chat-uikit-react/css-variables.css. The cascade:
- Global tokens set on the
.cometchatroot wrapper. - Component CSS (
.cometchat-search-bar) consumes these tokens viavar(). - Overrides target
.cometchat-search-bardescendant selectors.
Key Selectors
| Target | Selector |
|---|---|
| Root container | .cometchat-search-bar |
| Search icon | .cometchat-search-bar__icon |
| Input | .cometchat-search-bar__input |
| Input placeholder | .cometchat-search-bar__input::placeholder |
| Clear button | .cometchat-search-bar__clear-button |
| Clear button icon | .cometchat-search-bar__clear-button-icon |
| Disabled state | .cometchat-search-bar--disabled |
Example: Brand-themed search bar
App.css
Customization Matrix
| What to change | Where | Property/API | Example |
|---|---|---|---|
| Search value | Component props | value, onChange on Root | <Root value={q} onChange={setQ}> |
| Placeholder text | Component props | placeholder on Root | <Root placeholder="Find..."> |
| Debounce delay | Component props | debounceMs on Root | <Root debounceMs={300}> |
| Disable interaction | Component props | disabled on Root | <Root disabled> |
| Replace search icon | Component props | icon on Icon | <Icon icon={<MyIcon />}> |
| Replace clear icon | Component props | icon on ClearButton | <ClearButton icon={<X />}> |
| Hide clear button | Composition | Omit ClearButton | Don’t render <ClearButton /> |
| Change visual styling | Global CSS | .cometchat-search-bar selectors | See example above |
Props
All props are optional unless noted otherwise.CometChatSearchBar.Root
value
Current search value. When provided, the component operates in controlled mode.| Type | string |
| Default | undefined |
defaultValue
Initial search value for uncontrolled mode. Ignored whenvalue is provided.
| Type | string |
| Default | "" |
onChange
Callback fired when the search value changes. Receives the new value as a plain string.| Type | (value: string) => void |
| Default | undefined |
placeholder
Placeholder text for the input.| Type | string |
| Default | "Search" |
disabled
Whether the search bar is disabled. Propagated to the input and clear button via context.| Type | boolean |
| Default | false |
debounceMs
Debounce delay in milliseconds for theonChange callback. Set to 0 for no debounce.
| Type | number |
| Default | 0 |
inputRef
Ref forwarded to the underlying<input> element. Convenience prop — equivalent to using a ref on the Input sub-component directly.
| Type | Ref<HTMLInputElement> |
| Default | undefined |
className
Custom CSS class appended to the root container.| Type | string |
| Default | undefined |
style
Custom inline styles for the root container.| Type | CSSProperties |
| Default | undefined |
children
Content rendered inside the root. TypicallyIcon, Input, and ClearButton sub-components.
| Type | ReactNode |
| Default | undefined |
CometChatSearchBar.Icon
icon
Custom icon element. Defaults to the built-in CSS mask search icon.| Type | ReactNode |
| Default | Built-in search icon |
className
Custom CSS class appended to the icon container.| Type | string |
| Default | undefined |
CometChatSearchBar.Input
className
Custom CSS class appended to the input element.| Type | string |
| Default | undefined |
…rest
All standard HTML input attributes (exceptvalue, onChange, disabled, placeholder which are managed by context) are forwarded to the native <input> element.
| Type | InputHTMLAttributes<HTMLInputElement> |
| Default | — |
CometChatSearchBar.ClearButton
icon
Custom clear icon element. Defaults to the built-in CSS mask × icon.| Type | ReactNode |
| Default | Built-in × icon |
className
Custom CSS class appended to the clear button.| Type | string |
| Default | undefined |
aria-label
Accessible label for the clear button.| Type | string |
| Default | "Clear search" |
CSS Selectors
| Target | Selector |
|---|---|
| Root | .cometchat-search-bar |
| Search icon | .cometchat-search-bar__icon |
| Input | .cometchat-search-bar__input |
| Input placeholder | .cometchat-search-bar__input::placeholder |
| Clear button | .cometchat-search-bar__clear-button |
| Clear button icon | .cometchat-search-bar__clear-button-icon |
| Disabled modifier | .cometchat-search-bar--disabled |