Skip to content

Commit 54e713d

Browse files
authoredOct 31, 2024··
feat(SelectMenu): allows to customize labels (#2266)

File tree

3 files changed

+19
-6
lines changed

3 files changed

+19
-6
lines changed
 

‎docs/content/2.components/select-menu.md

+6-2
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ Learn how to customize icons from the [Select](/components/select#icon) componen
8585

8686
Use the `searchable` prop to enable search.
8787

88-
Use the `searchable-placeholder` prop to set a different placeholder.
88+
Use the `searchable-placeholder` prop to set a different placeholder or globally through the `ui.selectMenu.default.searchablePlaceholder.label` config. Defaults to `Search...`.
8989

9090
This will use Headless UI [Combobox](https://headlessui.com/v1/vue/combobox) component instead of [Listbox](https://headlessui.com/v1/vue/listbox).
9191

@@ -258,6 +258,8 @@ componentProps:
258258

259259
Use the `#option-empty` slot to customize the content displayed when the `searchable` prop is `true` and there is no options. You will have access to the `query` property in the slot scope.
260260

261+
You can also configure this globally through the `ui.selectMenu.default.optionEmpty.label` config. The token `{query}` will be replaced by `query` property. Defaults to `No results for "{query}".`.
262+
261263
::component-example
262264
---
263265
component: 'select-menu-example-option-empty-slot'
@@ -276,7 +278,9 @@ An example is available in the [Creatable](#creatable) section.
276278

277279
### `empty`
278280

279-
Use the `#empty` slot to customize the content displayed when there is no options. Defaults to `No options.`.
281+
Use the `#empty` slot to customize the content displayed when there is no options.
282+
283+
You can also configure this globally through the `ui.selectMenu.default.empty.label` config. Defaults to `No options.`.
280284

281285
::component-example
282286
---

‎src/runtime/components/forms/SelectMenu.vue

+3-3
Original file line numberDiff line numberDiff line change
@@ -107,12 +107,12 @@
107107
</component>
108108
<p v-else-if="searchable && query && !filteredOptions?.length" :class="uiMenu.option.empty">
109109
<slot name="option-empty" :query="query">
110-
No results for "{{ query }}".
110+
{{ uiMenu.default.optionEmpty.label.replace('{query}', query) }}
111111
</slot>
112112
</p>
113113
<p v-else-if="!filteredOptions?.length" :class="uiMenu.empty">
114114
<slot name="empty" :query="query">
115-
No options.
115+
{{ uiMenu.default.empty.label }}
116116
</slot>
117117
</p>
118118
</component>
@@ -247,7 +247,7 @@ export default defineComponent({
247247
},
248248
searchablePlaceholder: {
249249
type: String,
250-
default: 'Search...'
250+
default: () => configMenu.default.searchablePlaceholder.label
251251
},
252252
searchableLazy: {
253253
type: Boolean,

‎src/runtime/ui.config/forms/selectMenu.ts

+10-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,16 @@ export default {
2323
default: {
2424
selectedIcon: 'i-heroicons-check-20-solid',
2525
clearSearchOnClose: false,
26-
showCreateOptionWhen: 'empty'
26+
showCreateOptionWhen: 'empty',
27+
searchablePlaceholder: {
28+
label: 'Search...'
29+
},
30+
empty: {
31+
label: 'No options.'
32+
},
33+
optionEmpty: {
34+
label: 'No results for "{query}".'
35+
}
2736
},
2837
arrow: {
2938
...arrow,

0 commit comments

Comments
 (0)
Please sign in to comment.