Skip to content

Commit 967d6a2

Browse files
Merge pull request #88 from gooddata/feat/accessibility-updates
feat: updated alert accessibility
2 parents 8c28638 + 5301dfb commit 967d6a2

9 files changed

Lines changed: 36 additions & 23 deletions

File tree

Lines changed: 1 addition & 1 deletion
Loading

assets/icons/icon-alert-info.svg

Lines changed: 1 addition & 1 deletion
Loading

assets/icons/icon-alert-label.svg

Lines changed: 1 addition & 1 deletion
Loading
Lines changed: 1 addition & 1 deletion
Loading

assets/scss/content-select.scss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
border-bottom: 0;
2828
border-top-left-radius: 4px;
2929
border-top-right-radius: 4px;
30-
color: rgba($color-deep-purple, 0.5);
30+
color: #776E8C;
3131
font-family: $gdfont-demibold;
3232
font-size: 14px;
3333
line-height: 1.25;

layouts/shortcodes/alert.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@
22
{{ $_hugo_config := `{ "version": 1 }` }}
33
{{ $color := .Get "color" | default "primary" }}
44
{{ $icon := .Get "color" | default "default" }}
5-
<aside class="alert alert-{{ $color }}" role="alert" aria-labelledby="alert-title">
5+
<div class="alert alert-{{ $color }}" role="note">
66
{{ with resources.Get (printf "icons/icon-alert-%s.svg" $icon) }}{{ ( . | minify).Content | safeHTML }}{{ end }}
77
{{ with .Get "title" }}<h4 class="alert-heading">{{ . | safeHTML }}</h4>{{ end }}
88
{{ if eq .Page.File.Ext "md" }}
99
{{ replaceRE "^<pre><code>" "" .Inner | safeHTML }}
1010
{{ else }}
1111
{{ .Inner | htmlUnescape | safeHTML }}
1212
{{ end }}
13-
</aside>
13+
</div>

layouts/shortcodes/content-block.html

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,12 @@
44
{{ $block := .Inner }}
55

66
{{ with .Parent }}
7-
{{ $selectId := .Get "id" }}
8-
{{ $scratchIdTitles := print "content-block-" (string .Ordinal) }}
9-
{{ .Scratch.SetInMap $scratchIdTitles (string $index) $title }}
7+
{{ $scratchIdTitles := print "content-block-" (string .Ordinal) }}
8+
{{ .Scratch.SetInMap $scratchIdTitles (string $index) $title }}
109

11-
<div id="panel-{{ $title | anchorize }}" class="gd-docs-content__block content-{{ $title | anchorize }}{{ if eq $index 0 }} active{{ end }}" role="tabpanel" aria-labelledby="tab-{{ $title | anchorize }}">
12-
{{ $block }}
13-
</div>
10+
<div class="gd-docs-content__block {{ if eq $index 0 }}active{{ end }}" role="tabpanel">
11+
{{ $block }}
12+
</div>
1413
{{ else }}
1514
{{ $block }}
1615
{{ end }}

layouts/shortcodes/content-select.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
{{ if $titles }}
77
<div class="gd-docs-content-select__tabs" role="tablist">
88
{{ range $index, $title := $titles }}
9-
<button id="tab-{{ $title | anchorize }}" class="gd-docs-content-select__tab{{ if eq $index "0" }} active{{ end }}" data-content="{{ $title | anchorize }}" role="tab" aria-selected="{{ if eq $index "0" }}true{{ else }}false{{ end }}" aria-controls="panel-{{ $title | anchorize }}">{{ $title }}</button>
9+
<button class="gd-docs-content-select__tab{{ if eq $index "0" }} active{{ end }}" role="tab" aria-selected="{{ if eq $index "0" }}true{{ else }}false{{ end }}">{{ $title }}</button>
1010
{{ end }}
1111
</div>
1212
{{ end }}

static/js/content-select.js

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
});
1313
}
1414
});
15-
15+
1616
setTimeout(function() {
1717
$(".gd-docs-content__block").each(function(index) {
1818
if (index > 0) {
@@ -27,9 +27,23 @@
2727

2828
// Set up tab click behavior
2929
$(".gd-docs-content-select__tab").on("click", setActive);
30-
30+
3131
// Set up keyboard navigation
3232
$(".gd-docs-content-select__tab").on("keydown", handleKeydown);
33+
34+
// Set up unique ids and aria attributes
35+
$(".gd-docs-content-select").each(function(index) {
36+
$(this).find(".gd-docs-content-select__tabs").children().each(function(tabIndex) {
37+
$(this).attr("id", "tab-" + (index + 1) + "-" + (tabIndex + 1));
38+
$(this).attr("aria-controls", "panel-" + (index + 1) + "-" + (tabIndex + 1));
39+
$(this).attr("data-content", "panel-" + (index + 1) + "-" + (tabIndex + 1));
40+
});
41+
$(this).find(".gd-docs-content__block").each(function(panelIndex) {
42+
$(this).attr("aria-labelledby", "tab-" + (index + 1) + "-" + (panelIndex + 1));
43+
$(this).attr("id", "panel-" + (index + 1) + "-" + (panelIndex + 1));
44+
$(this).addClass("content-panel-" + (index + 1) + "-" + (panelIndex + 1));
45+
});
46+
});
3347
});
3448

3549
var setActive = function() {
@@ -42,24 +56,24 @@
4256
$(this)
4357
.addClass("active")
4458
.attr("aria-selected", "true");
45-
59+
4660
// Update panels
4761
var contentId = $(this).data("content");
4862
var tabContainer = $(this).parent().parent();
49-
63+
5064
tabContainer
5165
.find(".gd-docs-content__block")
5266
.removeClass("active")
5367
.filter(".content-" + contentId)
5468
.addClass("active");
5569
}
5670
};
57-
71+
5872
var handleKeydown = function(e) {
5973
var $tabs = $(this).parent().find(".gd-docs-content-select__tab");
6074
var index = $tabs.index(this);
6175
var newIndex;
62-
76+
6377
switch(e.which) {
6478
// Left arrow
6579
case 37:
@@ -68,21 +82,21 @@
6882
e.preventDefault();
6983
$tabs.eq(newIndex).focus().click();
7084
break;
71-
85+
7286
// Right arrow
7387
case 39:
7488
newIndex = index + 1;
7589
if (newIndex >= $tabs.length) newIndex = 0;
7690
e.preventDefault();
7791
$tabs.eq(newIndex).focus().click();
7892
break;
79-
93+
8094
// Home
8195
case 36:
8296
e.preventDefault();
8397
$tabs.eq(0).focus().click();
8498
break;
85-
99+
86100
// End
87101
case 35:
88102
e.preventDefault();

0 commit comments

Comments
 (0)