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

Issue with props merging on Menu #1424

Closed
layershifter opened this issue Mar 7, 2017 · 4 comments
Closed

Issue with props merging on Menu #1424

layershifter opened this issue Mar 7, 2017 · 4 comments
Labels

Comments

@layershifter
Copy link
Member

Extracted from #1375.

Steps

  1. Open codepen test case.
  2. Click on an item of menu.

Expected Result

Call of handleItem and handleMenu on click on MenuItem.

Actual Result

Only handleItem was called.
In fact, we don't call handleItemClick when onClick was passed to an MenuItem.

Version

Latest.

Testcase

http://codepen.io/layershifter/pen/aJBmwz

@levithomason
Copy link
Member

This is not a factory bug but the menu is incorrectly handling the items.

First, when creating shorthand items, the menu passes default props as an object. This means the items' onClick handler will override the default prop onClick handler:

    return _.map(items, (item, index) => MenuItem.create(item, {
      active: activeIndex === index,
      index,
      onClick: this.handleItemClick,
    }))

The menu should use the callback form of defaultProps which receives the user's props as an argument. This way, the onClick handler can wrap the user's onClick handler as well.

Second, the handleItemClick method assumes the items to be an array of objects from which it tries to lookup the clicked index and call the item's onClick handler. Instead, we should leave this to the wrapped item handler.

I'm not sure that we should auto wrap handlers in the factories as there may be cases where we want the override behavior.

@layershifter layershifter changed the title Issue with props merging on factories Issue with props merging on Menu Mar 7, 2017
@layershifter
Copy link
Member Author

I'll make PR that updates tests and Menu items handling.

@levithomason
Copy link
Member

I may have spoken prematurely on this as well. It will take more effort to diagnose properly. The defaultProps I believe are always overriden by the user's props. It is possible that even wrapping the user's props in the default props will be of no use as the user's handler will override the wrapped default handler:

https://github.com/Semantic-Org/Semantic-UI-React/blob/master/src/lib/factories.js#L46

const props = { ...defaultProps, ...usersProps }

Seems we need a way to define not defaultProps but some kind of overrideProps.

@layershifter
Copy link
Member Author

It was fixed in #1428 ✌️

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants