Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .Jules/palette.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
## 2024-06-22 - [CommentsPanel Keyboard A11y]
**Learning:** Simple chat/comment inputs that lack a surrounding `<form>` 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.
13 changes: 10 additions & 3 deletions src/components/CommentsPanel.tsx
Original file line number Diff line number Diff line change
@@ -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 }
Expand Down Expand Up @@ -56,15 +57,21 @@ export default function CommentsPanel({ entityType, entityId }: Props) {
<input
value={text}
onChange={(e) => setText(e.target.value)}
onKeyDown={(e: KeyboardEvent<HTMLInputElement>) => {
if (e.key === 'Enter' && !loading && text.trim()) {
post()
Comment on lines +61 to +62

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Ignore IME composition Enter before posting

When a user types a comment with an IME for languages such as Japanese or Chinese, pressing Enter often commits the current composition/candidate instead of meaning “submit”. This handler now treats every Enter as a post action, so those users can accidentally submit a partially composed comment; check the composition state, e.g. e.nativeEvent.isComposing, before calling post().

Useful? React with 👍 / 👎.

}
}}
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"
/>
<button
onClick={post}
disabled={loading || !text.trim()}
className="rounded-md bg-[#6C63FF] px-3 py-2 text-xs font-semibold text-white disabled:opacity-50 hover:bg-[#5A52E6] transition-colors duration-150"
aria-busy={loading}
className="rounded-md bg-[#6C63FF] px-3 py-2 text-xs font-semibold text-white disabled:opacity-50 hover:bg-[#5A52E6] transition-colors duration-150 min-w-[56px] flex items-center justify-center"
>
Post
{loading ? <Loader2 className="size-4 animate-spin" aria-hidden="true" /> : 'Post'}
</button>
</div>
</div>
Expand Down
Loading