Skip to content

Commit 72b0d9c

Browse files
Merge pull request #269 from softnetics/supakorn/migrate/components
fix: make combobox able to disable.
2 parents baaf3bd + 661f11a commit 72b0d9c

3 files changed

Lines changed: 39 additions & 20 deletions

File tree

.changeset/tender-hounds-shave.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
'@example/ui-playground': patch
3+
'@genseki/react': patch
4+
---
5+
6+
fix: make combobox able to disabled.

examples/ui-playground/src/app/playground/shadcn/combobox-section.tsx

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -157,9 +157,9 @@ function BasicComboboxMultiple() {
157157
function BasicComboboxSingle() {
158158
return (
159159
<ComboboxProvider items={frameworks}>
160-
<ComboboxTrigger className="w-[200px]" />
160+
<ComboboxTrigger className="w-[200px]" disabled={false /* You can disable the trigger */} />
161161
<ComboboxContent>
162-
<ComboboxCommandInput />
162+
<ComboboxCommandInput disabled={false} />
163163
<ComboboxCommandEmpty>No framework found.</ComboboxCommandEmpty>
164164
<ComboboxCommandList>
165165
<ComboboxCommandGroup>
@@ -234,7 +234,10 @@ function ControlledComboboxMultiple() {
234234
onValueChange={setValue}
235235
multipleItems
236236
>
237-
<ComboboxTriggerMultiValue className="w-[250px]" />
237+
<ComboboxTriggerMultiValue
238+
disabled={false /* You can disable the trigger */}
239+
className="w-[250px]"
240+
/>
238241
<ComboboxContent>
239242
<ComboboxCommandInput />
240243
<ComboboxCommandEmpty>No language found.</ComboboxCommandEmpty>
@@ -432,8 +435,9 @@ function CustomTriggerComboboxMultiple() {
432435
<ComboboxTriggerMultiValue>
433436
{(selectedItems) => (
434437
<Button
438+
disabled={false}
435439
variant="secondary"
436-
className="w-[250px] grid [grid-template-columns:1fr_1fr] gap-2 p-2 border-primary border"
440+
className="w-[250px] grid [grid-template-columns:1fr_1fr] gap-2 p-2 border-primary border disabled:border-muted"
437441
>
438442
{selectedItems?.map((selectedItem) => (
439443
<span

packages/react/v2/components/primitives/combobox.tsx

Lines changed: 25 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -109,10 +109,13 @@ function _ComboboxPopoverProvider(props: { children?: React.ReactNode }) {
109109
)
110110
}
111111

112-
function ComboboxTriggerMultiValue(props: {
112+
function ComboboxTriggerMultiValue({
113+
className,
114+
children,
115+
...props
116+
}: {
113117
children?: ((selectedItem: Item[] | undefined) => React.ReactElement) | React.ReactNode
114-
className?: string
115-
}) {
118+
} & Omit<React.ComponentPropsWithRef<typeof PopoverTrigger>, 'children'>) {
116119
const ctx = useCombobox()
117120

118121
const selectedItems = ctx.items.filter((item) => ctx.value.includes(item.value))
@@ -149,13 +152,15 @@ function ComboboxTriggerMultiValue(props: {
149152
<PopoverTrigger
150153
asChild
151154
onKeyDown={onTriggerKeyDown}
152-
className={cn('w-[200px] min-h-18 justify-between flex h-auto relative', props.className)}
155+
className={cn('w-[200px] min-h-18 justify-between flex h-auto relative', className)}
153156
aria-expanded={ctx.open}
157+
{...props}
158+
// These properties will be merged down to a children
154159
>
155-
{typeof props.children === 'function' ? (
156-
props.children(selectedItems)
157-
) : props.children ? (
158-
props.children
160+
{typeof children === 'function' ? (
161+
children(selectedItems)
162+
) : children ? (
163+
children
159164
) : (
160165
<Button variant="outline" role="combobox">
161166
{selectedItems.length > 0 ? renderItems : 'Please select item'}
@@ -166,10 +171,13 @@ function ComboboxTriggerMultiValue(props: {
166171
)
167172
}
168173

169-
function ComboboxTrigger(props: {
174+
function ComboboxTrigger({
175+
className,
176+
children,
177+
...props
178+
}: {
170179
children?: ((selectedItem: Item | undefined) => React.ReactElement) | React.ReactNode
171-
className?: string
172-
}) {
180+
} & Omit<React.ComponentPropsWithRef<typeof PopoverTrigger>, 'children'>) {
173181
const ctx = useCombobox()
174182

175183
if (ctx.multipleItems) {
@@ -188,13 +196,14 @@ function ComboboxTrigger(props: {
188196
<PopoverTrigger
189197
asChild
190198
onKeyDown={onTriggerKeyDown}
191-
className={cn('w-[200px] justify-between', props.className)}
199+
className={cn('w-[200px] justify-between', className)}
192200
aria-expanded={ctx.open}
201+
{...props}
193202
>
194-
{typeof props.children === 'function' ? (
195-
props.children(selectedItem)
196-
) : props.children ? (
197-
props.children
203+
{typeof children === 'function' ? (
204+
children(selectedItem)
205+
) : children ? (
206+
children
198207
) : (
199208
<Button variant="outline" role="combobox">
200209
{selectedItem?.label || 'Please select item'}

0 commit comments

Comments
 (0)