diff --git a/src/rum/server_render.clj b/src/rum/server_render.clj
index 9acbea8..3956987 100644
--- a/src/rum/server_render.clj
+++ b/src/rum/server_render.clj
@@ -9,6 +9,7 @@
(= :rum/nothing (first element))))
(def ^:dynamic *select-value*)
+(def ^:dynamic *multiple?*)
(defn append!
([^StringBuilder sb s0] (.append sb s0))
@@ -390,7 +391,15 @@
(append! sb " type=\"" (escape-html (to-str type)) "\""))
(when (and (= "option" tag)
- (= (get-value attrs) *select-value*))
+ (or (= (get-value attrs) *select-value*)
+ (and *multiple?*
+ (set? *select-value*)
+ (contains? *select-value* (get-value attrs)))
+ (and *multiple?*
+ (sequential? *select-value*)
+ (->> *select-value*
+ (filter #(= (get-value attrs) %))
+ (seq)))))
(append! sb " selected=\"\""))
(when id
@@ -407,7 +416,8 @@
(vreset! *state :state/tag-open))
(if (= "select" tag)
- (binding [*select-value* (get-value attrs)]
+ (binding [*select-value* (get-value attrs)
+ *multiple?* (:multiple attrs)]
(render-content! tag attrs children *state sb))
(render-content! tag attrs children *state sb)))))))
diff --git a/test/rum/test/server.clj b/test/rum/test/server.clj
index ffdc283..ef4a6a1 100644
--- a/test/rum/test/server.clj
+++ b/test/rum/test/server.clj
@@ -84,3 +84,41 @@
'([a] [a b] [a b c])))
(is (= (:arglists (meta #'comp-arglists-1))
'([a] [a b] [a b c]))))
+
+(deftest test-select-multiple
+ (testing "Set value"
+ (is (= (rum/render-static-markup [:select {:value #{"v1" "v2"}
+ :multiple true}
+ [:option {:value "v1"}]
+ [:option {:value "v2"}]
+ [:option {:value "v3"}]
+ ])
+ (str ""))))
+
+ (testing "Vector value"
+ (is (= (rum/render-static-markup [:select {:value ["v1" "v2"]
+ :multiple true}
+ [:option {:value "v1"}]
+ [:option {:value "v2"}]
+ [:option {:value "v3"}]])
+ (str ""))))
+
+ (testing "List value"
+ (is (= (rum/render-static-markup [:select {:value (list "v1" "v2")
+ :multiple true}
+ [:option {:value "v1"}]
+ [:option {:value "v2"}]
+ [:option {:value "v3"}]])
+ (str "")))))
\ No newline at end of file