Skip to content

Commit d64bec0

Browse files
committed
fix: check for NaN value when floating the label in text field
1 parent 8fc244e commit d64bec0

File tree

3 files changed

+10
-3
lines changed

3 files changed

+10
-3
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 & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@
104104
105105
function toNumber(value: string) {
106106
if (value === '') {
107-
return NaN;
107+
return Number.NaN;
108108
}
109109
return +value;
110110
}

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)