Skip to content

Commit

Permalink
Add click_away to Surface.Components.Events
Browse files Browse the repository at this point in the history
  • Loading branch information
tiagoefmoraes committed Sep 14, 2024
1 parent 27a502c commit b8a9e5c
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
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
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

0 comments on commit b8a9e5c

Please sign in to comment.