Skip to content

Commit

Permalink
feat: show the placeholder if there are no selection options in the s…
Browse files Browse the repository at this point in the history
…election
  • Loading branch information
luohuidong committed Feb 1, 2024
1 parent bf8d511 commit ea12d9d
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/large-geese-fold.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"unify-ui": patch
---

Show the placeholder if there are no selection options in the selection
12 changes: 10 additions & 2 deletions src/components/data-entry/Select/Select.vue
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export default defineComponent({
</script>

<script setup lang="ts">
import { UniPopup } from "@/components";
import { UniPopup, UniEmpty } from "@/components";
import type { SelectProps, SelectEmits } from "./types";
import { useProvideStore, useDocumentClick } from "./composables";
Expand Down Expand Up @@ -44,7 +44,11 @@ useDocumentClick({
</template>

<template v-else>
<slot></slot>
<slot>
<div :class="$style.empty">
<uni-empty></uni-empty>
</div>
</slot>
</template>
</ul>
</template>
Expand All @@ -62,4 +66,8 @@ useDocumentClick({
margin: 0;
border-radius: form.$radius;
}
.empty {
padding: 20px;
}
</style>
29 changes: 29 additions & 0 deletions src/components/data-entry/Select/story/Empty.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<script setup lang="ts">
import { ref } from "vue";
import { UniSelect, UniSelectOption } from "@/components";
const options: { label: string; value: string }[] = [];
const value = ref<string>();
</script>

<template>
<div class="container">
<UniSelect v-model="value">
<UniSelectOption
v-for="item in options"
:key="item.value"
:label="item.label"
:value="item.value"
></UniSelectOption>
</UniSelect>
</div>
</template>

<style scoped>
.container {
width: 500px;
height: 500px;
padding: 20px;
}
</style>
8 changes: 8 additions & 0 deletions src/components/data-entry/Select/story/Input.stories.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import ShowCaseLoading from "./Loading.vue";
import ShowCaseRemoteSearch from "./RemoteSearch.vue";
import ShowCaseMultiple from "./Multiple.vue";
import ShowCaseStatusError from "./StatusError.vue";
import ShowCaseEmpty from "./Empty.vue";

const meta = {
title: "Data Entry/Select",
Expand Down Expand Up @@ -76,3 +77,10 @@ export const StatusError: Story = {
template: "<ShowCaseStatusError />",
}),
};

export const Empty: Story = {
render: () => ({
components: { ShowCaseEmpty },
template: "<ShowCaseEmpty />",
}),
};

0 comments on commit ea12d9d

Please sign in to comment.