diff --git a/.Jules/palette.md b/.Jules/palette.md new file mode 100644 index 00000000..52b4851e --- /dev/null +++ b/.Jules/palette.md @@ -0,0 +1,3 @@ +## 2024-06-22 - [CommentsPanel Keyboard A11y] +**Learning:** Simple chat/comment inputs that lack a surrounding `
` tag require an explicit `onKeyDown` handler to capture the "Enter" key for submission, otherwise users are forced to use the mouse. +**Action:** When auditing or implementing simple inline inputs (like search, comment, or quick-reply bars), proactively check for form wrappers or `onKeyDown` handlers to ensure keyboard accessibility. diff --git a/src/components/CommentsPanel.tsx b/src/components/CommentsPanel.tsx index 2a595884..81993e34 100644 --- a/src/components/CommentsPanel.tsx +++ b/src/components/CommentsPanel.tsx @@ -1,6 +1,7 @@ 'use client' -import { useEffect, useState } from 'react' +import { useEffect, useState, KeyboardEvent } from 'react' +import { Loader2 } from 'lucide-react' import type { CommentRecord } from '@/lib/db/types' type Props = { entityType: 'event' | 'insight'; entityId: string } @@ -56,15 +57,21 @@ export default function CommentsPanel({ entityType, entityId }: Props) { setText(e.target.value)} + onKeyDown={(e: KeyboardEvent) => { + if (e.key === 'Enter' && !loading && text.trim()) { + post() + } + }} placeholder="Write a comment..." className="flex-1 rounded-md border border-white/10 bg-white/5 px-3 py-2 text-xs text-slate-100 placeholder:text-slate-500 focus:outline-none focus:ring-2 focus:ring-sky-400/40" />