Skip to content

Commit

Permalink
fix(Select): error handling has been corrected
Browse files Browse the repository at this point in the history
docs(Select): updated error example
  • Loading branch information
Craig Howell committed Feb 5, 2023
1 parent 8574757 commit bd7468e
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/lib/components/select/Label.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
const error: Writable<string | undefined> = getContext('select-error');
let defaultClass = 'block text-sm font-medium';
$: if (error) {
$: if ($error && $error.length > 0) {
defaultClass = defaultClass + ' text-danger';
} else {
defaultClass = defaultClass + ' text-light-secondary-content dark:text-dark-secondary-content';
Expand Down
1 change: 0 additions & 1 deletion src/lib/components/select/Select.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
input.value = option;
value = option;
$selectedValue = option;
error = undefined;
toggleVisible();
}
Expand Down
10 changes: 9 additions & 1 deletion src/routes/select/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,14 @@
import { email } from '../../docs/icons';
const options = ['Option 1', 'Option 2', 'Option 3'];
let value: string | undefined;
let error: string | undefined = "You're doing it wrong!";
$: if (value && value.length > 0) {
error = undefined;
} else {
error = "You're doing it wrong!";
}
</script>

<Col class="col-24">
Expand Down Expand Up @@ -40,7 +48,7 @@
</Select.Options>
</Select>
<br />
<Select name="select-3" error="There has been an error">
<Select name="select-3" {error} bind:value>
<Select.Label slot="label">Label</Select.Label>
<Select.Leading slot="leading" data={email} />
<Select.Options slot="options">
Expand Down
10 changes: 9 additions & 1 deletion src/routes/select/examples.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,14 @@ export const example = `
const email = "svg-path";
const options = ['Option 1', 'Option 2', 'Option 3'];
let value: string | undefined;
let error: string | undefined = "You're doing it wrong!";
$: if (value && value.length > 0) {
error = undefined;
} else {
error = "You're doing it wrong!";
}
</script>
<Select name="select-1" placeholder="Basic">
Expand All @@ -153,7 +161,7 @@ export const example = `
</Select.Options>
</Select>
<Select name="select-3" error="There has been an error">
<Select name="select-3" {error} bind:value>
<Select.Label slot="label">Label</Select.Label>
<Select.Leading slot="leading" data={email} />
<Select.Options slot="options">
Expand Down

0 comments on commit bd7468e

Please sign in to comment.