Skip to content

Commit

Permalink
🐛 fix(issues): Fix minor bugs for issues #31 and #32 (#33)
Browse files Browse the repository at this point in the history
🐛 fix(multiselect): add display names and fix hook dependencies

- add display names for MultiSelectValue, MultiSelectContent and MultiSelectItem
- update hook dependencies in MultiSelect components
- fix typos in MultiSelect usage examples

Fixes #31, #32
  • Loading branch information
RayRizzling authored Jan 31, 2025
1 parent bc95476 commit 938d0a7
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 8 deletions.
4 changes: 2 additions & 2 deletions apps/web/content/docs/components/multi-select.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,9 @@ import {
<MultiSelectItem value="vue">Vue</MultiSelectItem>
<MultiSelectItem value="angular">Angular</MultiSelectItem>
<MultiSelectItem value="svelte">Svelte</MultiSelectItem>
</MultiSelectList>>
</MultiSelectList>
</MultiSelectContent>
</MultiSel>
</MultiSelect>
```

## Examples
Expand Down
13 changes: 10 additions & 3 deletions apps/web/registry/default/ui/multi-select.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ const MultiSelect: React.FC<MultiSelectProps> = ({
onValueChangeProp(state, items)
}
},
[onValueChangeProp],
[onValueChangeProp, itemCache],
)

const [value, setValue] = useControllableState({
Expand Down Expand Up @@ -168,6 +168,7 @@ const MultiSelect: React.FC<MultiSelectProps> = ({
maxCount,
handleSelect,
handleDeselect,
itemCache
])

return (
Expand Down Expand Up @@ -325,6 +326,8 @@ const MultiSelectValue = React.forwardRef<
},
)

MultiSelectValue.displayName = 'MultiSelectValue'

const MultiSelectSearch = React.forwardRef<
React.ElementRef<typeof CommandInput>,
React.ComponentPropsWithoutRef<typeof CommandInput>
Expand Down Expand Up @@ -410,6 +413,8 @@ const MultiSelectContent = React.forwardRef<
)
})

MultiSelectContent.displayName = 'MultiSelectContent'

type MultiSelectItemProps = React.ComponentPropsWithoutRef<typeof CommandItem> &
Partial<MultiSelectOptionItem> & {
onSelect?: (value: string, item: MultiSelectOptionItem) => void
Expand Down Expand Up @@ -456,7 +461,7 @@ const MultiSelectItem = React.forwardRef<
React.useEffect(() => {
if (value)
itemCache.set(value, item!)
}, [selected, value, item])
}, [selected, value, item, itemCache])

const disabled = Boolean(
disabledProp || (!selected && maxCount && contextValue.length >= maxCount),
Expand Down Expand Up @@ -495,6 +500,8 @@ const MultiSelectItem = React.forwardRef<
},
)

MultiSelectItem.displayName = 'MultiSelectItem'

const MultiSelectGroup = React.forwardRef<
React.ElementRef<typeof CommandGroup>,
React.ComponentPropsWithoutRef<typeof CommandGroup>
Expand Down Expand Up @@ -585,4 +592,4 @@ export {
MultiSelectSeparator,
MultiSelectEmpty,
renderMultiSelectOptions,
}
}
13 changes: 10 additions & 3 deletions apps/web/registry/miami/ui/multi-select.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ const MultiSelect: React.FC<MultiSelectProps> = ({
onValueChangeProp(state, items)
}
},
[onValueChangeProp],
[onValueChangeProp, itemCache],
)

const [value, setValue] = useControllableState({
Expand Down Expand Up @@ -168,6 +168,7 @@ const MultiSelect: React.FC<MultiSelectProps> = ({
maxCount,
handleSelect,
handleDeselect,
itemCache
])

return (
Expand Down Expand Up @@ -325,6 +326,8 @@ const MultiSelectValue = React.forwardRef<
},
)

MultiSelectValue.displayName = 'MultiSelectValue'

const MultiSelectSearch = React.forwardRef<
React.ElementRef<typeof CommandInput>,
React.ComponentPropsWithoutRef<typeof CommandInput>
Expand Down Expand Up @@ -410,6 +413,8 @@ const MultiSelectContent = React.forwardRef<
)
})

MultiSelectContent.displayName = 'MultiSelectContent'

type MultiSelectItemProps = React.ComponentPropsWithoutRef<typeof CommandItem> &
Partial<MultiSelectOptionItem> & {
onSelect?: (value: string, item: MultiSelectOptionItem) => void
Expand Down Expand Up @@ -456,7 +461,7 @@ const MultiSelectItem = React.forwardRef<
React.useEffect(() => {
if (value)
itemCache.set(value, item!)
}, [selected, value, item])
}, [selected, value, item, itemCache])

const disabled = Boolean(
disabledProp || (!selected && maxCount && contextValue.length >= maxCount),
Expand Down Expand Up @@ -495,6 +500,8 @@ const MultiSelectItem = React.forwardRef<
},
)

MultiSelectItem.displayName = 'MultiSelectItem'

const MultiSelectGroup = React.forwardRef<
React.ElementRef<typeof CommandGroup>,
React.ComponentPropsWithoutRef<typeof CommandGroup>
Expand Down Expand Up @@ -585,4 +592,4 @@ export {
MultiSelectSeparator,
MultiSelectEmpty,
renderMultiSelectOptions,
}
}

0 comments on commit 938d0a7

Please sign in to comment.