Skip to content

Commit eb7a3af

Browse files
committed
fix(Tags): add top-level disabled to CloseButton and input feild
1 parent 8e10711 commit eb7a3af

File tree

5 files changed

+9
-9
lines changed

5 files changed

+9
-9
lines changed

src/lib/forms/tags/Tags.svelte

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import { computePosition, offset, flip, shift, autoUpdate } from "@floating-ui/dom";
77
import { onDestroy } from "svelte";
88
9-
let { value = $bindable([]), placeholder = "Enter tags", class: className, classes, itemClass, spanClass, closeClass, inputClass, closeBtnSize = "xs", unique = false, availableTags = [], showHelper = false, showAvailableTags = false, allowNewTags = true, inputProps = {}, ...restProps }: TagsProps = $props();
9+
let { value = $bindable([]), placeholder = "Enter tags", class: className, classes, itemClass, spanClass, closeClass, inputClass, closeBtnSize = "xs", unique = false, availableTags = [], showHelper = false, showAvailableTags = false, allowNewTags = true, inputProps = {}, disabled, ...restProps }: TagsProps = $props();
1010
1111
warnThemeDeprecation("Tags", { itemClass, spanClass, closeClass, inputClass }, { itemClass: "tag", spanClass: "span", closeClass: "close", inputClass: "input" });
1212
const styling = $derived(
@@ -158,11 +158,11 @@
158158
<span class={spanCls({ class: clsx(theme?.span, styling.span) })}>
159159
{tag}
160160
</span>
161-
<CloseButton size={closeBtnSize} class={close({ class: clsx(theme?.close, styling.close) })} onclick={() => deleteField(index)} />
161+
<CloseButton disabled size={closeBtnSize} class={close({ class: clsx(theme?.close, styling.close) })} onclick={() => deleteField(index)} />
162162
</div>
163163
{/each}
164164
<div class="relative w-full" bind:this={inputContainer}>
165-
<input {...inputProps} bind:this={inputElement} onkeydown={handleKeys} oninput={handleInput} bind:value={contents} placeholder={value.length === 0 ? placeholder : ""} type="text" autocomplete="off" class={inputCls({ class: clsx(styling.input) })} />
165+
<input {...inputProps} disabled bind:this={inputElement} onkeydown={handleKeys} oninput={handleInput} bind:value={contents} placeholder={value.length === 0 ? placeholder : ""} type="text" autocomplete="off" class={inputCls({ class: clsx(styling.input) })} />
166166
{#if availableTags.length > 0 && contents.trim() !== ""}
167167
{@const filteredSuggestions = availableTags.filter((tag) => tag.toLowerCase().includes(contents.trim().toLowerCase()) && (!unique || !value.some((t) => t.toLowerCase() === tag.toLowerCase())))}
168168
{#if filteredSuggestions.length > 0}

src/lib/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -903,6 +903,7 @@ export interface TagsProps extends TagsVariants, HTMLAttributes<HTMLDivElement>
903903
showAvailableTags?: boolean;
904904
allowNewTags?: boolean;
905905
inputProps?: HTMLInputAttributes;
906+
disabled?: boolean;
906907
}
907908

908909
// Timepicker

src/lib/utils/theme.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import type { Classes } from "$lib/theme/themeUtils";
55
export type CloseButtonVariants = VariantProps<typeof closeButton> & Classes<typeof closeButton>;
66

77
export const closeButton = tv({
8-
base: "focus:outline-hidden whitespace-normal",
8+
base: "focus:outline-hidden whitespace-normal disabled:cursor-not-allowed disabled:opacity-50",
99
variants: {
1010
// primary, secondary, gray, red, orange, amber, yellow, lime, green, emerald, teal, cyan, sky, blue, indigo, violet, purple, fuchsia, pink, rose
1111
color: {
Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,12 @@
11
<script lang="ts">
22
import { Button, Tags } from "flowbite-svelte";
3-
let tags: string[] = $state([]);
3+
let tags: string[] = $state(['foo', 'bar']);
44
const handleClick = () => {
55
alert(`Submitted: ${tags}`);
66
};
77
</script>
88

99
<form>
10-
<Tags inputProps={{ disabled: true }} class="mt-5 mb-3" bind:value={tags} />
11-
{#if tags.length > 0}
12-
<pre>{JSON.stringify(tags, null, 2)}</pre>
13-
{/if}
10+
<Tags disabled class="mt-5 mb-3" bind:value={tags} />
1411
<Button onclick={handleClick} disabled>Submit</Button>
1512
</form>

src/routes/docs/extend/tags.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ Import the `Tags` component in a script tag.
4141

4242
## Disabled
4343

44+
Use `disabled` to the `Tags` component.
45+
4446
```svelte example class="h-40"
4547
{#include Disabled.svelte}
4648
```

0 commit comments

Comments
 (0)