Elius94 / console-gui-tools

A simple library to draw option menu or other popup inputs and layout on Node.js console.
MIT License
106 stars 17 forks source link

[Bug]: OptionPopup - selected prop = "" is considered undefined #68

Closed Elius94 closed 1 year ago

Elius94 commented 1 year ago

What happened?

If you define a OptionPopup with selected: "", it throw a error considering selected undefined.

What should have happened?

It should allow to set it to empty string

Code

new OptionPopup({
  id: "testBox",
  title: "title",
  options: opts,
  selected: ""
})

Library Version

3.0.4

Node Version

19.3

What operating system are you using?

Windows

Terminal

Windows Terminal

Interest to fix the bug

Compositr commented 1 year ago

Did some further testing, anything that is falsy will throw an error because the if statement just uses a ! rather than a strict test for null | undefined

Bugged code https://github.com/Elius94/console-gui-tools/blob/6e68febe7cfa364b236d48f7ec110e1fe41fd2d1/src/components/widgets/OptionPopup.ts#L79

Elius94 commented 1 year ago

You are right! In addition I think that empty strings in node are considered false if you test them. Tnaks

Compositr commented 1 year ago

Opening a PR to address it if you don't mind. #69