981377660LMT / ts

ts学习
6 stars 1 forks source link

input 光标位置保持不变 #443

Open 981377660LMT opened 7 months ago

981377660LMT commented 7 months ago
  const keepFocusPosition = (): void => {
    const preFocusPosition = inputRef.current?.selectionStart ?? 0;
    setTimeout(() => {
      inputRef.current?.setSelectionRange(preFocusPosition, preFocusPosition);
    }, 0);
  };