Skip to content
This repository has been archived by the owner on Mar 4, 2020. It is now read-only.

fix(ChatMessage): actions menu's appearance #1739

Merged
merged 11 commits into from
Aug 5, 2019

Conversation

kuzhelov
Copy link
Contributor

@kuzhelov kuzhelov commented Jul 31, 2019

This PR changes the way positioning is applied to actionsMenu of ChatMessage - now Popper component is used to control positioning of this floating section.

This change is necessary to handle situations where actionsMenu's content may be cut by the edges of the viewport - this may be the case for messages with short content and long list of actionMenu's items.

Before

Actions menu content is cut off.

image

Now

Actions menu's position is adjusted.

image

Notes on the approach

To handle actionsMenu cut-off case, the strategy of using Popper's positioning was taken. Essentially, previously the set of static CSS props (in a sense that they were prescribed once and for entire component's time) were used for absolutely position actionsMenu, and these CSS values were part of the theme.

Unfortunately, these values should be set dynamically, in order to handle the cases when viewport's width is not enough to show the entire actionMenu's content - that's why Popper's positioning utilities were considered to be part of the solution

There were an alternative strategy to use Popper wrapper for the slot's content, instead of providing Popper as part of ChatMessage's implementation. However, this introduces couple of problems:

  • there will be 'two sources of truth' for the actionMenu positioning: one is the slot's wrapper, and another one - CSS values defined in theme
  • this results in quite complicated and brittle logic for the client

Thus, it was decided to pay the costs of extensibility and introduce Popper positioning for actionsMenu as part of ChatMessage's implementation, at least for now.

@@ -153,14 +157,16 @@ class ChatMessage extends UIComponent<WithAsProp<ChatMessageProps>, ChatMessageS
},

focus: event => {
if (this.messageRef) {
Copy link
Contributor Author

@kuzhelov kuzhelov Jul 31, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this check was guaranteed to pass

state = {
focused: false,
isFromKeyboard: false,
messageDomNode: null,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it is necessary to use state to store this DOM node, as otherwise Popper component that is used for actionsMenu rendering won't update its target once messageDomNode is set

return (
<Popper targetRef={this.state.messageDomNode} position="above" align="end">
{({ scheduleUpdate }) => {
this.updateActionsMenuPosition = scheduleUpdate
Copy link
Contributor Author

@kuzhelov kuzhelov Jul 31, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it is necessary to trigger position updates for the cases when actions menu appear, as it has width of 0 when is hidden (https://github.com/stardust-ui/react/blob/master/packages/react/src/themes/teams/components/Chat/chatMessageStyles.ts#L95)

<ElementType
onBlur={this.handleBlur}
onFocus={this.handleFocus}
onMouseEnter={() => this.updateActionsMenuPosition()}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is it ok not to update the position when you are only using keyboard?

Copy link
Contributor Author

@kuzhelov kuzhelov Jul 31, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, as logic of this.handleFocus is responsible for making position updates in this case: https://github.com/stardust-ui/react/pull/1739/files#diff-36ca6d6c5aa2d1fa2b0e2d9f04902716R168

@codecov
Copy link

codecov bot commented Aug 1, 2019

Codecov Report

Merging #1739 into master will increase coverage by 0.08%.
The diff coverage is 56.25%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1739      +/-   ##
==========================================
+ Coverage   71.06%   71.14%   +0.08%     
==========================================
  Files         861      857       -4     
  Lines        7171     7115      -56     
  Branches     2082     2054      -28     
==========================================
- Hits         5096     5062      -34     
+ Misses       2069     2047      -22     
  Partials        6        6
Impacted Files Coverage Δ
.../themes/teams/components/Chat/chatMessageStyles.ts 2.32% <ø> (ø) ⬆️
packages/react/src/components/Chat/ChatMessage.tsx 72.34% <56.25%> (-4.14%) ⬇️
...mes/teams/components/Checkbox/checkboxVariables.ts 0% <0%> (-75%) ⬇️
...act/src/themes/teams/components/List/listStyles.ts 16.66% <0%> (-3.34%) ⬇️
packages/react/src/components/Dialog/Dialog.tsx 31.57% <0%> (-3.31%) ⬇️
...ackages/react/src/components/Checkbox/Checkbox.tsx 80% <0%> (-1.82%) ⬇️
packages/react-proptypes/src/index.ts 34.26% <0%> (-0.46%) ⬇️
packages/react/src/components/Tree/Tree.tsx 93.33% <0%> (-0.42%) ⬇️
...ages/react/test/specs/behaviors/testDefinitions.ts 93.08% <0%> (-0.33%) ⬇️
packages/react/src/lib/factories.ts 94.2% <0%> (-0.25%) ⬇️
... and 25 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 2170f7e...ad8fee9. Read the comment docs.

@codecov
Copy link

codecov bot commented Aug 1, 2019

Codecov Report

Merging #1739 into master will decrease coverage by 0.01%.
The diff coverage is 56.25%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1739      +/-   ##
==========================================
- Coverage   69.99%   69.98%   -0.02%     
==========================================
  Files         868      868              
  Lines        7323     7336      +13     
  Branches     2117     2119       +2     
==========================================
+ Hits         5126     5134       +8     
- Misses       2191     2196       +5     
  Partials        6        6
Impacted Files Coverage Δ
.../themes/teams/components/Chat/chatMessageStyles.ts 2.32% <ø> (ø) ⬆️
packages/react/src/components/Chat/ChatMessage.tsx 72.34% <56.25%> (-4.14%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 0b82746...24f811f. Read the comment docs.

@kuzhelov kuzhelov changed the title fix(ChatMessage) actions menu's appearance fix(ChatMessage): actions menu's appearance Aug 1, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants