TheComputerM / svelte-materialify

A Material UI Design Component library for Svelte heavily inspired by vuetify.
https://svelte-materialify.vercel.app
MIT License
621 stars 84 forks source link

Numeric values from TextField #105

Open rhard opened 3 years ago

rhard commented 3 years ago

Is there any way how to receive the number from TextField instead of string? The next code returns string:

let value = 0;
...
<TextField type="number" bind:value={value}>Numeric field</TextField>
Florian-Schoenherr commented 3 years ago

We would need to change from binding to using on:input to do that. Would you mind doing this instead?

<TextField on:input={(e) => value = +e.target.value}>Numeric field</TextField>
rhard commented 3 years ago

Thanks for the suggestion. I currently fixed it by using:

    $: nbrSlowInterval = Number(strSlowInterval);
    $: nbrWeatherInterval = Number(strWeatherInterval);
Florian-Schoenherr commented 3 years ago

@rhard keep it DRY 😉

<TextField on:input={() => nbrSlowInterval = Number(e.target.value)}>SlowInterval</TextField>
<TextField on:input={() => nbrWeatherInterval = Number(e.target.value)}>WeatherInterval</TextField>

But you probably want native input-number functionality (like these little arrows), right?

rhard commented 3 years ago

Exactly! I was expecting this is already there like in others frameworks by default.

Florian-Schoenherr commented 3 years ago

TextField uses <input type="text" bind:value> inside, sadly <input {type} bind:value> is not possible, svelte forbids it. We could change to use <input {type} {value} on:input={(e) => parse(type, e.target.value)}> or something like that. Might be less performant.. probably gonna add <NumberField/> instead, because we will also have <DatePicker/>.

For now, maybe it would look more "material" to use a Slider instead.

frankieali commented 3 years ago

Can't you use e.target.valueAsNumber when type="number" is set?