From 5f3230cb7b574c9f058be19b5b1d4cf4153d288a Mon Sep 17 00:00:00 2001 From: "fandi.susanto.bts" Date: Wed, 5 Aug 2026 22:22:05 +0700 Subject: [PATCH] Add filterable and clearable to CSelect. --- src/components/select/CSelect.vue | 398 +++++++++++++++++++++++++++--- src/pages/components/Select.vue | 57 ++++- 2 files changed, 420 insertions(+), 35 deletions(-) diff --git a/src/components/select/CSelect.vue b/src/components/select/CSelect.vue index 61e38c3..b00e5b8 100644 --- a/src/components/select/CSelect.vue +++ b/src/components/select/CSelect.vue @@ -1,6 +1,7 @@ + + + + + + + + + diff --git a/src/pages/components/Select.vue b/src/pages/components/Select.vue index fa5cbf9..17f7180 100644 --- a/src/pages/components/Select.vue +++ b/src/pages/components/Select.vue @@ -15,6 +15,7 @@ const products = [ ] const selectedProduct = ref<(typeof products)[number] | null>(products[0] ?? null) const selectedProductId = ref(1) +const filteredProduct = ref<(typeof products)[number] | null>(null) const warehouses: CSelectOption[] = [ { label: 'North warehouse', value: 'north' }, @@ -68,6 +69,17 @@ const objectUsage = `` + +const filterableUsage = `` @@ -76,8 +88,8 @@ const objectUsage = `

Forms

Select

- CSelect styles a native single-value select and supports either data-driven - options or ordinary HTML option slots. + CSelect is a single-value selection control. It uses a native select by + default and can become a searchable combobox for longer data-driven lists.

@@ -87,7 +99,8 @@ const objectUsage = ` Pass raw objects with option-label to choose the displayed field. When option-value is omitted, selecting an option binds the complete object. Use - option-key to provide stable rendering identity. + option-key to provide stable rendering identity. Add clearable when + users should be able to return the model to null.

@@ -96,6 +109,7 @@ const objectUsage = ` Selected object: {{ selectedProduct }} @@ -104,6 +118,35 @@ const objectUsage = ` +
+

Filter existing options

+

+ Add filterable when a long list should be searchable. Typing narrows the + available options but does not create a new value: v-model changes only when + the user selects an existing option. Use CAutoComplete later when arbitrary + user-entered values should be allowed. +

+

+ This mode works with data-driven options. Use Arrow Up or Arrow Down to move, + Enter to select, and Escape to discard the current search and restore the selected label. +

+
+ + + + Selected object: {{ filteredProduct }} +
+ +
+

Data-driven options

@@ -142,7 +185,9 @@ const objectUsage = `Native option slot

Use the default slot when native option or optgroup markup is more - convenient. Data-driven and slotted options can also be combined. + convenient. Data-driven and slotted options can also be combined. Slotted options are + available in the default native mode; filterable reads from the + options prop instead.

@@ -173,10 +218,12 @@ const objectUsage = `
option-label
Property path or function used to label raw object options.
option-value
Property path or function selecting the bound value. Omit it to bind the complete object.
option-key
Property path or function providing a stable string or number key for raw objects.
+
clearable
Shows a compact × button that clears the selected model to null.
+
filterable
Replaces the native select with a searchable, existing-options-only combobox.
placeholder
Disabled initial option displayed while the model is null.
size
small, medium, or large.
disabled
Disables selection and focus.
-
required
Applies native required validation.
+
required
Requires an actual option selection, including in filterable mode.
invalid
Applies invalid styling and aria-invalid.