Skip to content

Commit f9318ce

Browse files
authored
chore: remove useless code (#73)
1 parent c6bee0d commit f9318ce

File tree

1 file changed

+12
-31
lines changed

1 file changed

+12
-31
lines changed

src/ResizableTextArea.tsx

Lines changed: 12 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,14 @@ import type { TextAreaProps } from '.';
88
import calculateAutoSizeStyle from './calculateNodeHeight';
99
import type { ResizableTextAreaRef } from './interface';
1010

11-
const RESIZE_START = 0;
12-
const RESIZE_MEASURING = 1;
13-
const RESIZE_STABLE = 2;
11+
const RESIZE_START = 0 as const;
12+
const RESIZE_MEASURING = 1 as const;
13+
const RESIZE_STABLE = 2 as const;
14+
15+
type ResizeState =
16+
| typeof RESIZE_START
17+
| typeof RESIZE_MEASURING
18+
| typeof RESIZE_STABLE;
1419

1520
const ResizableTextArea = React.forwardRef<ResizableTextAreaRef, TextAreaProps>(
1621
(props, ref) => {
@@ -62,34 +67,9 @@ const ResizableTextArea = React.forwardRef<ResizableTextAreaRef, TextAreaProps>(
6267

6368
const needAutoSize = !!autoSize;
6469

65-
// =============================== Scroll ===============================
66-
// https://github.com/ant-design/ant-design/issues/21870
67-
const fixFirefoxAutoScroll = () => {
68-
try {
69-
const isFirefox = navigator.userAgent.includes('Firefox');
70-
// FF has bug with jump of scroll to top. We force back here.
71-
if (isFirefox && document.activeElement === textareaRef.current) {
72-
const { scrollTop, selectionStart, selectionEnd } =
73-
textareaRef.current;
74-
75-
// Fix Safari bug which not rollback when break line
76-
// This makes Chinese IME can't input. Do not fix this
77-
// const { value: tmpValue } = textareaRef.current;
78-
// textareaRef.current.value = '';
79-
// textareaRef.current.value = tmpValue;
80-
81-
textareaRef.current.setSelectionRange(selectionStart, selectionEnd);
82-
textareaRef.current.scrollTop = scrollTop;
83-
}
84-
} catch (e) {
85-
// Fix error in Chrome:
86-
// Failed to read the 'selectionStart' property from 'HTMLInputElement'
87-
// http://stackoverflow.com/q/21177489/3040605
88-
}
89-
};
90-
9170
// =============================== Resize ===============================
92-
const [resizeState, setResizeState] = React.useState(RESIZE_STABLE);
71+
const [resizeState, setResizeState] =
72+
React.useState<ResizeState>(RESIZE_STABLE);
9373
const [autoSizeStyle, setAutoSizeStyle] =
9474
React.useState<React.CSSProperties>();
9575

@@ -133,7 +113,8 @@ const ResizableTextArea = React.forwardRef<ResizableTextAreaRef, TextAreaProps>(
133113
setResizeState(RESIZE_STABLE);
134114
setAutoSizeStyle(textareaStyles);
135115
} else {
136-
fixFirefoxAutoScroll();
116+
// https://github.com/react-component/textarea/pull/23
117+
// Firefox has blink issue before but fixed in latest version.
137118
}
138119
}, [resizeState]);
139120

0 commit comments

Comments
 (0)