Skip to content

Commit d74b34e

Browse files
committed
Merge branch 'DetachHead-fix-toNumber'
2 parents f7be8d9 + d64bec0 commit d74b34e

File tree

3 files changed

+10
-5
lines changed

3 files changed

+10
-5
lines changed

MIGRATING.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ https://github.com/material-components/material-components-web/blob/master/CHANG
1515
- The "\*ComponentDev" types (like `MenuComponentDev`) are gone. You can now use the component as its type. Components that can take a `component` or `tag` prop (like `Button`) have required generic arguments that you can get around by using "InstanceType", like `let button: InstanceType<typeof Button>;`.
1616
- If you're using `classAdderBuilder`, you need to use `keyof SmuiElementMap` instead of `string` as its generic argument.
1717
- The `dispatch` function in `@smui/common` will now throw an error if either the `Event` object is not available or the `element` is not provided.
18+
- The `Input` component from the `@smui/textfield` now sets `value` to `Number.NaN` when the input is empty.
1819

1920
## Changes
2021

packages/textfield/src/Input.svelte

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -104,9 +104,7 @@
104104
105105
function toNumber(value: string) {
106106
if (value === '') {
107-
const nan = new Number(Number.NaN);
108-
(nan as unknown as Array<any>).length = 0;
109-
return nan as number;
107+
return Number.NaN;
110108
}
111109
return +value;
112110
}

packages/textfield/src/Textfield.svelte

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,10 @@
6666
{#if !noLabel && (label != null || $$slots.label)}
6767
<FloatingLabel
6868
bind:this={floatingLabel}
69-
floatAbove={focused || (value != null && value !== '')}
69+
floatAbove={focused ||
70+
(value != null &&
71+
value !== '' &&
72+
(typeof value !== 'number' || !isNaN(value)))}
7073
{required}
7174
wrapped
7275
{...prefixFilter($$restProps, 'label$')}
@@ -83,7 +86,10 @@
8386
{#if !noLabel && (label != null || $$slots.label)}
8487
<FloatingLabel
8588
bind:this={floatingLabel}
86-
floatAbove={focused || (value != null && value !== '')}
89+
floatAbove={focused ||
90+
(value != null &&
91+
value !== '' &&
92+
(typeof value !== 'number' || !isNaN(value)))}
8793
{required}
8894
wrapped
8995
{...prefixFilter($$restProps, 'label$')}

0 commit comments

Comments
 (0)