Skip to content

Commit 2155c2f

Browse files
committed
✨(frontend) add document visible in list and openable via enter key
the document now appears in the list and can be opened using the enter key Signed-off-by: Cyril <c.gromoff@gmail.com>
1 parent ef08ba3 commit 2155c2f

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

src/frontend/apps/impress/src/features/docs/docs-grid/components/DocsGridItem.tsx

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { Tooltip, useModal } from '@openfun/cunningham-react';
22
import { DateTime } from 'luxon';
3+
import { useRouter } from 'next/router';
34
import { useTranslation } from 'react-i18next';
45
import { css } from 'styled-components';
56

@@ -21,6 +22,7 @@ type DocsGridItemProps = {
2122

2223
export const DocsGridItem = ({ doc, dragMode = false }: DocsGridItemProps) => {
2324
const { t } = useTranslation();
25+
const router = useRouter();
2426
const { isDesktop } = useResponsiveStore();
2527
const { flexLeft, flexRight } = useResponsiveDocGrid();
2628
const { spacingsTokens } = useCunninghamTheme();
@@ -33,6 +35,13 @@ export const DocsGridItem = ({ doc, dragMode = false }: DocsGridItemProps) => {
3335
shareModal.open();
3436
};
3537

38+
const handleKeyDown = (e: React.KeyboardEvent) => {
39+
if (e.key === 'Enter' || e.key === ' ') {
40+
e.preventDefault();
41+
void router.push(`/docs/${doc.id}`);
42+
}
43+
};
44+
3645
return (
3746
<>
3847
<Box
@@ -52,6 +61,10 @@ export const DocsGridItem = ({ doc, dragMode = false }: DocsGridItemProps) => {
5261
}
5362
`}
5463
className="--docs--doc-grid-item"
64+
onKeyDown={handleKeyDown}
65+
aria-label={t('Open document: {{title}}', {
66+
title: doc.title || t('Untitled document'),
67+
})}
5568
>
5669
<Box
5770
$flex={flexLeft}

src/frontend/apps/impress/src/i18n/translations.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -372,6 +372,7 @@
372372
"Open the document options": "Öffnen Sie die Dokumentoptionen",
373373
"Open the header menu": "Öffne das Kopfzeilen-Menü",
374374
"Open document actions menu": "Dokumentaktionsmenü öffnen",
375+
"Open document: {{title}}": "Dokument öffnen: {{title}}",
375376
"Main content": "Hauptinhalt",
376377
"Home content": "Startseiten-Inhalt",
377378
"Documents grid": "Dokumentenraster",
@@ -478,6 +479,7 @@
478479
"Cancel the deletion": "Cancel the deletion",
479480
"Cancel the download": "Cancel the download",
480481
"Open actions menu for document: {{title}}": "Open actions menu for document: {{title}}",
482+
"Open document: {{title}}": "Open document: {{title}}",
481483
"Open the menu of actions for the document: {{title}}": "Open the menu of actions for the document: {{title}}",
482484
"Share with {{count}} users_one": "Share with {{count}} user",
483485
"Shared with {{count}} users_many": "Shared with {{count}} users",
@@ -607,6 +609,7 @@
607609
"Open the document options": "Abrir las opciones del documento",
608610
"Open the header menu": "Abrir el menú de encabezado",
609611
"Open document actions menu": "Abrir menú de acciones del documento",
612+
"Open document: {{title}}": "Abrir documento: {{title}}",
610613
"Main content": "Contenido principal",
611614
"Home content": "Contenido de inicio",
612615
"Documents grid": "Lista de documentos",
@@ -839,6 +842,7 @@
839842
"Open the document options": "Ouvrir les options du document",
840843
"Open the header menu": "Ouvrir le menu d'en-tête",
841844
"Open document actions menu": "Ouvrir le menu d'actions du document",
845+
"Open document: {{title}}": "Ouvrir le document : {{title}}",
842846
"Open the menu of actions for the document: {{title}}": "Ouvrir le menu des actions du document : {{title}}",
843847
"Main content": "Contenu principal",
844848
"Home content": "Contenu d'accueil",
@@ -1204,6 +1208,7 @@
12041208
"Open the document options": "Open document opties",
12051209
"Open the header menu": "Open het hoofdmenu",
12061210
"Open document actions menu": "Open documentactiemenu",
1211+
"Open document: {{title}}": "Document openen: {{title}}",
12071212
"Main content": "Hoofdinhoud",
12081213
"Home content": "Startpagina-inhoud",
12091214
"Documents grid": "Documentenraster",

0 commit comments

Comments
 (0)