Skip to content

Commit

Permalink
feat(kselect): add before slot (#2481)
Browse files Browse the repository at this point in the history
  • Loading branch information
Justineo authored Oct 26, 2024
1 parent 2e953ba commit dfb5f07
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 4 deletions.
20 changes: 16 additions & 4 deletions docs/components/select.md
Original file line number Diff line number Diff line change
Expand Up @@ -597,7 +597,7 @@ A slot alternative for [`dropdownFooterText` prop](#dropdownfootertext).

### loading

Content to be displayed when [`loading` prop](#loading-1) is `true`. Note that this prop only applies when `enableFiltering` is `true`.
Content to be displayed when [`loading` prop](#loading-1) is `true`. Note that this slot only applies when `enableFiltering` is `true`.

<ClientOnly>
<KToggle toggled v-slot="{ isToggled, toggle }">
Expand Down Expand Up @@ -642,7 +642,7 @@ Slot to display custom content when items is empty or no items match filter quer

### label-tooltip

Use this prop to pass any custom content to label tooltip.
Use this slot to pass any custom content to label tooltip.

<ClientOnly>
<KSelect label="Label" :items="selectItems">
Expand All @@ -656,6 +656,18 @@ Use this prop to pass any custom content to label tooltip.
</KSelect>
```

### before

Use this slot for inserting icons before the input field.

<ClientOnly>
<KSelect :items="selectItems">
<template #before>
<SearchIcon />
</template>
</KSelect>
</ClientOnly>

## Events

### selected
Expand Down Expand Up @@ -684,7 +696,7 @@ Event payload is removed [item](#items).

<script setup lang="ts">
import { ref } from 'vue'
import { KongIcon } from '@kong/icons'
import { KongIcon, SearchIcon } from '@kong/icons'

const selectItems: SelectItem[] = [{
label: 'Service A',
Expand Down Expand Up @@ -774,4 +786,4 @@ const vModel = ref<string>('f')
font-size: $kui-font-size-20;
}
}
</style>
</style>
9 changes: 9 additions & 0 deletions sandbox/pages/SandboxSelect.vue
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,15 @@
</template>
</KSelect>
</SandboxSectionComponent>
<SandboxSectionComponent
title="before"
>
<KSelect :items="selectItems">
<template #before>
<KongIcon />
</template>
</KSelect>
</SandboxSectionComponent>
<SandboxSectionComponent title="itemTemplate">
<KSelect
:items="selectItems"
Expand Down
6 changes: 6 additions & 0 deletions src/components/KSelect/KSelect.vue
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,12 @@
@keyup.enter.stop
@update:model-value="onQueryChange"
>
<template
v-if="slots.before"
#before
>
<slot name="before" />
</template>
<template #after>
<button
v-if="isClearVisible"
Expand Down

0 comments on commit dfb5f07

Please sign in to comment.