Skip to content

Commit

Permalink
[MIRROR] Fixes TextInputModal not updating state on consecutive inputs (
Browse files Browse the repository at this point in the history
#1498) (#2457)

* Fixes TextInputModal not updating state on consecutive inputs (#82018)

## About The Pull Request

Fixes an issue encountered on another codebase (VOREStation,
VOREStation/VOREStation#15831 ) where multiple
consecutive calls of tgui_text_input() within the same procedure inherit
the input value of the previous procedure call (such as in the following
example procedure:

```
  /client/verb/testing_tgui_text_input()
	  set name = "TESTING TEXT INPUT"
	  set category = "Debug"
	  set desc = "meh"
  
	  var/a = tgui_input_text(usr, "test 1 input", "testing", null)
	  to_chat(usr, "a is [a]")
	  var/b = tgui_input_text(usr, "test 2 input", "testing", "test 2")
	  to_chat(usr, "b is [b]")
	  var/c = tgui_input_text(usr, "test 3 input", "testing", "blabla")
	  to_chat(usr, "c is [c]")
```

Previous functionality will mean that the default text for input 2 and
input 3 will be null if submitting without changing the text. Changing
null for var/a 's default to any proper, non-empty string will cause b
and c to be a.

In event of actual user input, the same behaviour persists (test input
1's user input will become the default of test input 2's user input and
so forth

New functionality ensures that the default argument/placeholder prop is
used to populate the text input area even in consecutive calls)

This is achieved through a single-line edit of the TextInputModal.tsx in
the InputArea component call's props, creating a key={title} prop that
ensures consecutive text inputs will use different states.
## Why It's Good For The Game

There are times where multiple consecutive tgui_text_input() may be
justified. Although I see that in case of the issue example of
/client/proc/cmd_admin_create_centcom_report(), it was given a custom
input menu rather than consecutive input calls, certain
downstreams/adjacent codebases may have requiremens of backwards
compatibility that needs code that can default to default byond style
input windows.

I will admit, I do not know how useful this fix will be for TGStation
itself, but its implementation causes no negative repercussions and
fixes a bug experienced elsewhere. This will help ensure code parity.

This is an early upport of the fix we've applied on virgo
(VOREStation/VOREStation#15832)
## Changelog
:cl:
fix: fixed consecutive tgui text input inheriting user input from
previous input form within the same proc
/:cl:

* Fixes TextInputModal not updating state on consecutive inputs

---------

Co-authored-by: NovaBot <[email protected]>
Co-authored-by: Runa Dacino <[email protected]>
  • Loading branch information
3 people authored Mar 18, 2024
1 parent a24b4f8 commit 119c3d8
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion tgui/packages/tgui/interfaces/TextInputModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ export const TextInputModal = (props) => {
<Box color="label">{message}</Box>
</Stack.Item>
<Stack.Item grow>
<InputArea input={input} onType={onType} />
<InputArea key={title} input={input} onType={onType} />
</Stack.Item>
<Stack.Item>
<InputButtons
Expand Down

0 comments on commit 119c3d8

Please sign in to comment.