Skip to content

Commit 845acb9

Browse files
authored
Merge pull request #12 from tonivanhala/feat/improve-a11y
chore(accessibility): use html tables for Clojure maps
2 parents ee3a544 + 90c6b6e commit 845acb9

2 files changed

Lines changed: 34 additions & 34 deletions

File tree

src/ClojureFinland/css/styles.clj

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -19,23 +19,17 @@
1919
[:h1 :h2
2020
{:color "#A8B3B4"}]
2121

22-
[:table :td
22+
[:table
23+
{:text-align "left"}]
24+
25+
[:table :th :td
2326
{:vertical-align "top"}]
2427

28+
["tbody::after"
29+
{:content "''"
30+
:display "block"
31+
:height "0.5em"}]
32+
2533
[:.code
2634
{:color "#8D9798"
27-
:font-weight "bold"}]
28-
29-
[:.separator
30-
{:height "0.5em"}]
31-
32-
[:.container
33-
{:display "inline-grid"
34-
:grid-template-columns "0.75em min-content 0.5em"}]
35-
36-
[:.item-first
37-
{:padding-top "0.2em"}]
38-
39-
[:.item-last
40-
{:padding-bottom "0.25em"
41-
:align-self "end"}]))
35+
:font-weight "bold"}]))

src/ClojureFinland/html/page.clj

Lines changed: 24 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -122,21 +122,29 @@
122122
(defn keyword-output [k]
123123
[:span.keyword ":" k])
124124

125+
(declare table-output)
126+
125127
(defn map-output [m]
126-
[:div.map
127-
[:div.container
128-
[:div.item-first "{"]
129-
[:div.item
130-
[:table
131-
[:tbody
132-
(for [[k v] m]
133-
[:tr
134-
[:td (keyword-output k)]
135-
[:td (cond
136-
(map? v) (map-output v)
137-
(link? v) (link v)
138-
:else (text-output v))]])]]]
139-
[:div.item-last "}"]]])
128+
(let [n-items (count m)]
129+
(map-indexed
130+
(fn [i [k v]]
131+
[:tr
132+
(into [:td {:aria-hidden "true"}] (if (= 0 i) "{" " "))
133+
[:th {:scope "row"} (keyword-output k)]
134+
[:td (let [column (cond
135+
(map? v) (table-output v)
136+
(link? v) (link v)
137+
:else (text-output v))]
138+
(cond-> column
139+
(= i (dec n-items)) (into [[:span {:aria-hidden "true"} "}"]])))]])
140+
m)))
141+
142+
(defn table-output
143+
[data]
144+
[:table
145+
(cond->> data
146+
(map? data) (conj [])
147+
:always (map #(into [:tbody] (map-output %))))])
140148

141149
(defn section [{:keys [title id description code items data text]}]
142150
(cond-> [] ; use vector to conj at the end
@@ -145,10 +153,8 @@
145153
description (conj (section description))
146154
items (conj (section items))
147155
data (conj (cond
148-
(map? data) (map-output data)
149-
(coll? data) (->> data
150-
(map map-output)
151-
(interpose [:div.separator]))
156+
(map? data) (table-output data)
157+
(coll? data) (table-output data)
152158
(link? data) (link data)
153159
:else (text-output data)))
154160
text (conj (section text))

0 commit comments

Comments
 (0)