Skip to content

Commit

Permalink
fix(input-number): add logic
Browse files Browse the repository at this point in the history
  • Loading branch information
koory1st committed Nov 22, 2023
1 parent 3eb47cd commit ffd46a6
Showing 1 changed file with 30 additions and 3 deletions.
33 changes: 30 additions & 3 deletions packages/input-number/src/lib/input-number.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,42 @@
import { SvelIcon, ArrowDown, Minus, ArrowUp, Plus } from '@svelement-ui/icon';
import SvelInput from '@svelement-ui/input';
let controls = true;
export let controls = true;
/** @type {'' | 'right'} */
let controlsPosition = '';
export let controlsPosition = '';
/** @type {string} */
export let placeholder = '';
/** @type {number | ''} */
export let value = '';
/** @type {number | null} */
export let precision = null;
$: classString = a2s(['svel-input-number', $$props.class]);
$: decreaseClass = a2s(['svel-input-number__decrease']);
$: increaseClass = a2s(['svel-input-number__increase']);
$: controlsAtRight = controls && controlsPosition === 'right';
let inputRef;
$: dataCurrentValue = value;
$: dataUserInput = null;
function getDisplayValue(dataCurrentValue, dataUserInput) {
if (dataUserInput !== null) {
return dataUserInput;
}
let currentValue = dataCurrentValue;
if (currentValue === undefined || currentValue === null) {
return '';
}
// todo:
if (Object.prototype.toString.call(currentValue).toLowerCase() === '') {
currentValue = currentValue.toFixed(precision);
}
return currentValue;
}
$: displayValue = getDisplayValue(dataCurrentValue, dataUserInput);
</script>

<div class={classString}>
Expand All @@ -35,5 +62,5 @@
</SvelIcon>
</span>
{/if}
<SvelInput />
<SvelInput bind:this={inputRef} bind:value={displayValue} {placeholder} type="number" />
</div>

0 comments on commit ffd46a6

Please sign in to comment.