Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions docs/content/docs/2.components/chat-messages.md
Original file line number Diff line number Diff line change
Expand Up @@ -435,6 +435,14 @@ import { isTextUIPart } from 'ai'
```
::

### Expose

When accessing the component via a template ref, you can use the following:

| Name | Type |
| ---- | ---- |
| `registerMessageRef(id: string, element: ComponentPublicInstance \| null)`{lang="ts-type"} | `void`{lang="ts-type"} |

## Theme

:component-theme
Expand Down
8 changes: 6 additions & 2 deletions src/runtime/components/ChatMessages.vue
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ export interface ChatMessagesProps<T extends UIMessage[] = UIMessage[]> {
}

export type ChatMessagesSlots<T extends UIMessage[] = UIMessage[]> = {
default?(props?: {}): VNode[]
default?(props: { registerMessageRef: (id: string, element: ComponentPublicInstance | null) => void }): VNode[]
Comment thread
zAlweNy26 marked this conversation as resolved.
indicator?(props: { ui: ChatMessages['ui'] }): VNode[]
viewport?(props: { ui: ChatMessages['ui'], onClick: () => void }): VNode[]
} & {
Expand Down Expand Up @@ -308,6 +308,10 @@ onMounted(() => {
}, { childList: true, subtree: true })
}
})

defineExpose({
registerMessageRef
})
</script>

<template>
Expand All @@ -318,7 +322,7 @@ onMounted(() => {
:class="ui.root({ class: [props.ui?.root, props.class] })"
:style="{ '--last-message-height': `${lastMessageHeight}px` }"
>
<slot>
<slot :register-message-ref="registerMessageRef">
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we really need to expose this in default slot? Isn't it enough to access it through a template ref? πŸ€”

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Personally, I’d prefer to avoid creating a template ref every time I need one when I’m dealing with simpler cases. I see the template ref as necessary for more complex scenarios.

<template v-for="message in props.messages" :key="message.id">
<UChatMessage
v-if="message.parts?.length"
Expand Down
Loading