Skip to content

Commit c21693f

Browse files
authored
Improve screen reader accessibility for hints (#3680)
1 parent c06b3dd commit c21693f

File tree

12 files changed

+55
-0
lines changed

12 files changed

+55
-0
lines changed

.changeset/shaggy-clocks-rule.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"gitbook": patch
3+
---
4+
5+
Improve screen reader accessibility for hints

packages/gitbook/src/components/DocumentView/Hint.tsx

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ import { Icon, type IconName } from '@gitbook/icons';
33

44
import { type ClassValue, tcls } from '@/lib/tailwind';
55

6+
import { getSpaceLanguage, tString } from '@/intl/server';
7+
import { languages } from '@/intl/translations';
68
import { Block, type BlockProps } from './Block';
79
import { Blocks } from './Blocks';
810
import { getBlockTextStyle } from './spacing';
@@ -18,6 +20,12 @@ export function Hint({
1820
const firstLine = getBlockTextStyle(firstNode);
1921
const hasHeading = ['heading-1', 'heading-2', 'heading-3'].includes(firstNode.type);
2022

23+
const language = contextProps.context.contentContext
24+
? getSpaceLanguage(contextProps.context.contentContext)
25+
: languages.en;
26+
27+
const label = tString(language, `hint_${block.data.style}`);
28+
2129
return (
2230
<div
2331
className={tcls(
@@ -38,6 +46,8 @@ export function Hint({
3846

3947
style
4048
)}
49+
aria-label={label}
50+
role="note"
4151
>
4252
<div
4353
className={tcls(

packages/gitbook/src/intl/translations/de.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,4 +126,8 @@ export const de = {
126126
tool_call_skipped: 'Übersprungen "${1}"',
127127
scroll_back: 'Zurück scrollen',
128128
scroll_further: 'Weiter scrollen',
129+
hint_info: 'Information',
130+
hint_warning: 'Warnung',
131+
hint_danger: 'Gefahr',
132+
hint_success: 'Erfolg',
129133
};

packages/gitbook/src/intl/translations/en.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,4 +123,8 @@ export const en = {
123123
tool_call_skipped: 'Skipped "${1}"',
124124
scroll_back: 'Scroll back',
125125
scroll_further: 'Scroll further',
126+
hint_info: 'Information',
127+
hint_warning: 'Warning',
128+
hint_danger: 'Danger',
129+
hint_success: 'Success',
126130
};

packages/gitbook/src/intl/translations/es.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,4 +127,8 @@ export const es: TranslationLanguage = {
127127
tool_call_skipped: 'Omitido "${1}"',
128128
scroll_back: 'Desplazar hacia atrás',
129129
scroll_further: 'Desplazar más',
130+
hint_info: 'Información',
131+
hint_warning: 'Advertencia',
132+
hint_danger: 'Peligro',
133+
hint_success: 'Éxito',
130134
};

packages/gitbook/src/intl/translations/fr.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,4 +122,8 @@ export const fr = {
122122
tool_call_skipped: 'Ignoré "${1}"',
123123
scroll_back: "Défiler vers l'arrière",
124124
scroll_further: 'Défiler plus loin',
125+
hint_info: 'Information',
126+
hint_warning: 'Avertissement',
127+
hint_danger: 'Danger',
128+
hint_success: 'Succès',
125129
};

packages/gitbook/src/intl/translations/ja.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,4 +125,8 @@ export const ja: TranslationLanguage = {
125125
tool_call_skipped: '"${1}" をスキップしました',
126126
scroll_back: '戻る',
127127
scroll_further: '進む',
128+
hint_info: '情報',
129+
hint_warning: '警告',
130+
hint_danger: '危険',
131+
hint_success: '成功',
128132
};

packages/gitbook/src/intl/translations/nl.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,4 +125,8 @@ export const nl: TranslationLanguage = {
125125
tool_call_skipped: '"${1}" overgeslagen',
126126
scroll_back: 'Terug scrollen',
127127
scroll_further: 'Verder scrollen',
128+
hint_info: 'Informatie',
129+
hint_warning: 'Waarschuwing',
130+
hint_danger: 'Gevaar',
131+
hint_success: 'Succes',
128132
};

packages/gitbook/src/intl/translations/no.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,4 +126,8 @@ export const no: TranslationLanguage = {
126126
tool_call_skipped: 'Hoppet over "${1}"',
127127
scroll_back: 'Rull tilbake',
128128
scroll_further: 'Rull videre',
129+
hint_info: 'Informasjon',
130+
hint_warning: 'Advarsel',
131+
hint_danger: 'Fare',
132+
hint_success: 'Suksess',
129133
};

packages/gitbook/src/intl/translations/pt-br.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,4 +125,8 @@ export const pt_br = {
125125
tool_call_skipped: 'Pulado "${1}"',
126126
scroll_back: 'Rolar para trás',
127127
scroll_further: 'Rolar para frente',
128+
hint_info: 'Informação',
129+
hint_warning: 'Aviso',
130+
hint_danger: 'Perigo',
131+
hint_success: 'Sucesso',
128132
};

0 commit comments

Comments
 (0)