diff --git a/tgui/packages/tgui/components/Input.tsx b/tgui/packages/tgui/components/Input.tsx index c515627b8c1..d9b517f1cb5 100644 --- a/tgui/packages/tgui/components/Input.tsx +++ b/tgui/packages/tgui/components/Input.tsx @@ -77,22 +77,33 @@ export const Input = (props: Props) => { } }; + /** Focuses the input on mount */ useEffect(() => { + if (!autoFocus && !autoSelect) return; + const input = inputRef.current; if (!input) return; - input.value = toInputValue(value); - if (autoFocus || autoSelect) { - setTimeout(() => { - input.focus(); + setTimeout(() => { + input.focus(); - if (autoSelect) { - input.select(); - } - }, 1); - } + if (autoSelect) { + input.select(); + } + }, 1); }, []); + /** Updates the initial value on props change */ + useEffect(() => { + const input = inputRef.current; + if (!input) return; + + const newValue = toInputValue(value); + if (input.value === newValue) return; + + input.value = newValue; + }, [value]); + return (