@@ -37,29 +37,32 @@ function Input(props, ref) {
37
37
// not cause a layout shift.
38
38
let [ reservePadding , setReservePadding ] = useValueEffect ( false ) ;
39
39
let onResize = useCallback ( ( ) => setReservePadding ( function * ( reservePadding ) {
40
- if ( reservePadding ) {
41
- // Try to collapse padding if the content is clipped.
42
- if ( inputRef . current . scrollWidth > inputRef . current . offsetWidth ) {
43
- let width = inputRef . current . parentElement . offsetWidth ;
44
- yield false ;
40
+ if ( inputRef . current ) {
41
+ if ( reservePadding ) {
42
+ // Try to collapse padding if the content is clipped.
43
+ if ( inputRef . current . scrollWidth > inputRef . current . offsetWidth ) {
44
+ let width = inputRef . current . parentElement . offsetWidth ;
45
+ yield false ;
45
46
46
- // If removing padding causes a layout shift, add it back.
47
- if ( inputRef . current . parentElement . offsetWidth !== width ) {
48
- yield true ;
47
+ // If removing padding causes a layout shift, add it back.
48
+ if ( inputRef . current . parentElement . offsetWidth !== width ) {
49
+ yield true ;
50
+ }
49
51
}
50
- }
51
- } else {
52
- // Try to add padding if the content is not clipped.
53
- if ( inputRef . current . offsetWidth >= inputRef . current . scrollWidth ) {
54
- let width = inputRef . current . parentElement . offsetWidth ;
55
- yield true ;
52
+ } else {
53
+ // Try to add padding if the content is not clipped.
54
+ if ( inputRef . current . offsetWidth >= inputRef . current . scrollWidth ) {
55
+ let width = inputRef . current . parentElement . offsetWidth ;
56
+ yield true ;
56
57
57
- // If adding padding does not change the width (i.e. width is constrained), remove it again.
58
- if ( inputRef . current . parentElement . offsetWidth === width ) {
59
- yield false ;
58
+ // If adding padding does not change the width (i.e. width is constrained), remove it again.
59
+ if ( inputRef . current . parentElement . offsetWidth === width ) {
60
+ yield false ;
61
+ }
60
62
}
61
63
}
62
64
}
65
+
63
66
} ) , [ inputRef , setReservePadding ] ) ;
64
67
65
68
useLayoutEffect ( onResize , [ onResize ] ) ;
0 commit comments