-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Fix onitem click for contextual menu with anchor item #5003
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
Fix onitem click for contextual menu with anchor item #5003
Conversation
| index={ 0 } | ||
| focusableElementIndex={ 0 } | ||
| totalItemCount={ 1 } | ||
| onItemClick={ itemOnClick } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do you need to set this in the test if it's not going to be used?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because the snapshot has it has a function, The actual behavior should be if we have onclick then we should invoke otherwise we shouldnt have any default method.
| describe('creates a normal button', () => { | ||
| let menuItem: IContextualMenuItem; | ||
| let menuClassNames: IMenuItemClassNames; | ||
| let itemOnClick: () => void; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you are going to use this function, can you use jest.fn() here instead?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
| aria-disabled={ isItemDisabled(item) } | ||
| style={ item.style } | ||
| onClick={ this._onItemClick } | ||
| onClick={ onItemClick ? onItemClick.bind(this, item) : undefined } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't believe that this is the correct place to make this change. The issue is that ContextualMenuAnchor doesn't get an onItemBaseClick passed to it, so the onClick is never called in this._onItemClick. I believe the correct response is change contextualmenuitemwrapper's this._onItemClick to the following.
protected _onItemClick = (ev: React.MouseEvent<HTMLElement>): void => {
const { item, onItemClickBase, onItemClick } = this.props;
if (onItemClickBase) {
onItemClickBase(item, ev, ev.currentTarget as HTMLElement);
} else if (onItemClick) {
onItemClick(item, ev);
}
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since we dont pass onItemClickBase to ContextualMenuAnchor, it is best override the onItemClick here as per our suggestion
* master: ComboBox: Fix styling when navigating menu with single select (microsoft#5017) Use require.resolve logic in builds & watch .js files from node_modules (microsoft#5007) Fix onitem click for contextual menu with anchor item (microsoft#5003) CommandBar example: fix link color on website (microsoft#4975)
Pull request checklist
$ npm run changeDescription of changes
With #4741 , the behavior of the context menu is regressed, If you have both onclick with preventdefault and href of the context menu item, href is now obeyed and onclick is never been called. This is because now _onItemClick from ContextualMenuItemWrapper is called instead from props.
With this change, the onclick is passed from props instead of baseclass.
Focus areas to test
(ContextualMenu)
Microsoft Reviewers: Open in CodeFlow