Skip to content

Commit

Permalink
Fixes certain prefs menu fields not updating when swapping character …
Browse files Browse the repository at this point in the history
…slots (tgstation#86495)

## About The Pull Request

Fixes NovaSector/NovaSector#4268

My second time fixing this bug...was broken again by
tgstation#81968 very shortly after I
fixed it.

Puts the gutted code that was necessary for this was happen back where
it belongs and locks it behind a conditional so it should not cause any
lag.

## Why It's Good For The Game

Restores missing functionality required for certain tgui components and
makes preferences menu useable again.

<details><summary>Before (watch the ringtone field)</summary>


![Yd1Af0Hx5e](https://github.com/user-attachments/assets/bbc4d1ee-7021-4db3-9e18-baa97efb227f)

</details>

<details><summary>After (now it updates properly)</summary>


![OvdRvWRhFe](https://github.com/user-attachments/assets/d2d71f78-e442-4c52-8fa5-7843272c511f)

</details>


## Changelog

:cl:
fix: certain text input fields in the character setup menu will now
update properly when swapping character slots
/:cl:

Co-authored-by: Ghom <[email protected]>
  • Loading branch information
vinylspiders and Ghommie authored Sep 8, 2024
1 parent ed34376 commit 5691449
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
16 changes: 16 additions & 0 deletions tgui/packages/tgui/components/Input.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ type OptionalProps = Partial<{
placeholder: string;
/** Clears the input value on enter */
selfClear: boolean;
/** Auto-updates the input value on props change */
updateOnPropsChange: boolean;
/** The state variable of the input. */
value: string | number;
}>;
Expand Down Expand Up @@ -96,6 +98,7 @@ export function Input(props: Props) {
placeholder,
selfClear,
value,
updateOnPropsChange,
...rest
} = props;

Expand Down Expand Up @@ -155,6 +158,19 @@ export function Input(props: Props) {
}, 1);
}, []);

if (updateOnPropsChange) {
/** 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
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,7 @@ export const FeatureShortTextInput = (
width="100%"
value={props.value}
maxLength={props.serverData.maximum_length}
updateOnPropsChange
onChange={(_, value) => props.handleSetValue(value)}
/>
);
Expand Down

0 comments on commit 5691449

Please sign in to comment.