'use client' import { useEffect, useState } from 'react' import { MAX_ALT_TEXT_LENGTH, normalizeAltText } from '@/utils/altText' interface ImageAltTextDialogProps { /** Preview source of the image being described. */ src: string /** Current alt text for the image. */ initialAlt: string /** Save the new (normalized) alt text. */ onSave: (alt: string) => void /** Close without saving. */ onClose: () => void } /** * Per-image alt-text editor, ported from Bluesky's ImageAltTextDialog to the * product's stack (modal + Tailwind/CSS-variables instead of the RN Dialog). * Lets screen-reader users get a real description of post media. */ export default function ImageAltTextDialog({ src, initialAlt, onSave, onClose, }: ImageAltTextDialogProps) { const [value, setValue] = useState(initialAlt) // Close on Escape for keyboard users. useEffect(() => { const onKey = (e: KeyboardEvent) => { if (e.key === 'Escape') onClose() } window.addEventListener('keydown', onKey) return () => window.removeEventListener('keydown', onKey) }, [onClose]) const remaining = MAX_ALT_TEXT_LENGTH - value.length const handleSave = () => { onSave(normalizeAltText(value)) } return (
e.stopPropagation()} >

Image description

{/* eslint-disable-next-line @next/next/no-img-element */} {value