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: animation no-close on selected text #703

Merged
merged 2 commits into from
Aug 29, 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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 21 additions & 2 deletions assets/js/hooks/animation.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
function getSelectionText() {
var text = "";
if (window.getSelection) {
text = window.getSelection().toString();
} else if (document.selection && document.selection.type != "Control") {
text = document.selection.createRange().text;
}
return text;
}

export default {

hiddenClasses() {
Expand All @@ -14,16 +24,25 @@ export default {
});
},


updated() {
this.showElementIfNeeded();
(this.el.dataset.is_closing === "true") && this.hideElement()
this.hideElementIfNeeded();
},

showElementIfNeeded() {
(this.el.dataset.is_open === undefined) || !this.el.classList.contains("hidden") || this.showElement();
},

hideElementIfNeeded() {
if (this.el.dataset.is_closing === "true"){
if (getSelectionText()) {
this.pushEventTo(this.el, "stop_closing", {});
} else {
this.hideElement()
}
}
},

hideElement() {
if(this.el.dataset.lg_persists !== undefined && document.body.clientWidth >= 1024) return;
this.panel.classList.remove(...this.panel.dataset.animate_enter_class.split(" "));
Expand Down
4 changes: 4 additions & 0 deletions lib/moon/design/bottom_sheet.ex
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,10 @@ defmodule Moon.Design.BottomSheet do
{:noreply, assign(socket, is_closing: true)}
end

def handle_event("stop_closing", _, socket) do
{:noreply, assign(socket, is_closing: false)}
end

def handle_event("set_close", _, socket) do
{:noreply, assign(socket, is_open: false, is_closing: false)}
end
Expand Down
4 changes: 4 additions & 0 deletions lib/moon/design/drawer.ex
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@ defmodule Moon.Design.Drawer do
{:noreply, assign(socket, is_closing: true)}
end

def handle_event("stop_closing", _, socket) do
{:noreply, assign(socket, is_closing: false)}
end

def handle_event("set_close", _, socket) do
{:noreply, assign(socket, is_open: false, is_closing: false)}
end
Expand Down
4 changes: 4 additions & 0 deletions lib/moon/design/modal.ex
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@ defmodule Moon.Design.Modal do
{:noreply, assign(socket, is_closing: true)}
end

def handle_event("stop_closingt", _, socket) do
{:noreply, assign(socket, is_closing: false)}
end

def handle_event("set_close", _, socket) do
{:noreply, assign(socket, is_open: false, is_closing: false)}
end
Expand Down