Skip to content

Commit

Permalink
add dom/Focused?
Browse files Browse the repository at this point in the history
  • Loading branch information
xificurC committed Jun 24, 2024
1 parent d84dcb6 commit 371cacb
Showing 1 changed file with 8 additions and 12 deletions.
20 changes: 8 additions & 12 deletions src/hyperfiddle/electric_dom3.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
(:refer-clojure :exclude [comment])
(:require
[clojure.core :as cc]
[contrib.missionary-contrib :as mx]
[hyperfiddle.electric-de :as e :refer [$]]
;; [hyperfiddle.rcf :as rcf :refer [tests]]
[missionary.core :as m]
Expand Down Expand Up @@ -510,19 +511,14 @@ input's value, use `EventListener`."
;; Extras ;;
;;;;;;;;;;;;

;; G example impl, could we have e/mix ?
#_(e/defn Focused
([] ($ Focused node))
([node]
(e/client
($ EventListener node #{"focus" "blur"}
(fn [e]
(case (.-type e)
"focus" true
"blur" false))
{}
(= node (.-activeElement js/document))))))
#?(:cljs
(defn focused?> [node]
(->> (mx/mix (m/observe (fn [!] (with-listener node "focus" (fn [_] (! true)))))
(m/observe (fn [!] (with-listener node "blur" (fn [_] (! false))))))
(m/reductions {} (= node (.-activeElement js/document)))
(m/relieve {}))))

(e/defn Focused? ([] ($ Focused? node)) ([node] (e/input (focused?> node))))

;;;;;;;;;;;
;; Sugar ;;
Expand Down

0 comments on commit 371cacb

Please sign in to comment.