diff --git a/lib/scenic/component/input/text_field.ex b/lib/scenic/component/input/text_field.ex index 5e83c06a..d275b71a 100644 --- a/lib/scenic/component/input/text_field.ex +++ b/lib/scenic/component/input/text_field.ex @@ -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 @@ -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) @@ -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) diff --git a/test/scenic/component/input/text_field_test.exs b/test/scenic/component/input/text_field_test.exs index f92f2edc..c1b9b6fb 100644 --- a/test/scenic/component/input/text_field_test.exs +++ b/test/scenic/component/input/text_field_test.exs @@ -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) @@ -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) @@ -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) @@ -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) @@ -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) @@ -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) @@ -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) @@ -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)