---
url: https://talkjs.com/docs/UI_Components/Web_Components/t-conversation-list/
title: "<t-conversation-list> | Web Components | TalkJS Docs"
---

For AI agents: Find a documentation index at https://talkjs.com/llms.txt (full content at https://talkjs.com/llms-full.txt). Get a markdown version of any page by appending .md to its URL path.

# <t-conversation-list>

Display a list of conversations.

The `<t-conversation-list>` web component represents a [conversation list UI](https://talkjs.com/docs/Features/Chat_UIs/#conversation-list), which displays a list of conversations that the current user is a participant of.

## interface ConversationListProps

```typescript
interface ConversationListProps extends BaseConversationListProps {
  appId: string;
  baseTheme?: "classic" | "default";
  conversationFilter?: ConversationFilter;
  onSelectConversation?: (event: SelectConversationEvent) => void;
  selectedConversationId?: string;
  theme?: Partial<Theme>;
  themeCustom?: any;
  userId: string;
  token?: string;
  tokenFetcher?: () => string | Promise<string>;
}
```

### Properties

**appId**: string

Your app's unique TalkJS ID. You can find it on the Settings page of the [TalkJS dashboard.](https://talkjs.com/dashboard)

**userId**: string

The ID of the current user.

If the given user ID doesn't exist, a "Something went wrong" message will be displayed.

**baseTheme _(optional)_**: "classic" | "default"

The base theme to start from.

Defaults to `"default"`. If an unsupported value is passed at runtime, a warning is logged and `"default"` is used instead.

**conversationFilter _(optional)_**: [ConversationFilter](https://talkjs.com/docs/Data_APIs/JavaScript/Filters/#ConversationFilter)

A filter to apply to the conversation list.

Only conversations matching this filter are included in the conversation list.

Updating this prop re-subscribes to the conversation list with the new filter.

**Example 1**

Show only support conversations

```ts
<ConversationList
  appId="<APP_ID>"
  userId="<USER_ID>"
  conversationFilter={{ custom: { category: ["==", "support"] } }}
/>
```

**Example 2**

Hide conversations that have no messages yet

```ts
<ConversationList
  appId="<APP_ID>"
  userId="<USER_ID>"
  conversationFilter={{ hasMessages: true }}
/>
```

**onSelectConversation _(optional)_**: (event: [SelectConversationEvent](https://talkjs.com/docs/UI_Components/Other_types/#SelectConversationEvent)) => void

Callback that triggers when the user selects a conversation from the list.

Note that updating the selected conversation through the selectedConversationId prop \*\*will not\*\* trigger this callback.

Use this callback to have an adjacent chatbox show the correct conversation. See [Respond to a select conversation event.](https://talkjs.com/docs/UI_Components/React/ConversationList/#respond-to-a-select-conversation-event)

**selectedConversationId _(optional)_**: string

The ID of the conversation currently selected in the list.

Changing the value of this prop will cause the ConversationList UI to update.

If you're using a modern web framework like React or Vue, also include an onSelectConversation prop where you'll update your local `selectedConversationId` state so that it stays in sync with the UI's internals.

Note that updating the selected conversation through this prop \*\*will not\*\* trigger the onSelectConversation callback.

**theme _(optional)_**: Partial<[Theme](https://talkjs.com/docs/UI_Components/Theme/Shared_types/#Theme)\>

Lets you override theme components with your own implementations to customize them.

See [Custom theme components](https://talkjs.com/docs/UI_Components/React/Customization/#custom-theme-components) for more info.

**themeCustom _(optional)_**: any

Arbitrary custom data passed down to the theme.

Whatever data you pass here will be made available for use in theme components through [CommonChatboxProps.themeCustom](https://talkjs.com/docs/UI_Components/Theme/Shared_types/#CommonChatboxProps__themeCustom) for Chatbox theme components and through [CommonConversationListProps.themeCustom](https://talkjs.com/docs/UI_Components/Theme/Shared_types/#CommonConversationListProps__themeCustom) for ConversationList theme components.

**token _(optional)_**: string

A token to authenticate the session with.

See the [Authentication guide](https://talkjs.com/docs/Features/Security/Authentication/) and [Token reference](https://talkjs.com/docs/Features/Security/Advanced_Authentication/#token-reference) for details and examples.

Required when authentication is enabled, otherwise optional.

**tokenFetcher _(optional)_**: () => string | Promise<string>

A function that fetches and returns a new authentication token from your server.

TalkJS calls this function whenever the current token is about to expire. This callback is designed to work with any backend setup. See [Refreshable tokens](https://talkjs.com/docs/Features/Security/Advanced_Authentication/#refreshable-tokens) for details and examples.

## class ConversationListElement

```typescript
declare class ConversationListController {
  selectConversation(conversationId: string | null, focusedMessageId?: string): Promise<void>;
}
```

The `t-conversation-list` element is a custom element that extends the `HTMLElement` class. It exposes the following method:

### selectConversation

_conversationListController_.selectConversation(conversationId, focusedMessageId): Promise<void>

Selects a conversation with the given ID, or de-select a conversation by passing `null`.

This method is called from the theme's ConversationListItem component when the user clicks on the given conversation. You can also call it programmatically from elsewhere to simulate a user click.

This method will trigger the [ConversationListProps.onSelectConversation](https://talkjs.com/docs/UI_Components/Web_Components/t-conversation-list/#ConversationListProps__onSelectConversation) event. In most cases, if you want to change the selected conversation programmatically from outside the conversation list, it's better to pass a different value to the [ConversationListProps.selectedConversationId](https://talkjs.com/docs/UI_Components/Web_Components/t-conversation-list/#ConversationListProps__selectedConversationId) prop instead, as that lets you keep your local state in sync with the props passed to the conversation list.

You can also optionally pass a `focusedMessageId` to signify the intent of scrolling to a particular message within that conversation.

#### Parameters

**conversationId**: string | null

**focusedMessageId _(optional)_**: string

#### Returns

Promise<void>

## Examples

The following examples show how to use the `<t-conversation-list>` component.

### Create a conversation list with an existing user

To create a conversation list and pass it an existing user, use the following:

**Angular**

```html
<t-conversation-list app-id="<APP_ID>" user-id="sample_user_alice" />
```

**Vue**

```html
<t-conversation-list app-id="<APP_ID>" user-id="sample_user_alice" />
```

**Svelte**

```html
<t-conversation-list
  app-id="<APP_ID>"
  user-id="sample_user_alice"
></t-conversation-list>
```

**HTML**

```html
<t-conversation-list
  app-id="<APP_ID>"
  user-id="sample_user_alice"
></t-conversation-list>
```

### Create a conversation list with a new user

Install the [`@talkjs/core` package](https://www.npmjs.com/package/@talkjs/core), which lets you read, subscribe to, and update your chat data:

**npm**

```shell
npm install @talkjs/core
```

**yarn**

```shell
yarn add @talkjs/core
```

Import it into the component where you want to use it:

```js
import { getTalkSession } from '@talkjs/core';
```

Then create the session and user:

**Angular**

```ts
appId = '<APP_ID>';
userId = 'sebastian';
session: TalkSession | null = null;

ngOnInit() {
  this.session = getTalkSession({
    appId: this.appId,
    userId: this.userId,
  });
  this.session.currentUser.createIfNotExists({ name: 'Sebastian' });
}
```

**Vue**

```js
const appId = '<APP_ID>';
const userId = 'sebastian';

const session = getTalkSession({ appId, userId });
session.currentUser.createIfNotExists({ name: 'Sebastian' });
```

**Svelte**

```js
const appId = '<APP_ID>';
const userId = 'sebastian';

const session = getTalkSession({ appId, userId });
session.currentUser.createIfNotExists({ name: 'Sebastian' });
```

Pass the new user to your conversation list:

**Angular**

```html
<t-conversation-list [app-id]="appId" [user-id]="userId" />
```

**Vue**

```html
<t-conversation-list :app-id="appId" :user-id="userId" />
```

**Svelte**

```js
<t-conversation-list app-id={appId} user-id={userId}></t-conversation-list>
```

If you're using TalkJS web components without a package manager, see the [Create new users and conversations](https://talkjs.com/docs/UI_Components/Web_Components/Installation/#create-new-users-and-conversations) guide.

### Respond to a select conversation event

Respond to a select conversation event by switching the [chatbox](https://talkjs.com/docs/UI_Components/Web_Components/t-chatbox/) to show the selected conversation.

When a user selects a conversation from the list, the component emits a `select-conversation` event with the selected conversation’s details. You can handle this event to update a chatbox or perform another action.

**Angular**

```txt
// chat.component.html
<t-conversation-list
  app-id="<APP_ID>"
  user-id="sample_user_alice"
  [selected-conversation-id]="conversationId()"
  (selectConversation)="onSelectConversation($event)"
></t-conversation-list>

<t-chatbox
  app-id="<APP_ID>"
  user-id="sample_user_alice"
  [conversation-id]="conversationId()"
></t-chatbox>

// chat.component.ts
conversationId = signal("sample_conversation");

onSelectConversation(event: SelectConversationEvent): void {
  this.conversationId.set(event.conversation.id);
}
```

**Vue**

```html
<script setup>
  const conversationId = ref('sample_conversation');

  function onSelectConversation(event) {
    conversationId.value = event.conversation.id;
  }
</script>

<template>
  <main>
    <t-conversation-list
      app-id="<APP_ID>"
      user-id="sample_user_alice"
      :selected-conversation-id="conversationId"
      @select-conversation="onSelectConversation"
    />

    <t-chatbox
      app-id="<APP_ID>"
      user-id="sample_user_alice"
      :conversation-id="conversationId"
    />
  </main>
</template>
```

**Svelte**

```js
<script>
  let conversation = $state("sample_conversation");

  function onSelectConversation(event) {
    conversation = event.conversation.id;
  }
</script>

<t-conversation-list
  app-id="<APP_ID>"
  user-id="sample_user_alice"
  selected-conversation-id={conversation}
  on:selectConversation={onSelectConversation}
></t-conversation-list>

<t-chatbox
  app-id="<APP_ID>"
  user-id="sample_user_alice"
  conversation-id={conversation}
></t-chatbox>
```

**HTML**

```html
<t-conversation-list
  id="conversation-list"
  app-id="<APP_ID>"
  user-id="sample_user_alice"
  selected-conversation-id="sample_conversation"
></t-conversation-list>

<t-chatbox
  id="chatbox"
  app-id="<APP_ID>"
  user-id="sample_user_alice"
  conversation-id="sample_conversation"
></t-chatbox>

<script>
  const conversationList = document.getElementById('conversation-list');
  const chatbox = document.getElementById('chatbox');

  conversationList.addEventListener('select-conversation', (event) => {
    chatbox.conversationId = event.conversation.id;
  });
</script>
```
