Skip to content

Commit d7c1e39

Browse files
authored
Merge pull request #103 from darklang/fix-html-cmds-focus
Fix Tea.Html.Cmds.focus
2 parents e612208 + d556424 commit d7c1e39

File tree

3 files changed

+44
-40
lines changed

3 files changed

+44
-40
lines changed

lib/js/src-ocaml/tea_html_cmds.js

Lines changed: 16 additions & 16 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src-ocaml/tea_html_cmds.ml

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,16 @@
1-
21
let focus id =
3-
Tea_cmd.call (fun _enqueue -> match Js.Nullable.toOption (Web.Document.getElementById id) with
4-
| None -> Js.log ("Attempted to focus a non-existant element of: ", id)
5-
| Some elem ->
6-
(* let () = Js.log ("Focusing element", id, elem) in *)
7-
let ecb _ignored = Web.Node.focus elem in
8-
let cb _ignored = let _unhandledID = Web.Window.requestAnimationFrame ecb in () in (* One to get out of the current render frame*)
9-
let _unhandledID = Web.Window.requestAnimationFrame cb in (* And another to properly focus *)
10-
()
11-
)
2+
Tea_cmd.call
3+
(fun _enqueue ->
4+
let ecb _ =
5+
match Js.Nullable.toOption (Web.Document.getElementById id) with
6+
| None ->
7+
Js.log ("Attempted to focus a non-existant element of: ", id)
8+
| Some elem -> Web.Node.focus elem
9+
in
10+
(* One to get out of the current render frame*)
11+
let cb _ = ignore (Web.Window.requestAnimationFrame ecb) in
12+
(* And another to properly focus *)
13+
ignore (Web.Window.requestAnimationFrame cb);
14+
())
15+
16+

src-reason/tea_html_cmds.re

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
11
let focus = id =>
2-
Tea_cmd.call(_enqueue =>
3-
switch (Js.Nullable.toOption(Web.Document.getElementById(id))) {
4-
| None => Js.log(("Attempted to focus a non-existant element of: ", id))
5-
| Some(elem) =>
6-
/* let () = Js.log ("Focusing element", id, elem) in */
7-
let ecb = _ignored => Web.Node.focus(elem);
8-
let cb = _ignored => {
9-
let _unhandledID = Web.Window.requestAnimationFrame(ecb);
10-
();
11-
}; /* One to get out of the current render frame*/
12-
let _unhandledID = Web.Window.requestAnimationFrame(cb); /* And another to properly focus */
13-
();
14-
}
15-
);
2+
Tea_cmd.call(_enqueue => {
3+
let ecb = _ =>
4+
switch (Js.Nullable.toOption(Web.Document.getElementById(id))) {
5+
| None => Js.log(("Attempted to focus a non-existant element of: ", id))
6+
| Some(elem) => Web.Node.focus(elem)
7+
};
8+
9+
/* One to get out of the current render frame*/
10+
let cb = _ => ignore(Web.Window.requestAnimationFrame(ecb));
11+
/* And another to properly focus */
12+
ignore(Web.Window.requestAnimationFrame(cb));
13+
();
14+
});

0 commit comments

Comments
 (0)