Skip to content

Commit

Permalink
crucial tgui fix taken from tg (#462)
Browse files Browse the repository at this point in the history
  • Loading branch information
notfrying1pans authored Apr 13, 2024
1 parent 896f9bf commit f716052
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 14 deletions.
20 changes: 7 additions & 13 deletions tgui/packages/tgui/components/Input.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ export function Input(props: Props) {
...rest
} = props;

// The ref to the input field
const inputRef = useRef<HTMLInputElement>(null);

function handleInput(event: SyntheticEvent<HTMLInputElement>) {
Expand Down Expand Up @@ -136,11 +137,15 @@ export function Input(props: Props) {

/** Focuses the input on mount */
useEffect(() => {
if (!autoFocus && !autoSelect) return;

const input = inputRef.current;
if (!input) return;

const newValue = toInputValue(value);

if (input.value !== newValue) input.value = newValue;

if (!autoFocus && !autoSelect) return;

setTimeout(() => {
input.focus();

Expand All @@ -150,17 +155,6 @@ export function Input(props: Props) {
}, 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 (
<Box
className={classes([
Expand Down
2 changes: 1 addition & 1 deletion tgui/packages/tgui/components/VirtualList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export const VirtualList = (props: PropsWithChildren) => {

setPadding((children.length - newVisibleElements) * averageItemHeight);
}
}, [containerRef, visibleElements, setVisibleElements, setPadding]);
}, [containerRef, visibleElements, children]);

useEffect(() => {
adjustExtents();
Expand Down

0 comments on commit f716052

Please sign in to comment.