Skip to content

Commit 6a06167

Browse files
committed
fix: add class to combo item in Input.svelte
1 parent 015c790 commit 6a06167

File tree

3 files changed

+6
-4
lines changed

3 files changed

+6
-4
lines changed

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
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,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, ...restProps }: InputProps<InputValue> = $props();
77
88
// Automatically enable combobox when data is provided
99
const isCombobox = $derived(Array.isArray(data) && data.length > 0);
@@ -19,7 +19,7 @@
1919
let _size = $derived(size || clampSize(group?.size) || "md");
2020
const _color = $derived(color === "default" && background ? "tinted" : color);
2121
22-
const { base, input: inputCls, left: leftCls, right: rightCls, clearbtn, combo } = $derived(input({ size: _size, color: _color, group: isGroup }));
22+
const { base, input: inputCls, left: leftCls, right: rightCls, clearbtn, combo, comboItem } = $derived(input({ size: _size, color: _color, group: isGroup }));
2323
2424
const clearAll = () => {
2525
if (elementRef) {
@@ -202,7 +202,7 @@
202202
<div class={cn(combo(), comboClass)}>
203203
{#each filteredSuggestions as item, i}
204204
<button type="button" class="w-full px-3 py-2 text-left {i === selectedIndex ? 'bg-gray-100 dark:bg-gray-700' : 'hover:bg-gray-50 dark:hover:bg-gray-700'} focus:outline-none" onclick={() => selectItem(item)} onmouseenter={() => (selectedIndex = i)}>
205-
{item}
205+
<p class={cn(comboItem(),comboItemClass)}>{item}</p>
206206
</button>
207207
{/each}
208208
</div>

src/lib/forms/input-field/theme.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ export const input = tv({
99
left: "flex absolute inset-y-0 items-center text-gray-500 dark:text-gray-400 pointer-events-none start-0 p-2.5",
1010
right: "flex absolute inset-y-0 items-center text-gray-500 dark:text-gray-400 end-0 p-2.5",
1111
clearbtn: "absolute right-2 top-1/2 -translate-y-1/2 text-gray-400 hover:text-black",
12-
combo: "absolute top-full right-0 left-0 z-20 mt-1 max-h-60 overflow-y-auto rounded-md border border-gray-200 bg-white shadow-lg dark:border-gray-700 dark:bg-gray-800"
12+
combo: "absolute top-full right-0 left-0 z-20 mt-1 max-h-60 overflow-y-auto rounded-md border border-gray-200 bg-white shadow-lg dark:border-gray-700 dark:bg-gray-800",
13+
comboItem: "text-gray-900 dark:text-gray-50"
1314
},
1415
variants: {
1516
size: {

src/lib/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -772,6 +772,7 @@ export interface InputProps<T extends InputValue = string> extends Omit<HTMLInpu
772772
maxSuggestions?: number;
773773
onSelect?: (item: string) => void;
774774
comboClass?: ClassValue;
775+
comboItemClass?: ClassValue;
775776
onInput?: (event: Event) => void;
776777
onFocus?: (event: FocusEvent) => void;
777778
onBlur?: (event: FocusEvent) => void;

0 commit comments

Comments
 (0)