cisco-sbg-ui / magna-react

magna-react.vercel.app
5 stars 0 forks source link

ATextInput escapes \n #823

Closed vdineva closed 3 weeks ago

vdineva commented 1 month ago
  1. Type into a ATextInput component the value 123.

  2. In the console, use vanilla js to get the value of the field

  3. Observe it is returned as it should - 123 Screenshot 2024-08-05 at 11 13 10

  4. Type into a ATextInput component the value 123\n

  5. In the console, use vanilla js to get the value of the field

  6. Observe it is returned as "123\\n"

Expected behavior: the value is returned as "123\n" Screenshot 2024-08-05 at 11 13 25

related issue in the monorepo: https://cisco-sbg.atlassian.net/browse/XDR-4715

rwharrisjr commented 1 month ago

This is not a magna-react specific issue, but a consequence of JavaScript.

Trying the same steps in https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/text gives the same result - the behavior is part of how input fields and the value works.

I'd suggest manually cleaning up input data with

(str) => str.replace(/\\n/g, '\n')

Note that some platforms use \r for a newline, but I'm not sure if that would apply to the values in this scenario.


Marking this as won't fix since magna shouldn't be modifying data outside of what is native to JavaScript.