Skip to content

Commit e1857a7

Browse files
feat(editor): improve image alt text input interaction (#3379)
Enhance image alt text field visibility by showing on hover or focus, and add focus/blur state tracking for better user experience.
1 parent c68f384 commit e1857a7

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

packages/tiptap/src/blog-editor/image-with-alt.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { useCallback, useEffect, useRef, useState } from "react";
55

66
function ImageNodeView({ node, updateAttributes, selected }: NodeViewProps) {
77
const [isHovered, setIsHovered] = useState(false);
8+
const [isFocused, setIsFocused] = useState(false);
89
const [altText, setAltText] = useState(node.attrs.alt || "");
910
const inputRef = useRef<HTMLInputElement>(null);
1011
const containerRef = useRef<HTMLDivElement>(null);
@@ -28,6 +29,8 @@ function ImageNodeView({ node, updateAttributes, selected }: NodeViewProps) {
2829
}
2930
}, []);
3031

32+
const showAltField = isHovered || isFocused;
33+
3134
return (
3235
<NodeViewWrapper className="relative">
3336
<div
@@ -46,7 +49,7 @@ function ImageNodeView({ node, updateAttributes, selected }: NodeViewProps) {
4649
].join(" ")}
4750
draggable={false}
4851
/>
49-
{isHovered && (
52+
{showAltField && (
5053
<div className="absolute bottom-2 left-2 right-2 bg-white/95 backdrop-blur-sm rounded-md shadow-lg border border-neutral-200 p-2">
5154
<label className="flex items-center gap-2">
5255
<span className="text-xs text-neutral-500 whitespace-nowrap">
@@ -58,6 +61,8 @@ function ImageNodeView({ node, updateAttributes, selected }: NodeViewProps) {
5861
value={altText}
5962
onChange={handleAltChange}
6063
onKeyDown={handleKeyDown}
64+
onFocus={() => setIsFocused(true)}
65+
onBlur={() => setIsFocused(false)}
6166
placeholder="Describe this image..."
6267
className="flex-1 text-sm bg-transparent border-none outline-none text-neutral-700 placeholder:text-neutral-400"
6368
/>

0 commit comments

Comments
 (0)