-
Notifications
You must be signed in to change notification settings - Fork 2.9k
[ContextualMenu] Fixes useTargetWidth property #3943
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
Changes from 2 commits
50528e0
1e6a98c
442c9c0
f3cdb18
d667782
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| { | ||
| "changes": [ | ||
| { | ||
| "packageName": "office-ui-fabric-react", | ||
| "comment": "Fixes useTargetWidth prop for ContextualMenu", | ||
| "type": "patch" | ||
| } | ||
| ], | ||
| "packageName": "office-ui-fabric-react", | ||
| "email": "joem@microsoft.com" | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -247,7 +247,9 @@ export class ContextualMenu extends BaseComponent<IContextualMenuProps, IContext | |
| let contextMenuStyle; | ||
| let targetAsHtmlElement = this._target as HTMLElement; | ||
| if ((useTargetWidth || useTargetAsMinWidth) && targetAsHtmlElement && targetAsHtmlElement.offsetWidth) { | ||
| let targetWidth = targetAsHtmlElement.offsetWidth; | ||
| const targetBoundingRect = targetAsHtmlElement.getBoundingClientRect(); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should never have been in the render function in the first place. Calling offsetWidth/getBoundingClientRect (and other stuff) can trigger a reflow which is bad for performance. Ideally we'll store this and not call it again, and when we do call it it should be async. Move all of this to a separate function that get's called asynchronously.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Any guidance on this? There doesn't seem to be any
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure how to include an
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Take a look at Really contextualmenu shouldn't be measuring anything. But yes, it should be part of the lifecycle. |
||
| const targetWidth = targetBoundingRect.width; | ||
|
|
||
| if (useTargetWidth) { | ||
| contextMenuStyle = { | ||
| width: targetWidth | ||
|
|
@@ -271,7 +273,7 @@ export class ContextualMenu extends BaseComponent<IContextualMenuProps, IContext | |
| } | ||
| return ( | ||
| <Callout | ||
| {...calloutProps} | ||
| { ...calloutProps } | ||
| target={ useTargetPoint ? targetPoint : target } | ||
| isBeakVisible={ isBeakVisible } | ||
| beakWidth={ beakWidth } | ||
|
|
||
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.
you're checking offsetWidth, but calling getBoundingClientRect, while it's probably fine we should still change it to be consistent.
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.
What's the appropriate check here then? I would've thought checking
offsetWidthinitially was unnecessary anyway.