Skip to content

Commit

Permalink
allow setting tabs heading level
Browse files Browse the repository at this point in the history
  • Loading branch information
woylie committed Jan 1, 2024
1 parent 006a813 commit 63a15c8
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
7 changes: 6 additions & 1 deletion lib/doggo.ex
Original file line number Diff line number Diff line change
Expand Up @@ -3891,6 +3891,11 @@ defmodule Doggo do
attr :id, :string, required: true
attr :title, :string, required: true, doc: "A title that labels the tabs."

attr :heading, :string,
default: "h3",
values: ["h2", "h3", "h4", "h5", "h6"],
doc: "The heading level."

attr :class, :any,
default: [],
doc: "Additional CSS classes. Can be a string or a list of strings."
Expand All @@ -3904,7 +3909,7 @@ defmodule Doggo do
def tabs(assigns) do
~H"""
<div id={@id} class={["tabs" | List.wrap(@class)]} {@rest}>
<h3 id={"#{@id}-title"}><%= @title %></h3>
<.dynamic_tag name={@heading} id={"#{@id}-title"}><%= @title %></.dynamic_tag>
<div role="tablist" aria-labelledby={"#{@id}-title"}>
<button
:for={{panel, index} <- Enum.with_index(@panel, 1)}
Expand Down
14 changes: 14 additions & 0 deletions test/doggo_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -4170,6 +4170,20 @@ defmodule DoggoTest do
assert text(div) == "some other text"
end

test "with heading" do
assigns = %{}

html =
parse_heex(~H"""
<Doggo.tabs id="my-tabs" title="My Tabs" heading="h4">
<:panel label="Panel 1">some text</:panel>
<:panel label="Panel 2">some other text</:panel>
</Doggo.tabs>
""")

assert text(html, ":root > h4") == "My Tabs"
end

test "with additional class as string" do
assigns = %{}

Expand Down

0 comments on commit 63a15c8

Please sign in to comment.