|
3 | 3 | import { CloseButton, type SizeType, type InputProps, type InputValue, cn } from "$lib";
|
4 | 4 | import { input, clampSize } from ".";
|
5 | 5 |
|
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); |
7 | 14 |
|
8 | 15 | // Automatically enable combobox when data is provided
|
9 | 16 | const isCombobox = $derived(Array.isArray(data) && data.length > 0);
|
|
143 | 150 |
|
144 | 151 | // Combined event handlers that call custom handlers first, then default behavior
|
145 | 152 | function handleInput(event: Event) {
|
146 |
| - if (onInput) { |
147 |
| - onInput(event); |
| 153 | + if (resolvedOnInput) { |
| 154 | + resolvedOnInput(event); |
148 | 155 | }
|
149 | 156 | defaultHandleInput(event);
|
150 | 157 | }
|
151 | 158 |
|
152 | 159 | function handleFocus(event: FocusEvent) {
|
153 |
| - if (onFocus) { |
154 |
| - onFocus(event); |
| 160 | + if (resolvedOnFocus) { |
| 161 | + resolvedOnFocus(event); |
155 | 162 | }
|
156 | 163 | defaultHandleFocus(event);
|
157 | 164 | }
|
158 | 165 |
|
159 | 166 | function handleBlur(event: FocusEvent) {
|
160 |
| - if (onBlur) { |
161 |
| - onBlur(event); |
| 167 | + if (resolvedOnBlur) { |
| 168 | + resolvedOnBlur(event); |
162 | 169 | }
|
163 | 170 | defaultHandleBlur(event);
|
164 | 171 | }
|
165 | 172 |
|
166 | 173 | function handleKeydown(event: KeyboardEvent) {
|
167 |
| - if (onKeydown) { |
168 |
| - onKeydown(event); |
| 174 | + if (resolvedOnKeydown) { |
| 175 | + resolvedOnKeydown(event); |
169 | 176 | }
|
170 | 177 | defaultHandleKeydown(event);
|
171 | 178 | }
|
|
0 commit comments