feat(editor): add alt text support for images (#2097)

* feat(editor): add alt text support for images
* feat:  extend alt text support to videos and diagrams

---------
Co-authored-by: Philipinho <16838612+Philipinho@users.noreply.github.com>
This commit is contained in:
Olivier Lambert
2026-05-20 16:45:59 +01:00
committed by GitHub
co-authored by Philipinho
parent 66a754c9eb
commit 1c166c4736
12 changed files with 315 additions and 17 deletions
@@ -18,6 +18,7 @@ import {
} from "@tabler/icons-react";
import { useTranslation } from "react-i18next";
import { getFileUrl } from "@/lib/config.ts";
import { useAltTextControl } from "@/features/editor/components/common/use-alt-text-control.tsx";
import classes from "../common/toolbar-menu.module.css";
export function VideoMenu({ editor }: EditorMenuProps) {
@@ -38,6 +39,7 @@ export function VideoMenu({ editor }: EditorMenuProps) {
isAlignCenter: ctx.editor.isActive("video", { align: "center" }),
isAlignRight: ctx.editor.isActive("video", { align: "right" }),
src: videoAttrs?.src || null,
alt: videoAttrs?.alt || "",
};
},
});
@@ -112,6 +114,16 @@ export function VideoMenu({ editor }: EditorMenuProps) {
editor.commands.deleteSelection();
}, [editor]);
const {
button: altTextButton,
panel: altTextPanel,
isEditing: isEditingAlt,
} = useAltTextControl({
editor,
nodeName: "video",
currentAlt: editorState?.alt || "",
});
return (
<BaseBubbleMenu
editor={editor}
@@ -125,7 +137,10 @@ export function VideoMenu({ editor }: EditorMenuProps) {
}}
shouldShow={shouldShow}
>
<div className={classes.toolbar}>
{isEditingAlt ? (
altTextPanel
) : (
<div className={classes.toolbar}>
<Tooltip position="top" label={t("Align left")} withinPortal={false}>
<ActionIcon
onClick={alignLeft}
@@ -164,6 +179,10 @@ export function VideoMenu({ editor }: EditorMenuProps) {
<div className={classes.divider} />
{altTextButton}
<div className={classes.divider} />
<Tooltip position="top" label={t("Download")} withinPortal={false}>
<ActionIcon
onClick={handleDownload}
@@ -185,7 +204,8 @@ export function VideoMenu({ editor }: EditorMenuProps) {
<IconTrash size={18} />
</ActionIcon>
</Tooltip>
</div>
</div>
)}
</BaseBubbleMenu>
);
}
@@ -9,7 +9,7 @@ import { useTranslation } from "react-i18next";
export default function VideoView(props: NodeViewProps) {
const { t } = useTranslation();
const { editor, node, selected } = props;
const { src, width, align, aspectRatio, placeholder } = node.attrs;
const { src, width, align, alt, aspectRatio, placeholder } = node.attrs;
const alignClass = useMemo(() => {
if (align === "left") return "alignLeft";
if (align === "right") return "alignRight";
@@ -47,7 +47,7 @@ export default function VideoView(props: NodeViewProps) {
preload="metadata"
controls
src={getFileUrl(src)}
aria-label={placeholder?.name || t("Video")}
aria-label={alt || undefined}
/>
)}
{!src && previewSrc && (