1
1
// eslint-disable-next-line camelcase
2
2
import { getTheme_v2 } from '@sanity/ui/theme'
3
- import { useCallback , useEffect , useRef , useState } from 'react'
3
+ import { startTransition , useCallback , useEffect , useState } from 'react'
4
4
import {
5
5
type ArrayFieldProps ,
6
6
type PortableTextBlock ,
@@ -10,10 +10,11 @@ import {
10
10
} from 'sanity'
11
11
import styled , { css } from 'styled-components'
12
12
13
- import { CommentInput } from '../../../../../../structure/comments'
14
- import { tasksLocaleNamespace } from '../../../../../i18n'
15
- import { useMentionUser } from '../../../context'
16
- import { type FormMode } from '../../../types'
13
+ import { CommentInput } from '../../../../../../../structure/comments'
14
+ import { tasksLocaleNamespace } from '../../../../../../i18n'
15
+ import { useMentionUser } from '../../../../context'
16
+ import { type FormMode } from '../../../../types'
17
+ import { renderBlock } from './render'
17
18
18
19
const DescriptionInputRoot = styled . div < { $mode : FormMode ; $minHeight : number } > ( ( props ) => {
19
20
const theme = getTheme_v2 ( props . theme )
@@ -43,39 +44,42 @@ export function DescriptionInput(props: ArrayFieldProps & {mode: FormMode}) {
43
44
inputProps : { onChange} ,
44
45
} = props
45
46
const value = _propValue as PortableTextBlock [ ] | undefined
46
-
47
47
const currentUser = useCurrentUser ( )
48
48
const { mentionOptions} = useMentionUser ( )
49
49
50
50
const handleChange = useCallback ( ( next : PortableTextBlock [ ] ) => onChange ( set ( next ) ) , [ onChange ] )
51
51
52
- const rootRef = useRef < HTMLDivElement | null > ( null )
52
+ const [ rootRef , setRootRef ] = useState < HTMLDivElement | null > ( null )
53
53
const [ textBoxScrollHeight , setTextBoxScrollHeight ] = useState < number > ( 200 )
54
54
const setTextboxHeight = useCallback ( ( ref : HTMLDivElement ) => {
55
55
const textBox = ref . querySelector ( '[role="textbox"]' )
56
56
if ( ! textBox ) return
57
+
57
58
const height = textBox . scrollHeight
58
59
setTextBoxScrollHeight ( height )
59
60
} , [ ] )
60
61
61
- const setRootRef = useCallback (
62
- ( ref : HTMLDivElement ) => {
63
- if ( ! ref ) return
64
- setTextboxHeight ( ref )
65
- rootRef . current = ref
66
- } ,
67
- [ setTextboxHeight ] ,
68
- )
62
+ const handleSetRootRef = useCallback ( ( ref : HTMLDivElement ) => {
63
+ if ( ! ref ) return
64
+ startTransition ( ( ) => {
65
+ setRootRef ( ref )
66
+ } )
67
+ } , [ ] )
68
+
69
69
const { t} = useTranslation ( tasksLocaleNamespace )
70
70
71
71
useEffect ( ( ) => {
72
- if ( ! rootRef . current ) return
73
- setTextboxHeight ( rootRef . current )
74
- } , [ value , setTextboxHeight ] )
72
+ if ( ! rootRef ) return
73
+ setTextboxHeight ( rootRef )
74
+ } , [ value , setTextboxHeight , rootRef ] )
75
75
76
76
if ( ! currentUser ) return null
77
77
return (
78
- < DescriptionInputRoot $mode = { mode } ref = { setRootRef } $minHeight = { textBoxScrollHeight || 200 } >
78
+ < DescriptionInputRoot
79
+ $mode = { mode }
80
+ ref = { handleSetRootRef }
81
+ $minHeight = { textBoxScrollHeight || 200 }
82
+ >
79
83
< CommentInput
80
84
expandOnFocus = { false }
81
85
currentUser = { currentUser }
@@ -86,6 +90,7 @@ export function DescriptionInput(props: ArrayFieldProps & {mode: FormMode}) {
86
90
placeholder = { t ( 'form.input.description.placeholder' ) }
87
91
// eslint-disable-next-line react/jsx-no-bind
88
92
onDiscardConfirm = { ( ) => null }
93
+ renderBlock = { renderBlock }
89
94
/>
90
95
</ DescriptionInputRoot >
91
96
)
0 commit comments