Skip to content

Commit 6f6544e

Browse files
committed
fix: chip input leaves add key in input after adding chip
Closes #703
1 parent d9ddb12 commit 6f6544e

File tree

3 files changed

+23
-6
lines changed

3 files changed

+23
-6
lines changed

packages/chip-input/src/ChipInput.svelte

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -95,10 +95,6 @@
9595
bind:this={input}
9696
bind:value={text}
9797
{...prefixFilter(restProps, 'input$')}
98-
onkeydown={(e) => {
99-
handleInputKeydown(e);
100-
restProps.input$onkeydown?.(e);
101-
}}
10298
/>
10399
</Textfield>
104100
{#snippet loading()}
@@ -118,6 +114,8 @@
118114

119115
<script lang="ts">
120116
import type { ComponentProps, Snippet } from 'svelte';
117+
import { onMount } from 'svelte';
118+
import { on } from 'svelte/events';
121119
import type { SmuiAttrs } from '@smui/common';
122120
import type { ActionArray } from '@smui/common/internal';
123121
import {
@@ -321,6 +319,26 @@
321319
...(key != null ? { key } : {}),
322320
});
323321
322+
onMount(() => {
323+
const el = input?.getElement();
324+
325+
if (el) {
326+
return on(
327+
el,
328+
'keydown',
329+
(e) => {
330+
handleInputKeydown(e);
331+
restProps.input$onkeydown?.(
332+
e as KeyboardEvent & {
333+
currentTarget: EventTarget & HTMLInputElement;
334+
},
335+
);
336+
},
337+
{ passive: false },
338+
);
339+
}
340+
});
341+
324342
function handleAutocompleteSelected(event: CustomEvent<any>) {
325343
event.preventDefault();
326344

packages/site/src/routes/demo/chip-input/+page.svelte

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
<Demo component={Objects} file="chip-input/_Objects.svelte">
2121
Objects
2222
{#snippet subtitle()}
23-
Objects allow you to have dupliate entries.
23+
Objects allow you to have duplicate entries.
2424
{/snippet}
2525
</Demo>
2626

packages/textfield/src/Input.svelte

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,6 @@
143143
case 'range':
144144
value = toNumber(e.currentTarget.value);
145145
break;
146-
// Fall through.
147146
default:
148147
value = e.currentTarget.value;
149148
break;

0 commit comments

Comments
 (0)