Skip to content

Commit e5235bf

Browse files
authored
Use an event and dispatch it instead of adding event handlers the other way. (#2440)
1 parent 76f0122 commit e5235bf

File tree

2 files changed

+7
-12
lines changed

2 files changed

+7
-12
lines changed

src/lib/holocene/combobox/async-test.svelte

+5-5
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@
1414
1515
export let id = '';
1616
17-
function keypress(stuff) {
17+
function input(stuff: CustomEvent) {
1818
loading = true;
19-
value = stuff.target.value;
20-
19+
value = stuff.detail;
20+
console.log(value);
2121
options = syncOptions;
2222
2323
// This makes sure the worst case always happens the newest value comes first
@@ -41,7 +41,7 @@
4141
// console.log("it's old!", { value });
4242
}
4343
},
44-
2000 + i * 100,
44+
2000 + i * 25,
4545
value,
4646
);
4747
}
@@ -50,7 +50,7 @@
5050
<Combobox
5151
bind:value
5252
{options}
53-
{keypress}
53+
on:input={input}
5454
on:change={(newVal) => {
5555
console.log('change', newVal);
5656
}}

src/lib/holocene/combobox/combobox.svelte

+2-7
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
change: { value: string | T };
2525
filter: string;
2626
close: { selectedOption: string | T };
27+
input: string;
2728
}>();
2829
2930
type ExtendedInputEvent = Event & {
@@ -48,11 +49,6 @@
4849
actionTooltip?: string;
4950
href?: string;
5051
hrefDisabled?: boolean;
51-
/**
52-
* Use Keypress to receive the event after the combobox has done it's updating for async operations
53-
* @param event
54-
*/
55-
keypress?: (event: KeyboardEvent) => void;
5652
loading?: boolean;
5753
loadingText?: string;
5854
}
@@ -99,7 +95,6 @@
9995
export let label: string;
10096
export let multiselect = false;
10197
export let value: string | string[] = multiselect ? [] : undefined;
102-
export let keypress: BaseProps['keypress'] = () => {};
10398
export let noResultsText: string;
10499
export let disabled = false;
105100
export let labelHidden = false;
@@ -331,6 +326,7 @@
331326
// Reactive statement at top makes this work, not my favorite tho
332327
displayValue = event.currentTarget.value;
333328
filterValue = displayValue;
329+
dispatch('input', displayValue);
334330
};
335331
336332
function filterOptions(value: string, options: (T | string)[]) {
@@ -418,7 +414,6 @@
418414
on:focus|stopPropagation={openList}
419415
on:input|stopPropagation={handleInput}
420416
on:keydown|stopPropagation={handleInputKeydown}
421-
on:keyup={keypress}
422417
on:click|stopPropagation={handleInputClick}
423418
data-testid={$$props['data-testid'] ?? id}
424419
bind:this={inputElement}

0 commit comments

Comments
 (0)