(props: ThreadItemProps)
| 456 | * A ThreadItem displays an individual chat message. |
| 457 | */ |
| 458 | export function ThreadItem(props: ThreadItemProps) { |
| 459 | let { |
| 460 | styles, |
| 461 | children, |
| 462 | textValue = ' ', |
| 463 | isStreaming, |
| 464 | shouldAnnounceOnMount, |
| 465 | focusMode, |
| 466 | allowsArrowNavigation |
| 467 | } = props; |
| 468 | let {announceItem} = useContext(InternalChatContext); |
| 469 | |
| 470 | // TODO: using aria-live on the gridlist item was pretty chatty and the streaming causes the text announcement |
| 471 | // to constantly reset. If we used a live region and updated its contents when streaming finished that worked decently |
| 472 | // but still feels quite verbose. Stick with this and get feedback |
| 473 | useLayoutEffect(() => { |
| 474 | if ((isStreaming === undefined || shouldAnnounceOnMount) && textValue && textValue !== ' ') { |
| 475 | announceItem(textValue); |
| 476 | } |
| 477 | |
| 478 | // eslint-disable-next-line react-hooks/exhaustive-deps |
| 479 | }, []); |
| 480 | |
| 481 | let isStreamingNow = isStreaming ?? false; |
| 482 | let prevStreamingRef = useRef(isStreamingNow); |
| 483 | useLayoutEffect(() => { |
| 484 | if (isStreaming === undefined) { |
| 485 | return; |
| 486 | } |
| 487 | let wasStreaming = prevStreamingRef.current; |
| 488 | prevStreamingRef.current = isStreamingNow; |
| 489 | if (wasStreaming && !isStreamingNow && textValue && textValue !== ' ') { |
| 490 | announceItem(textValue); |
| 491 | } |
| 492 | }, [isStreaming, isStreamingNow, textValue, announceItem]); |
| 493 | |
| 494 | return ( |
| 495 | <GridListItem |
| 496 | textValue={textValue} |
| 497 | focusMode={focusMode} |
| 498 | allowsArrowNavigation={allowsArrowNavigation} |
| 499 | className={renderProps => mergeStyles(threadItemBase({...renderProps}), styles)}> |
| 500 | {children} |
| 501 | </GridListItem> |
| 502 | ); |
| 503 | } |
| 504 | |
| 505 | export interface ThreadLoadMoreItemProps extends GridListLoadMoreItemProps {} |
| 506 |
nothing calls this directly
no test coverage detected