This repository was archived by the owner on Jan 29, 2026. It is now read-only.
File tree Expand file tree Collapse file tree
packages/tds-widget/src/chat/input-area Expand file tree Collapse file tree Original file line number Diff line number Diff line change 44 NolInputAreaUI ,
55 INPUT_AREA_HEIGHT as NOL_INPUT_AREA_HEIGHT ,
66} from './nol-input-area-ui'
7+ export * from './nol-input-area-ui/use-input-resize-observer'
Original file line number Diff line number Diff line change 1+ import { useState , useEffect , useRef } from 'react'
2+
3+ import { useScroll } from '../../chat'
4+
5+ export function useInputResizeObserver ( defaultHeight : number ) {
6+ const { setScrollBy, chatContainerRef } = useScroll ( )
7+ const inputContainerRef = useRef < HTMLDivElement | null > ( null )
8+
9+ const inputContainerHeightRef = useRef < number > ( defaultHeight )
10+ const [ inputContainerHeight , setInputContainerHeight ] =
11+ useState < number > ( defaultHeight )
12+
13+ useEffect ( ( ) => {
14+ inputContainerHeightRef . current = inputContainerHeight
15+ } , [ inputContainerHeight ] )
16+
17+ useEffect ( ( ) => {
18+ const inputContainer = inputContainerRef ?. current
19+
20+ if ( ! inputContainer ) {
21+ return
22+ }
23+
24+ const observer = new ResizeObserver ( ( ) => {
25+ const diff = inputContainer . clientHeight - inputContainerHeightRef . current
26+
27+ const chatContainer = chatContainerRef ?. current
28+
29+ if (
30+ diff > 0 ||
31+ ! (
32+ chatContainer &&
33+ chatContainer . scrollTop + chatContainer . clientHeight ===
34+ chatContainer . scrollHeight
35+ )
36+ ) {
37+ setScrollBy ( diff )
38+ }
39+ setInputContainerHeight ( inputContainer . clientHeight )
40+ } )
41+
42+ observer . observe ( inputContainer )
43+
44+ return ( ) => {
45+ observer . disconnect ( )
46+ }
47+ // eslint-disable-next-line react-hooks/exhaustive-deps
48+ } , [ ] )
49+
50+ return {
51+ inputContainerRef,
52+ inputContainerHeight,
53+ }
54+ }
You can’t perform that action at this time.
0 commit comments