Skip to content

Commit 4621c42

Browse files
sainfsadeghbarati
andauthored
feat: add modelValue prop to NativeSelect
* feat: add controlled way to NativeSelect component * chore: update * chore: build registry lint --------- Co-authored-by: Sadegh Barati <sadeghbaratiwork@gmail.com>
1 parent d2811c8 commit 4621c42

File tree

4 files changed

+133
-120
lines changed

4 files changed

+133
-120
lines changed

apps/v4/public/r/styles/new-york-v4/native-select.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
},
1414
{
1515
"path": "registry/new-york-v4/ui/native-select/NativeSelect.vue",
16-
"content": "<script setup lang=\"ts\">\nimport type { HTMLAttributes } from \"vue\"\nimport { reactiveOmit } from \"@vueuse/core\"\nimport { ChevronDownIcon } from \"lucide-vue-next\"\nimport { cn } from \"@/lib/utils\"\n\ndefineOptions({\n inheritAttrs: false,\n})\n\nconst props = defineProps<{ class?: HTMLAttributes[\"class\"] }>()\nconst delegatedProps = reactiveOmit(props, \"class\")\n</script>\n\n<template>\n <div\n class=\"group/native-select relative w-fit has-[select:disabled]:opacity-50\"\n data-slot=\"native-select-wrapper\"\n >\n <select\n data-slot=\"native-select\"\n :class=\"cn(\n 'border-input placeholder:text-muted-foreground selection:bg-primary selection:text-primary-foreground dark:bg-input/30 dark:hover:bg-input/50 h-9 w-full min-w-0 appearance-none rounded-md border bg-transparent px-3 py-2 pr-9 text-sm shadow-xs transition-[color,box-shadow] outline-none disabled:pointer-events-none disabled:cursor-not-allowed',\n 'focus-visible:border-ring focus-visible:ring-ring/50 focus-visible:ring-[3px]',\n 'aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 aria-invalid:border-destructive',\n props.class,\n )\"\n v-bind=\"{ ...$attrs, ...delegatedProps }\"\n >\n <slot />\n </select>\n <ChevronDownIcon\n class=\"text-muted-foreground pointer-events-none absolute top-1/2 right-3.5 size-4 -translate-y-1/2 opacity-50 select-none\"\n aria-hidden=\"true\"\n data-slot=\"native-select-icon\"\n />\n </div>\n</template>\n",
16+
"content": "<script setup lang=\"ts\">\nimport type { AcceptableValue } from \"reka-ui\"\nimport type { HTMLAttributes } from \"vue\"\nimport { reactiveOmit, useVModel } from \"@vueuse/core\"\nimport { ChevronDownIcon } from \"lucide-vue-next\"\nimport { cn } from \"@/lib/utils\"\n\ndefineOptions({\n inheritAttrs: false,\n})\n\nconst props = defineProps<{ modelValue?: AcceptableValue | AcceptableValue[], class?: HTMLAttributes[\"class\"] }>()\n\nconst emit = defineEmits<{\n \"update:modelValue\": AcceptableValue\n}>()\n\nconst modelValue = useVModel(props, \"modelValue\", emit, {\n passive: true,\n defaultValue: \"\",\n})\n\nconst delegatedProps = reactiveOmit(props, \"class\")\n</script>\n\n<template>\n <div\n class=\"group/native-select relative w-fit has-[select:disabled]:opacity-50\"\n data-slot=\"native-select-wrapper\"\n >\n <select\n v-bind=\"{ ...$attrs, ...delegatedProps }\"\n v-model=\"modelValue\"\n data-slot=\"native-select\"\n :class=\"cn(\n 'border-input placeholder:text-muted-foreground selection:bg-primary selection:text-primary-foreground dark:bg-input/30 dark:hover:bg-input/50 h-9 w-full min-w-0 appearance-none rounded-md border bg-transparent px-3 py-2 pr-9 text-sm shadow-xs transition-[color,box-shadow] outline-none disabled:pointer-events-none disabled:cursor-not-allowed',\n 'focus-visible:border-ring focus-visible:ring-ring/50 focus-visible:ring-[3px]',\n 'aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 aria-invalid:border-destructive',\n props.class,\n )\"\n >\n <slot />\n </select>\n <ChevronDownIcon\n class=\"text-muted-foreground pointer-events-none absolute top-1/2 right-3.5 size-4 -translate-y-1/2 opacity-50 select-none\"\n aria-hidden=\"true\"\n data-slot=\"native-select-icon\"\n />\n </div>\n</template>\n",
1717
"type": "registry:ui"
1818
},
1919
{

apps/v4/registry/new-york-v4/ui/native-select/NativeSelect.vue

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,25 @@
11
<script setup lang="ts">
2+
import type { AcceptableValue } from "reka-ui"
23
import type { HTMLAttributes } from "vue"
3-
import { reactiveOmit } from "@vueuse/core"
4+
import { reactiveOmit, useVModel } from "@vueuse/core"
45
import { ChevronDownIcon } from "lucide-vue-next"
56
import { cn } from "@/lib/utils"
67
78
defineOptions({
89
inheritAttrs: false,
910
})
1011
11-
const props = defineProps<{ class?: HTMLAttributes["class"] }>()
12+
const props = defineProps<{ modelValue?: AcceptableValue | AcceptableValue[], class?: HTMLAttributes["class"] }>()
13+
14+
const emit = defineEmits<{
15+
"update:modelValue": AcceptableValue
16+
}>()
17+
18+
const modelValue = useVModel(props, "modelValue", emit, {
19+
passive: true,
20+
defaultValue: "",
21+
})
22+
1223
const delegatedProps = reactiveOmit(props, "class")
1324
</script>
1425

@@ -18,14 +29,15 @@ const delegatedProps = reactiveOmit(props, "class")
1829
data-slot="native-select-wrapper"
1930
>
2031
<select
32+
v-bind="{ ...$attrs, ...delegatedProps }"
33+
v-model="modelValue"
2134
data-slot="native-select"
2235
:class="cn(
2336
'border-input placeholder:text-muted-foreground selection:bg-primary selection:text-primary-foreground dark:bg-input/30 dark:hover:bg-input/50 h-9 w-full min-w-0 appearance-none rounded-md border bg-transparent px-3 py-2 pr-9 text-sm shadow-xs transition-[color,box-shadow] outline-none disabled:pointer-events-none disabled:cursor-not-allowed',
2437
'focus-visible:border-ring focus-visible:ring-ring/50 focus-visible:ring-[3px]',
2538
'aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 aria-invalid:border-destructive',
2639
props.class,
2740
)"
28-
v-bind="{ ...$attrs, ...delegatedProps }"
2941
>
3042
<slot />
3143
</select>

apps/v4/registry/registry-blocks.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,11 @@ export const blocks: Registry["items"] = [
4444
type: "registry:component",
4545
},
4646
{
47-
path: "blocks/dashboard-01/components/DraggableRow.vue",
47+
path: "blocks/dashboard-01/components/DragHandle.vue",
4848
type: "registry:component",
4949
},
5050
{
51-
path: "blocks/dashboard-01/components/DragHandle.vue",
51+
path: "blocks/dashboard-01/components/DraggableRow.vue",
5252
type: "registry:component",
5353
},
5454
{

0 commit comments

Comments
 (0)