Skip to content

Commit 1ca5ac4

Browse files
authored
fix: tabbed-code radio rendering crashes Arizona renderer (#44)
Returning {input, Attrs, []} from a function called via ?each bypasses Arizona's parse transform, and the runtime renderer's to_bin/1 doesn't accept the 3-tuple void-element form. This took down the homepage with a bad_template_value crash. Inline the input tuple into the ?each lambda so the parse transform compiles it directly, switch to the void-element 2-tuple shorthand {input, Attrs}, and use {checked, N =:= 1} (Arizona strips false boolean attrs at parse time) to keep first-tab-checked behaviour without a second clause.
1 parent eb56451 commit 1ca5ac4

1 file changed

Lines changed: 11 additions & 21 deletions

File tree

src/views/asobi_site_tabbed_code.erl

Lines changed: 11 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,17 @@ render(Bindings) ->
3434
Indexed = lists:zip(lists:seq(1, length(Tabs)), Tabs),
3535
?html(
3636
{'div', [{class, ~"tabbed-code"}], [
37-
?each(fun({N, _Tab}) -> radio(Id, N) end, Indexed),
37+
?each(
38+
fun({N, _Tab}) ->
39+
{input, [
40+
{type, ~"radio"},
41+
{name, Id},
42+
{id, input_id(Id, N)},
43+
{checked, N =:= 1}
44+
]}
45+
end,
46+
Indexed
47+
),
3848
{'div', [{class, ~"tabbed-code-labels"}, {role, ~"tablist"}], [
3949
?each(
4050
fun({N, #{label := Label}}) ->
@@ -56,26 +66,6 @@ render(Bindings) ->
5666
]}
5767
).
5868

59-
%% The first radio is checked by default so one tab is visible before
60-
%% any user interaction.
61-
radio(Id, 1) ->
62-
{input,
63-
[
64-
{type, ~"radio"},
65-
{name, Id},
66-
{id, input_id(Id, 1)},
67-
{checked, ~"checked"}
68-
],
69-
[]};
70-
radio(Id, N) ->
71-
{input,
72-
[
73-
{type, ~"radio"},
74-
{name, Id},
75-
{id, input_id(Id, N)}
76-
],
77-
[]}.
78-
7969
input_id(Id, N) ->
8070
iolist_to_binary([Id, $-, integer_to_binary(N)]).
8171

0 commit comments

Comments
 (0)