Skip to content

Commit

Permalink
fix: Crash when ListBox, Select or ComboBox has null children (#545)
Browse files Browse the repository at this point in the history
  • Loading branch information
dogmar authored Nov 30, 2023
1 parent 2228bb4 commit 44603f9
Showing 1 changed file with 21 additions and 18 deletions.
39 changes: 21 additions & 18 deletions src/components/ListBox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -89,11 +89,12 @@ const ScrollContainer = styled.div<ScrollContainerProps>(
})
)

function propsToTextValue({
textValue,
children,
label,
}: Record<string, unknown>) {
function propsToTextValue(props: Record<string, unknown> | null | undefined) {
if (!props) {
return ''
}
const { textValue, children, label } = props

return typeof textValue === 'string' && textValue
? textValue
: typeof label === 'string' && label
Expand Down Expand Up @@ -126,20 +127,22 @@ function useItemWrappedChildren(
)
}
Children.forEach(children, (child) => {
const { textValue: _, ...childProps } = child.props

if (child) {
const item = (
<Item
key={child.key}
textValue={propsToTextValue(child.props)}
>
{cloneElement(child, childProps)}
</Item>
)

wrapped.push(item)
if (!child) {
return
}

const { textValue: _, ...passThruProps } = child.props || {}

const item = (
<Item
key={child.key}
textValue={propsToTextValue(child.props)}
>
{cloneElement(child, passThruProps)}
</Item>
)

wrapped.push(item)
})

if (footer) {
Expand Down

0 comments on commit 44603f9

Please sign in to comment.