From 817659a55a44336fd099f194e566002df9109ab8 Mon Sep 17 00:00:00 2001 From: Juraj Kapsiar Date: Tue, 26 Nov 2019 12:05:49 +0100 Subject: [PATCH] feat(Chat): Allow to disable actions menu positioning (#2126) * allow to disable actions menu positioning * changelog --- CHANGELOG.md | 3 ++ .../react/src/components/Chat/ChatMessage.tsx | 52 +++++++++++-------- 2 files changed, 34 insertions(+), 21 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2d1f2260b4..ffd45b30d5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -20,6 +20,9 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm ### Fixes - Trigger `whatInput` cleanup when last `Provider` with custom `target` gets removed @silviuavram ([#2127](https://github.com/microsoft/fluent-ui-react/pull/2127)) +### Performance +- Allow suppression of action menu positioning in `ChatMessage` @jurokapsiar ([#2126](https://github.com/microsoft/fluent-ui-react/pull/2126)) + ## [v0.40.3](https://github.com/stardust-ui/react/tree/v0.40.3) (2019-11-08) [Compare changes](https://github.com/stardust-ui/react/compare/v0.40.2...v0.40.3) diff --git a/packages/react/src/components/Chat/ChatMessage.tsx b/packages/react/src/components/Chat/ChatMessage.tsx index 6c01b9a527..2cb9fec6c8 100644 --- a/packages/react/src/components/Chat/ChatMessage.tsx +++ b/packages/react/src/components/Chat/ChatMessage.tsx @@ -100,6 +100,9 @@ export interface ChatMessageProps */ onMouseEnter?: ComponentEventHandler + /** Allows suppression of action menu positioning for performance reasons */ + positionActionMenu?: boolean + /** Reaction group applied to the message. */ reactionGroup?: ShorthandValue | ShorthandCollection @@ -140,6 +143,7 @@ class ChatMessage extends UIComponent, ChatMessageS onBlur: PropTypes.func, onFocus: PropTypes.func, onMouseEnter: PropTypes.func, + positionActionMenu: PropTypes.bool, reactionGroup: PropTypes.oneOfType([ customPropTypes.collectionShorthand, customPropTypes.itemShorthand, @@ -152,6 +156,7 @@ class ChatMessage extends UIComponent, ChatMessageS accessibility: chatMessageBehavior, as: 'div', badgePosition: 'end', + positionActionMenu: true, reactionGroupPosition: 'start', } @@ -206,7 +211,7 @@ class ChatMessage extends UIComponent, ChatMessageS actionMenu: ChatMessageProps['actionMenu'], styles: ComponentSlotStylesPrepared, ) { - const { unstable_overflow: overflow } = this.props + const { unstable_overflow: overflow, positionActionMenu } = this.props const { messageNode } = this.state const actionMenuElement = Menu.create(actionMenu, { @@ -222,32 +227,37 @@ class ChatMessage extends UIComponent, ChatMessageS return actionMenuElement } - const menuRect: DOMRect = _.invoke(this.menuRef.current, 'getBoundingClientRect') || { + const menuRect: DOMRect = (positionActionMenu && + _.invoke(this.menuRef.current, 'getBoundingClientRect')) || { height: 0, } - const messageRect: DOMRect = _.invoke(messageNode, 'getBoundingClientRect') || { height: 0 } + const messageRect: DOMRect = (positionActionMenu && + _.invoke(messageNode, 'getBoundingClientRect')) || { height: 0 } return (