Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Dropdown]: Adds error slot using hasErrors and showErrors #432

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions src/components/dropdown/dropdown.stories.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,17 @@
<leo-option value="Frob">Frob</leo-option>
</Dropdown>
</Slot>
<Slot
name="error"
explanation="A slot where any errors related to the component will be shown. Errors are only shown if showErrors and hasErrors are set on the Dropdown (this one has them forced on)"
>
<Dropdown {...args} hasErrors showErrors>
<leo-option value="Error 1">Error 1</leo-option>
<leo-option value="Error 2">Error 2</leo-option>
<leo-option value="Error 3">Error 3</leo-option>
<div slot="errors">Something is not quite right here!</div>
</Dropdown>
</Slot>
</SlotInfo>
</Story>

Expand Down Expand Up @@ -198,4 +209,15 @@
gap: 8px;
align-items: center;
}

[slot='errors'] {
display: flex;
flex-direction: row;
gap: var(--leo-spacing-m);
align-items: center;

margin-top: var(--leo-spacing-s);

color: var(--leo-color-systemfeedback-error-icon);
}
</style>
7 changes: 7 additions & 0 deletions src/components/dropdown/dropdown.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@
export let required = false
export let mode: Mode = 'outline'

export let hasErrors = false
export let showErrors = false

let dispatch = createEventDispatcher()

let isOpen = false
Expand All @@ -52,6 +55,7 @@
bind:size
{mode}
showFocusOutline={isOpen}
error={hasErrors && showErrors}
>
<slot name="label" slot="label" />
<slot name="left-icon" slot="left-icon" />
Expand Down Expand Up @@ -99,6 +103,9 @@
<slot />
</Menu>
</div>
{#if showErrors && hasErrors}
<slot name="errors" />
{/if}

<style lang="scss">
:host {
Expand Down