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

FIX: Prevent chat message actions to disappear on mouseleave #23063

Merged
merged 2 commits into from Sep 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -2,7 +2,6 @@
<div
{{did-insert this.setup}}
{{did-update this.setup this.chat.activeMessage.model.id}}
{{on "mouseleave" this.onMouseleave}}
{{on "wheel" this.onWheel passive=true}}
{{will-destroy this.teardown}}
class={{concat-class
Expand Down
Expand Up @@ -48,21 +48,6 @@ export default class ChatMessageActionsDesktop extends Component {
this.chat.activeMessage = null;
}

@action
onMouseleave(event) {
// if the mouse is leaving the actions menu for the actual menu, don't close it
// this will avoid the menu rerendering
if (
(event.toElement || event.relatedTarget)?.closest(
".chat-message-container"
)
) {
return;
}

this.chat.activeMessage = null;
}

@action
setup(element) {
this.popper?.destroy();
Expand Down
Expand Up @@ -258,6 +258,12 @@ export default class ChatMessage extends Component {
return this.chat.userCanInteractWithChat && this.site.desktopView;
}

get secondaryActionsIsExpanded() {
return document.querySelector(
".more-buttons.secondary-actions.is-expanded"
);
}

@action
expand() {
const recursiveExpand = (message) => {
Expand Down Expand Up @@ -382,11 +388,13 @@ export default class ChatMessage extends Component {
return;
}

this._onMouseEnterMessageDebouncedHandler = discourseDebounce(
this,
this._debouncedOnHoverMessage,
250
);
if (!this.secondaryActionsIsExpanded) {
this._onMouseEnterMessageDebouncedHandler = discourseDebounce(
this,
this._debouncedOnHoverMessage,
250
);
}
}

@action
Expand All @@ -399,7 +407,9 @@ export default class ChatMessage extends Component {
return;
}

this._setActiveMessage();
if (!this.secondaryActionsIsExpanded) {
this._setActiveMessage();
}
}

@action
Expand All @@ -417,8 +427,9 @@ export default class ChatMessage extends Component {
) {
return;
}

this.chat.activeMessage = null;
if (!this.secondaryActionsIsExpanded) {
this.chat.activeMessage = null;
}
}

@bind
Expand Down
27 changes: 27 additions & 0 deletions plugins/chat/spec/system/chat_channel_spec.rb
Expand Up @@ -287,4 +287,31 @@
)
end
end

context "when opening message secondary options" do
it "doesn’t hide dropdown on mouseleave" do
chat.visit_channel(channel_1)
last_message = find(".chat-message-container:last-child")
last_message.hover

expect(page).to have_css(
".chat-message-actions-container[data-id='#{last_message["data-id"]}']",
)

find(".chat-message-actions-container .secondary-actions").click
expect(page).to have_css(
".chat-message-actions-container .secondary-actions .select-kit-body",
)

find("#site-logo").hover
expect(page).to have_css(
".chat-message-actions-container .secondary-actions .select-kit-body",
)

find("#site-logo").click
expect(page).to have_no_css(
".chat-message-actions-container .secondary-actions .select-kit-body",
)
end
end
end