Skip to content

Commit

Permalink
Fixes input value not clearing on NTOS app [no gbp] (#143)
Browse files Browse the repository at this point in the history
* Fixes input value not clearing on NTOS app [no gbp] (#80614)

## About The Pull Request
Problem goes a little deeper than simply adding "selfClear" prop - ntos
messenger is looking for more of a controlled component. Whenever
messages are sent, it attempts to update the value in the input box
## Why It's Good For The Game
Fixes #80611
## Changelog
:cl:
fix: NTOS Messenger should clear on enter now
/:cl:

* Fixes input value not clearing on NTOS app [no gbp]

---------

Co-authored-by: Jeremiah <[email protected]>
Co-authored-by: NovaBot <[email protected]>
  • Loading branch information
3 people authored and Iajret committed Dec 28, 2023
1 parent 96d07f0 commit 0b44352
Showing 1 changed file with 20 additions and 9 deletions.
29 changes: 20 additions & 9 deletions tgui/packages/tgui/components/Input.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
<Box
className={classes([
Expand Down

0 comments on commit 0b44352

Please sign in to comment.