mirror of
https://github.com/portainer/portainer.git
synced 2025-07-24 15:59:41 +02:00
refactor(gitops): migrate git form to react [EE-4849] (#8268)
This commit is contained in:
parent
afe6cd6df0
commit
273a3f9a10
130 changed files with 3194 additions and 1190 deletions
26
app/react/components/form-components/useCaretPosition.ts
Normal file
26
app/react/components/form-components/useCaretPosition.ts
Normal file
|
@ -0,0 +1,26 @@
|
|||
import { useRef, useState, useCallback, useEffect } from 'react';
|
||||
|
||||
export function useCaretPosition<
|
||||
T extends HTMLInputElement | HTMLTextAreaElement = HTMLInputElement
|
||||
>() {
|
||||
const node = useRef<T>(null);
|
||||
const [start, setStart] = useState(0);
|
||||
const [end, setEnd] = useState(0);
|
||||
|
||||
const updateCaret = useCallback(() => {
|
||||
if (node.current) {
|
||||
const { selectionStart, selectionEnd } = node.current;
|
||||
|
||||
setStart(selectionStart || 0);
|
||||
setEnd(selectionEnd || 0);
|
||||
}
|
||||
}, []);
|
||||
|
||||
useEffect(() => {
|
||||
if (node.current) {
|
||||
node.current.setSelectionRange(start, end);
|
||||
}
|
||||
});
|
||||
|
||||
return { start, end, ref: node, updateCaret };
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue