breaking(number-input): type value as null | number (#1044)

Fixes #1039
This commit is contained in:
metonym 2022-01-27 06:57:32 -08:00 committed by GitHub
commit 9e915cf90a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 58 additions and 58 deletions

View file

@ -1,7 +1,7 @@
<script>
/**
* @typedef {"increment" | "decrement"} NumberInputTranslationId
* @event {number} change
* @event {null | number} change
*/
/**
@ -11,10 +11,11 @@
export let size = undefined;
/**
* Specify the input value
* @type {number | string}
* Specify the input value.
* Use `null` to denote "no value"
* @type {null | number}
*/
export let value = "";
export let value = null;
/** Specify the step increment */
export let step = 1;
@ -131,17 +132,12 @@
let inputValue = value;
const normalizeValue = (_value) => {
if (_value === undefined || _value === "") return _value;
return Number(_value);
};
$: dispatch("change", value);
$: incrementLabel = translateWithId("increment");
$: decrementLabel = translateWithId("decrement");
$: value = normalizeValue(inputValue);
$: value = inputValue ? Number(inputValue) : null;
$: error =
invalid || (!allowEmpty && value === "") || value > max || value < min;
invalid || (!allowEmpty && value == null) || value > max || value < min;
$: errorId = `error-${id}`;
$: ariaLabel =
$$props["aria-label"] ||
@ -208,7 +204,7 @@
max="{max}"
min="{min}"
step="{step}"
value="{value}"
value="{value ?? ''}"
readonly="{readonly}"
{...$$restProps}
on:input
@ -263,7 +259,7 @@
max="{max}"
min="{min}"
step="{step}"
value="{value}"
value="{value ?? ''}"
readonly="{readonly}"
{...$$restProps}
on:input