Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reduce complexity on Dropdown component #387

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

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.

None yet

2 participants