Skip to content

Conversation

couds
Copy link
Owner

@couds couds commented Apr 20, 2022

Use context to store current value, and onSelect function to avoid iterate and overwrite children with cloneElement

@couds couds requested a review from kennethnym April 20, 2022 08:08
Fix dropdown bug noy selecting
Copy link
Collaborator

@kennethnym kennethnym left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, but can you also update the TypeScript definition of Dropdown as well because of the new fullwidth prop?

Comment on lines +63 to +68
.reduce((current, child, i) => {
if ((i === 0 && !current) || child.props.value === value) {
return child.props.children;
}
return current;
}, label);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about using find instead? find stops iterating when it finds a match unlike reduce.

React.Children.toArray(children)
    .find((child, i) => child.type === DropdownItem && ((i === 0 && !label) || child.props.value === value)
    ?? label

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants