InputAttributes should accept (boolean | string | number) values
See original GitHub issueAs you can see here: https://github.com/sweetalert2/sweetalert2/blob/138b5c87e84cb73e917c2efb81a5578b17067391/sweetalert2.d.ts#L632
… inputAttributes
only accepts string
values, however even in examples, you can see maxLength
attribute being passed as number
.
Also, I think it could accept also boolean
allowing people to do something like:
inputAttributes: {
autofocus: true
// ...
}
Also, I think the inputValue
parameter should be boolean | number | string
instead of any
:
Issue Analytics
- State:
- Created 6 years ago
- Reactions:2
- Comments:6 (6 by maintainers)
Top Results From Across the Web
Using boolean-value of attributes in JSX - Stack Overflow
You can just omit the value assignment; the attribute will be assigned a value of true by default. Instead of doing any of:...
Read more ><input>: The Input (Form Input) element - HTML
(Not a Boolean attribute!) The autocomplete attribute takes as its value a space-separated string that describes what, if any, type of ...
Read more >How To Use HTML5 Input Types | DigitalOcean
required - boolean to indicate if the value is required before the <form> can be submitted; tabindex - number to indicate which order...
Read more >Boolean attributes - HTML Spec
A number of attributes are boolean attributes . ... If the attribute is present, its value must either be the empty string or...
Read more >lightning-input - documentation - Salesforce Developers
As a result, a number that should be invalid can be accepted as valid due to the loss of precision in the stored...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Hello @rafaelss95, thanks for your careful reading of the declaration file 😃
SweetAlert2 uses
Element.setAttribute
, which takes astring
for the attribute values. In fact, HTML attributes can only bear string values, don’t forget that. If you set a number like42
, it will be stored as"42"
because JavaScript would call.toString()
on anything that’s not already a string. That’s why passing a number will “work”, but technically you can also pass objects, symbols, space shuttles and cats. But this is wrong as JS will perform type coercion, and your space shuttle will silently be transformed in"[object Object]"
.In TypeScript, you’ll have to be stricter here and explicitely use
toString()
, so you are explicit about the fact that you’re transforming the value and loosing information.The same goes for
inputValue
, SweetAlert2 usesHTMLInputElement.value
, which exclusively takes strings.@toverux Just submtted a PR. Please, have a look and let me know if I’m missing something…