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

Click away #671

Merged
merged 2 commits into from
Sep 14, 2024
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
3 changes: 3 additions & 0 deletions lib/surface/components/events.ex
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ defmodule Surface.Components.Events do
@doc "Triggered when the component receives click"
prop click, :event

@doc "Triggered when a click event happens outside of the element"
prop click_away, :event

@doc "Triggered when the page receives focus"
prop window_focus, :event

Expand Down
1 change: 1 addition & 0 deletions lib/surface/components/utils.ex
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ defmodule Surface.Components.Utils do
[
event_to_opts(assigns.capture_click, :"phx-capture-click"),
event_to_opts(assigns.click, :"phx-click"),
event_to_opts(assigns.click_away, :"phx-click-away"),
event_to_opts(assigns.window_focus, :"phx-window-focus"),
event_to_opts(assigns.window_blur, :"phx-window-blur"),
event_to_opts(assigns.focus, :"phx-focus"),
Expand Down
13 changes: 13 additions & 0 deletions test/surface/components/events_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,19 @@ defmodule Surface.Components.EventsTest do
"""
end

test "click away event with parent live view as target" do
html =
render_surface do
~F"""
<ComponentWithEvents click_away="my_click_away" />
"""
end

assert html =~ """
<div phx-click-away="my_click_away"></div>
"""
end

test "click event with parent live view as target" do
html =
render_surface do
Expand Down
Loading