Skip to content

Commit

Permalink
Changed focus_in event to focus and focus_out to blur.
Browse files Browse the repository at this point in the history
  • Loading branch information
GPrimola committed Aug 2, 2023
1 parent e00777e commit 9a736ae
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 16 deletions.
8 changes: 4 additions & 4 deletions lib/scenic/component/input/text_field.ex
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ defmodule Scenic.Component.Input.TextField do
It also sends other two events when focus is gained or lost, respectively:
`{:focus_in, id}`
`{:focus_out, id}`
`{:focus, id}`
`{:blur, id}`
## Styles
Expand Down Expand Up @@ -262,7 +262,7 @@ defmodule Scenic.Component.Input.TextField do
defp capture_focus(%{assigns: %{focused: false, graph: graph, id: id, theme: theme}} = scene) do
# capture the input
capture_input(scene, @input_capture)
:ok = send_parent_event(scene, {:focus_in, id})
:ok = send_parent_event(scene, {:focus, id})

# start animating the caret
cast_children(scene, :start_caret)
Expand All @@ -283,7 +283,7 @@ defmodule Scenic.Component.Input.TextField do
defp release_focus(%{assigns: %{focused: true, graph: graph, id: id, theme: theme}} = scene) do
# release the input
release_input(scene)
:ok = send_parent_event(scene, {:focus_out, id})
:ok = send_parent_event(scene, {:blur, id})

# stop animating the caret
cast_children(scene, :stop_caret)
Expand Down
24 changes: 12 additions & 12 deletions test/scenic/component/input/text_field_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -92,27 +92,27 @@ defmodule Scenic.Component.Input.TextFieldTest do
:_pong_ = GenServer.call(vp_pid, :_ping_)
end

test "press_in captures, starts editing and fire focus_in event", %{vp: vp, pid: pid} do
test "press_in captures, starts editing and fire focus event", %{vp: vp, pid: pid} do
assert Input.fetch_captures!(vp) == {:ok, []}
Input.send(vp, @press_in)
force_sync(vp.pid, pid)
assert Input.fetch_captures!(vp) == {:ok, [:codepoint, :cursor_button, :key]}
assert_receive({:fwd_event, {:focus_in, :text_field}}, 200)
assert_receive({:fwd_event, {:focus, :text_field}}, 200)

Input.send(vp, @cp_k)
assert_receive({:fwd_event, {:value_changed, :text_field, "kInitial value"}}, 200)
end

test "press_out releases, ends editing and fire focus_out event", %{vp: vp, pid: pid} do
test "press_out releases, ends editing and fire blur event", %{vp: vp, pid: pid} do
Input.send(vp, @press_in)
force_sync(vp.pid, pid)
assert Input.fetch_captures!(vp) == {:ok, [:codepoint, :cursor_button, :key]}
assert_receive({:fwd_event, {:focus_in, :text_field}}, 200)
assert_receive({:fwd_event, {:focus, :text_field}}, 200)

Input.send(vp, @press_out)
force_sync(vp.pid, pid)
assert Input.fetch_captures!(vp) == {:ok, []}
assert_receive({:fwd_event, {:focus_out, :text_field}}, 200)
assert_receive({:fwd_event, {:blur, :text_field}}, 200)

Input.send(vp, @cp_k)
refute_receive(_, 10)
Expand All @@ -121,7 +121,7 @@ defmodule Scenic.Component.Input.TextFieldTest do
test "pressing in the field moves the cursor to the nearst character gap", %{vp: vp, pid: pid} do
Input.send(vp, @press_in)
force_sync(vp.pid, pid)
assert_receive({:fwd_event, {:focus_in, :text_field}}, 200)
assert_receive({:fwd_event, {:focus, :text_field}}, 200)

Input.send(vp, @cp_k)
assert_receive({:fwd_event, {:value_changed, :text_field, "kInitial value"}}, 200)
Expand Down Expand Up @@ -202,7 +202,7 @@ defmodule Scenic.Component.Input.TextFieldTest do
test "backspace does nothing at the start of the string", %{vp: vp, pid: pid} do
Input.send(vp, @press_in)
force_sync(vp.pid, pid)
assert_receive({:fwd_event, {:focus_in, :text_field}}, 200)
assert_receive({:fwd_event, {:focus, :text_field}}, 200)

Input.send(vp, @key_backspace)
refute_receive(_, 10)
Expand All @@ -219,7 +219,7 @@ defmodule Scenic.Component.Input.TextFieldTest do
test "delete does nothing at the end of the field", %{vp: vp, pid: pid} do
Input.send(vp, @press_in)
force_sync(vp.pid, pid)
assert_receive({:fwd_event, {:focus_in, :text_field}}, 200)
assert_receive({:fwd_event, {:focus, :text_field}}, 200)

Input.send(vp, @key_end)
Input.send(vp, @key_delete)
Expand All @@ -232,7 +232,7 @@ defmodule Scenic.Component.Input.TextFieldTest do

Input.send(vp, {:cursor_button, {:btn_left, 1, [], {20, 60}}})
force_sync(vp.pid, pid)
assert_receive({:fwd_event, {:focus_in, :number_field}}, 200)
assert_receive({:fwd_event, {:focus, :number_field}}, 200)

Input.send(vp, {:codepoint, {"a", []}})
refute_receive(_, 10)
Expand All @@ -252,7 +252,7 @@ defmodule Scenic.Component.Input.TextFieldTest do

Input.send(vp, {:cursor_button, {:btn_left, 1, [], {14, 86}}})
force_sync(vp.pid, pid)
assert_receive({:fwd_event, {:focus_in, :integer_field}}, 200)
assert_receive({:fwd_event, {:focus, :integer_field}}, 200)

Input.send(vp, {:codepoint, {"a", []}})
refute_receive(_, 10)
Expand All @@ -272,7 +272,7 @@ defmodule Scenic.Component.Input.TextFieldTest do

Input.send(vp, {:cursor_button, {:btn_left, 1, [], {14, 121}}})
force_sync(vp.pid, pid)
assert_receive({:fwd_event, {:focus_in, :abcdefg_field}}, 200)
assert_receive({:fwd_event, {:focus, :abcdefg_field}}, 200)

Input.send(vp, {:codepoint, {"a", []}})
assert_receive({:fwd_event, {:value_changed, :abcdefg_field, "a"}}, 200)
Expand All @@ -290,7 +290,7 @@ defmodule Scenic.Component.Input.TextFieldTest do

Input.send(vp, {:cursor_button, {:btn_left, 1, [], {14, 171}}})
force_sync(vp.pid, pid)
assert_receive({:fwd_event, {:focus_in, :fn_field}}, 200)
assert_receive({:fwd_event, {:focus, :fn_field}}, 200)

Input.send(vp, {:codepoint, {"a", []}})
refute_receive(_, 10)
Expand Down

0 comments on commit 9a736ae

Please sign in to comment.