Skip to content

Commit 5537c53

Browse files
committed
fix: #1625
fix: Input add @deprecated message for onInput, onFocus, onBlur, onKeydown feat: add oninput, onfocus, onblur, onkeydown
1 parent 33d4597 commit 5537c53

File tree

5 files changed

+37
-18
lines changed

5 files changed

+37
-18
lines changed

src/lib/forms/input-field/Input.svelte

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,14 @@
33
import { CloseButton, type SizeType, type InputProps, type InputValue, cn } from "$lib";
44
import { input, clampSize } from ".";
55
6-
let { children, left, right, value = $bindable(), elementRef = $bindable(), clearable = false, size, color = "default", class: className, wrapperClass, leftClass, rightClass, divClass, clearableSvgClass, clearableColor = "none", clearableClass, clearableOnClick, data = [], maxSuggestions = 5, onSelect, comboClass, comboItemClass, onInput, onFocus, onBlur, onKeydown, ...restProps }: InputProps<InputValue> = $props();
6+
let { children, left, right, value = $bindable(), elementRef = $bindable(), clearable = false, size, color = "default", class: className, wrapperClass, leftClass, rightClass, divClass, clearableSvgClass, clearableColor = "none", clearableClass, clearableOnClick, data = [], maxSuggestions = 5, onSelect, comboClass, comboItemClass, onInput, onFocus, onBlur, onKeydown, oninput, onfocus, onblur, onkeydown, ...restProps }: InputProps<InputValue> = $props();
7+
8+
// onSelect is a custom combobox selection handler that takes a string
9+
// standard DOM events, onInput, onFocus, onBlur, onKeydown will be deprecated in the next minor version
10+
const resolvedOnInput = $derived(oninput || onInput);
11+
const resolvedOnFocus = $derived(onfocus || onFocus);
12+
const resolvedOnBlur = $derived(onblur || onBlur);
13+
const resolvedOnKeydown = $derived(onkeydown || onKeydown);
714
815
// Automatically enable combobox when data is provided
916
const isCombobox = $derived(Array.isArray(data) && data.length > 0);
@@ -143,29 +150,29 @@
143150
144151
// Combined event handlers that call custom handlers first, then default behavior
145152
function handleInput(event: Event) {
146-
if (onInput) {
147-
onInput(event);
153+
if (resolvedOnInput) {
154+
resolvedOnInput(event);
148155
}
149156
defaultHandleInput(event);
150157
}
151158
152159
function handleFocus(event: FocusEvent) {
153-
if (onFocus) {
154-
onFocus(event);
160+
if (resolvedOnFocus) {
161+
resolvedOnFocus(event);
155162
}
156163
defaultHandleFocus(event);
157164
}
158165
159166
function handleBlur(event: FocusEvent) {
160-
if (onBlur) {
161-
onBlur(event);
167+
if (resolvedOnBlur) {
168+
resolvedOnBlur(event);
162169
}
163170
defaultHandleBlur(event);
164171
}
165172
166173
function handleKeydown(event: KeyboardEvent) {
167-
if (onKeydown) {
168-
onKeydown(event);
174+
if (resolvedOnKeydown) {
175+
resolvedOnKeydown(event);
169176
}
170177
defaultHandleKeydown(event);
171178
}

src/lib/types.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -780,9 +780,17 @@ export interface InputProps<T extends InputValue = string> extends Omit<HTMLInpu
780780
onSelect?: (item: string) => void;
781781
comboClass?: ClassValue;
782782
comboItemClass?: ClassValue;
783+
oninput?: (event: Event) => void;
784+
onfocus?: (event: FocusEvent) => void;
785+
onblur?: (event: FocusEvent) => void;
786+
onkeydown?: (event: KeyboardEvent) => void;
787+
/** @deprecated Use `oninput` instead. Will be removed in next minor version. */
783788
onInput?: (event: Event) => void;
789+
/** @deprecated Use `onfocus` instead. Will be removed in next minor version. */
784790
onFocus?: (event: FocusEvent) => void;
791+
/** @deprecated Use `onblur` instead. Will be removed in next minor version. */
785792
onBlur?: (event: FocusEvent) => void;
793+
/** @deprecated Use `onkeydown` instead. Will be removed in next minor version. */
786794
onKeydown?: (event: KeyboardEvent) => void;
787795
}
788796

src/routes/docs/forms/input-field.md

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,11 @@ text with one click.
111111
/>
112112
```
113113

114-
## Custom Event Handlers
114+
## Event Handlers
115+
116+
Use lowercase event handlers: `oninput`, `onfocus`, `onblur`, `onkeydown`.
117+
118+
**Migration**: `OnInput`, `onFocus`, `onBlur`, and `onKeydown` will be **deprecated** from version v1.7.0.
115119

116120
```svelte example
117121
<script lang="ts">
@@ -122,10 +126,10 @@ text with one click.
122126
<P class="my-4">{value}</P>
123127
<Input
124128
bind:value
125-
onInput={(e) => console.log("Custom input:", e)}
126-
onFocus={(e) => console.log("Input focused")}
127-
onBlur={(e) => console.log("Input blurred")}
128-
onKeydown={(e) => {
129+
oninput={(e) => console.log("Custom input:", e)}
130+
onfocus={(e) => console.log("Input focused")}
131+
onblur={(e) => console.log("Input blurred")}
132+
onkeydown={(e) => {
129133
if (e.key === "Tab") {
130134
console.log("Tab pressed");
131135
}

src/routes/utils/ExampleDarkMode.svelte

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<script lang="ts">
22
let { dark, onclick }: { dark: boolean; onclick: () => void } = $props();
3-
console.log("dark in example: ", dark);
3+
// console.log("dark in example: ", dark);
44
</script>
55

66
<button {onclick} type="button" class="hover:text-primary-700 dark:hover:text-primary-600 me-2 flex items-center rounded-lg border border-gray-200 bg-white p-2 text-xs font-medium text-gray-700 hover:bg-gray-100 focus:z-10 focus:ring-2 focus:ring-gray-300 focus:outline-hidden dark:border-gray-600 dark:bg-gray-800 dark:text-gray-400 dark:hover:bg-gray-700 dark:hover:text-white dark:focus:ring-gray-500">

src/routes/utils/ExampleWrapper.svelte

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@
5353
if (document && document.documentElement) {
5454
// Get the current dark mode state from document
5555
const isDark = document.documentElement.classList.contains("dark");
56-
console.log("Dark mode detected from document:", isDark);
56+
// console.log("Dark mode detected from document:", isDark);
5757
5858
// Reset independent mode when document dark mode changes
5959
if (independentDarkMode) {
@@ -70,7 +70,7 @@
7070
// Sync the iframe dark mode with the current dark state
7171
function syncIframeDarkMode(): void {
7272
if (iframe && iframe.contentDocument) {
73-
console.log("Syncing iframe dark mode:", dark);
73+
// console.log("Syncing iframe dark mode:", dark);
7474
if (dark) {
7575
iframe.contentDocument.documentElement.classList.add("dark");
7676
} else {
@@ -98,7 +98,7 @@
9898
9999
// Initial dark mode check
100100
dark = document.documentElement.classList.contains("dark");
101-
console.log("Initial dark mode state:", dark);
101+
// console.log("Initial dark mode state:", dark);
102102
103103
// Set up a mutation observer to watch for class changes on documentElement
104104
documentObserver = new MutationObserver((mutations) => {

0 commit comments

Comments
 (0)