Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tabpane: ensure each HTML elt has a unique ID #1610

Merged
merged 1 commit into from
Jul 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion layouts/shortcodes/tab.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
{{ $header = (.Get 0) -}}
{{ else -}}
{{/* Prefill header if not given as named or unnamed parameter */ -}}
{{ $header = default (printf "Tab %v" ( add $.Ordinal 1)) (.Get "header") -}}
{{ $header = .Get "header" | default (printf "Tab %v" .Ordinal) -}}
{{ end -}}

{{/* store all tab info in dict tab */ -}}
Expand Down
32 changes: 13 additions & 19 deletions layouts/shortcodes/tabpane.html
Original file line number Diff line number Diff line change
Expand Up @@ -47,22 +47,16 @@
{{ $persistTab := and $deprecatedPersistLang (ne $persistKeyKind "none") -}}
{{ $rightPane := default false ($.Get "right") -}}
{{ $activeSet := false -}}
{{- /* Scratchpad gets populated through call to .Inner */ -}}
{{- .Inner -}}
{{/* Scratchpad gets populated through call to .Inner */ -}}
{{ .Inner -}}

{{ $persistKeyList := slice -}}
{{ $duplicate := false -}}
{{ $duplicateKey := "" -}}

{{ $Ordinal := $.Ordinal -}}
{{ if ge hugo.Version "0.93.0" -}}
{{ if .Page.Store.Get "Ordinal" -}}
{{ $Ordinal = .Page.Store.Get "Ordinal" -}}
{{end -}}
{{ end -}}
{{ $persistKeyList := slice -}}
{{ $tabPaneOrdinal := .Ordinal -}}

{{/* Nav tabs */ -}}
<ul class="nav nav-tabs{{ if $rightPane }} justify-content-end{{ end }}" id="tabs-{{- $Ordinal -}}" role="tablist">
<ul class="nav nav-tabs{{ if $rightPane }} justify-content-end{{ end }}" id="tabs-{{- $tabPaneOrdinal -}}" role="tablist">
{{ range $index, $element := $.Scratch.Get "tabs" -}}

{{ $disabled := false -}}
Expand Down Expand Up @@ -104,8 +98,8 @@

<li class="nav-item{{ if $rightpush }} ms-auto{{ end -}}">
{{/* Generate the IDs for the <a> and the <div> elements */ -}}
{{ $tabid := printf "tabs-%02v-%v-tab" $Ordinal $index | anchorize -}}
{{ $entryid := printf "tabs-%02v-%v" $Ordinal $index | anchorize -}}
{{ $tabid := printf "tabs-%02v-%v-tab" $tabPaneOrdinal $index | anchorize -}}
{{ $entryid := printf "tabs-%02v-%v" $tabPaneOrdinal $index | anchorize -}}

<button class="nav-link
{{- if and ( not $activeSet ) ( not $disabled ) }} active{{ end -}}
Expand All @@ -124,7 +118,7 @@
{{ $activeSet = true -}}
{{ end -}}

{{- end }}
{{ end }}
</ul>

{{ if $duplicate -}}
Expand All @@ -134,7 +128,7 @@
{{ $activeSet = false -}}

{{/* Tab panes */ -}}
<div class="tab-content" id="tabs-{{ $Ordinal }}-content">
<div class="tab-content" id="tabs-{{ $tabPaneOrdinal }}-content">
{{- range $index, $element := $.Scratch.Get "tabs" -}}

{{ $lang := $langPane -}}
Expand All @@ -160,10 +154,10 @@
{{ $text = . }}
{{ end -}}

{{ $tabid := printf "tabs-%02v-%v-tab" $Ordinal $index | anchorize -}}
{{ $entryid := printf "tabs-%02v-%v" $Ordinal $index | anchorize }}
{{ $tabid := printf "tabs-%02v-%v-tab" $tabPaneOrdinal $index | anchorize -}}
{{ $entryid := printf "tabs-%02v-%v" $tabPaneOrdinal $index | anchorize }}
<div class="{{ if $text }}tab-body {{end}}tab-pane fade{{ if and ( not $activeSet ) ( not $disabled ) }} show active{{ end }}"
id="{{ $entryid }}" role="tabpanel" aria-labelled-by="{{ $tabid }}" tabindex="{{ $Ordinal }}">
id="{{ $entryid }}" role="tabpanel" aria-labelled-by="{{ $tabid }}" tabindex="{{ $tabPaneOrdinal }}">
{{ if $text -}}
{{ index . "content" -}}
{{ else -}}
Expand All @@ -175,5 +169,5 @@
{{ $activeSet = true -}}
{{ end -}}

{{- end }}
{{ end }}
</div>