Skip to content

Commit f5fc2e9

Browse files
committed
fix: #1600
1 parent 97318c7 commit f5fc2e9

File tree

4 files changed

+86
-45
lines changed

4 files changed

+86
-45
lines changed

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

Lines changed: 14 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -5,30 +5,7 @@
55
import { input, clampSize } from ".";
66
import clsx from "clsx";
77
8-
let {
9-
children,
10-
left,
11-
right,
12-
value = $bindable(),
13-
elementRef = $bindable(),
14-
clearable = false,
15-
size,
16-
color = "default",
17-
class: className,
18-
wrapperClass,
19-
classLeft,
20-
classRight,
21-
divClass,
22-
clearableSvgClass,
23-
clearableColor = "none",
24-
clearableClass,
25-
clearableOnClick,
26-
// Combobox props
27-
data = [],
28-
maxSuggestions = 5,
29-
onSelect,
30-
...restProps
31-
}: InputProps<InputValue> = $props();
8+
let { children, left, right, value = $bindable(), elementRef = $bindable(), clearable = false, size, color = "default", class: className, wrapperClass, classLeft, classRight, divClass, clearableSvgClass, clearableColor = "none", clearableClass, clearableOnClick, data = [], maxSuggestions = 5, onSelect, ...restProps }: InputProps<InputValue> = $props();
329
3310
// Automatically enable combobox when data is provided
3411
const isCombobox = $derived(Array.isArray(data) && data.length > 0);
@@ -183,10 +160,9 @@
183160
<div tabindex="-1" bind:this={dummyFocusDiv} class="sr-only"></div>
184161
{/if}
185162

163+
{#if isCombobox}
186164
<div class={twMerge(isCombobox ? "relative w-full" : "", wrapperClass)}>
187-
{#if group}
188-
{@render inputContent()}
189-
{:else if right || left || clearable}
165+
{#if right || left || clearable}
190166
<div class={base({ class: divClass })}>
191167
{@render inputContent()}
192168
</div>
@@ -204,6 +180,17 @@
204180
</div>
205181
{/if}
206182
</div>
183+
{:else}
184+
{#if group}
185+
{@render inputContent()}
186+
{:else if right || left || clearable}
187+
<div class={base({ class: divClass })}>
188+
{@render inputContent()}
189+
</div>
190+
{:else}
191+
{@render inputContent()}
192+
{/if}
193+
{/if}
207194

208195
{#snippet inputContent()}
209196
{#if left}

src/routes/component-data/Input.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
["clearableColor", "\"none\""],
2323
["clearableClass", ""],
2424
["clearableOnClick", ""],
25-
["// Combobox props\n data", "[]"],
25+
["data", "[]"],
2626
["maxSuggestions", "5"],
2727
["onSelect", ""]
2828
]

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

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,33 @@ text with one click.
168168
<Input data={carMakers} clearable placeholder="Clearable" />
169169
```
170170

171+
## Combobox with icon
172+
173+
```svelte example class="h-80"
174+
<script>
175+
import { Input } from "flowbite-svelte";
176+
import { EnvelopeSolid } from "flowbite-svelte-icons";
177+
const fakeEmails = [
178+
179+
180+
181+
182+
183+
184+
185+
186+
187+
188+
];
189+
</script>
190+
191+
<Input data={fakeEmails} placeholder="[email protected]" clearable type="email" size="md" class="ps-9">
192+
{#snippet left()}
193+
<EnvelopeSolid class="h-5 w-5" />
194+
{/snippet}
195+
</Input>
196+
```
197+
171198
## Input sizes
172199

173200
Use the following examples to apply a small, default or large size for the input fields.

static/llm/forms/input-field.md

Lines changed: 44 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ On this page you will find all of the input types based on multiple variants, st
1717

1818
Use this example as a generic form element which includes multiple input fields types such as text, email, password, number, URL, and phone number and use the grid layout to add multiple columns and rows.
1919

20-
```svelte
20+
```svelte example
2121
<script>
2222
import { Input, Label, Helper, Button, Checkbox, A } from "flowbite-svelte";
2323
</script>
@@ -73,7 +73,7 @@ Use this example as a generic form element which includes multiple input fields
7373
This example shows how to create an input field where the user can remove the
7474
text with one click.
7575

76-
```svelte
76+
```svelte example
7777
<script>
7878
import { Input } from "flowbite-svelte";
7979
</script>
@@ -83,7 +83,7 @@ text with one click.
8383

8484
## Event
8585

86-
```svelte
86+
```svelte example
8787
<script>
8888
import { Input } from "flowbite-svelte";
8989
</script>
@@ -99,7 +99,7 @@ text with one click.
9999

100100
## Accessing Input Element with elementRef
101101

102-
```svelte
102+
```svelte example
103103
<script lang="ts">
104104
import { Button, Modal, Input, Label } from "flowbite-svelte";
105105
let defaultModal = $state(false);
@@ -143,7 +143,7 @@ text with one click.
143143

144144
## Combobox
145145

146-
```svelte
146+
```svelte example
147147
<script>
148148
import { Input } from "flowbite-svelte";
149149
const carMakers = ["Toyota", "Ford", "Honda", "Chevrolet", "Nissan", "BMW", "Mercedes-Benz", "Volkswagen", "Hyundai", "Kia", "Mazda", "Subaru", "Lexus", "Audi", "Jeep", "Dodge", "Ram", "GMC", "Cadillac", "Chrysler", "Buick", "Infiniti", "Acura", "Volvo", "Porsche", "Jaguar", "Land Rover", "Mini", "Mitsubishi", "Genesis", "Tesla", "Fiat", "Peugeot", "Renault", "Alfa Romeo", "Citroën", "SEAT", "Skoda", "Saab", "Suzuki", "Isuzu", "Scion", "Hummer", "Lincoln", "Opel", "Daewoo", "Rivian", "Lucid", "Polestar", "Bugatti", "Maserati", "Ferrari", "Lamborghini", "Bentley", "Rolls-Royce", "Aston Martin", "McLaren", "Pagani", "Koenigsegg", "Maybach", "Tata", "Mahindra", "Perodua", "Proton", "Chery", "Geely", "Great Wall", "BYD", "NIO", "XPeng", "VinFast", "Zotye", "FAW", "BAIC", "Lancia", "Dacia", "Cupra", "Roewe", "Holden", "Smart"];
@@ -154,13 +154,40 @@ text with one click.
154154
<Input data={carMakers} clearable placeholder="Clearable" />
155155
```
156156

157+
## Combobox with icon
158+
159+
```svelte example
160+
<script>
161+
import { Input } from "flowbite-svelte";
162+
import { EnvelopeSolid } from "flowbite-svelte-icons";
163+
const fakeEmails = [
164+
165+
166+
167+
168+
169+
170+
171+
172+
173+
174+
];
175+
</script>
176+
177+
<Input data={fakeEmails} placeholder="[email protected]" clearable type="email" size="md" class="ps-9">
178+
{#snippet left()}
179+
<EnvelopeSolid class="h-5 w-5" />
180+
{/snippet}
181+
</Input>
182+
```
183+
157184
## Input sizes
158185

159186
Use the following examples to apply a small, default or large size for the input fields.
160187

161188
User the size prop to change the input size. Choose one from 'sm:text-md' | 'text-sm' | 'sm:text-xs'. The default size is text-sm.
162189

163-
```svelte
190+
```svelte example
164191
<script>
165192
import { Input, Label } from "flowbite-svelte";
166193
</script>
@@ -185,7 +212,7 @@ User the size prop to change the input size. Choose one from 'sm:text-md' | 'tex
185212

186213
Get started with this example if you want to apply the disabled state to an input field. Add the disabled to change the input to disabled.
187214

188-
```svelte
215+
```svelte example
189216
<script>
190217
import { Input } from "flowbite-svelte";
191218
</script>
@@ -198,7 +225,7 @@ Get started with this example if you want to apply the disabled state to an inpu
198225

199226
Use the following example to apply validation styles for success and error messages.
200227

201-
```svelte
228+
```svelte example
202229
<script>
203230
import { Input, Label, Helper } from "flowbite-svelte";
204231
</script>
@@ -223,7 +250,7 @@ Use the following example to apply validation styles for success and error messa
223250

224251
## Input with icon
225252

226-
```svelte
253+
```svelte example
227254
<script>
228255
import { Label, Input, Button, CloseButton } from "flowbite-svelte";
229256
import { EnvelopeSolid } from "flowbite-svelte-icons";
@@ -264,7 +291,7 @@ Use the following example to apply validation styles for success and error messa
264291

265292
This example can be used to add a descriptive icon or additional text inside the input field.
266293

267-
```svelte
294+
```svelte example
268295
<script>
269296
import { Label, Input, Button, InputAddon, ButtonGroup, Checkbox } from "flowbite-svelte";
270297
</script>
@@ -322,7 +349,7 @@ This example can be used to add a descriptive icon or additional text inside the
322349

323350
This example shows how to add `onclick` event handler to the icon in `Input`. By clicking an icon, it toggles icon and `type`:
324351

325-
```svelte
352+
```svelte example
326353
<script>
327354
import { Button, Label, Input, ButtonGroup, InputAddon } from "flowbite-svelte";
328355
import { EyeOutline, EyeSlashOutline } from "flowbite-svelte-icons";
@@ -366,7 +393,7 @@ This example shows how to add `onclick` event handler to the icon in `Input`. By
366393

367394
Use the helper prop to add your helper text. You can use HTML in the helper text.
368395

369-
```svelte
396+
```svelte example
370397
<script>
371398
import { Input, Label, Helper } from "flowbite-svelte";
372399
</script>
@@ -385,7 +412,7 @@ Use the helper prop to add your helper text. You can use HTML in the helper text
385412

386413
By default the `Input` component binds the `value` as `string`. If you need a variable bound as `number` you need to use a specialised version of `Input` called `NumberInput`.
387414

388-
```svelte
415+
```svelte example
389416
<script lang="ts">
390417
import { Input, Label } from "flowbite-svelte";
391418
let value = $state(5);
@@ -403,7 +430,7 @@ By default the `Input` component binds the `value` as `string`. If you need a va
403430

404431
## Search input
405432

406-
```svelte
433+
```svelte example
407434
<script>
408435
import { Input, Label, Button } from "flowbite-svelte";
409436
import { SearchOutline } from "flowbite-svelte-icons";
@@ -426,7 +453,7 @@ By default the `Input` component binds the `value` as `string`. If you need a va
426453

427454
Use this example to show a dropdown menu right next to the input field.
428455

429-
```svelte
456+
```svelte example
430457
<script>
431458
import { Input, InputAddon, ButtonGroup, Button, Dropdown, DropdownItem } from "flowbite-svelte";
432459
import { ChevronDownOutline, SearchOutline } from "flowbite-svelte-icons";
@@ -453,7 +480,7 @@ Use this example to show a dropdown menu right next to the input field.
453480

454481
If you need a full control over `input` HTML element while still re-using the Flowbite formatting, you can put the `input` element as a default slot. The example below is in fact the implementation of the above mentioned `NumberInput`.
455482

456-
```svelte
483+
```svelte example
457484
<script>
458485
import { Input } from "flowbite-svelte";
459486
let value = $state(5);
@@ -469,7 +496,7 @@ If you need a full control over `input` HTML element while still re-using the Fl
469496

470497
## Using Svelte's snapshot to preserve the input
471498

472-
```svelte
499+
```svelte example
473500
<script lang="ts">
474501
import { Tabs, TabItem, Label, Button, Input, Textarea } from "flowbite-svelte";
475502
import type { Snapshot } from "./$types";

0 commit comments

Comments
 (0)