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
10 changes: 10 additions & 0 deletions .Jules/palette.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
## 2024-06-24 - Hidden File Input and Overlay Button Focus

**Learning:**
- Hidden file inputs (`className="hidden"`) can still receive keyboard focus if they don't explicitly have `tabIndex={-1}` and `aria-hidden="true"`, causing a confusing focus state for screen reader and keyboard users.
- Absolute positioned icon-only buttons overlaying images within `overflow-hidden` containers lose their default focus rings due to clipping.

**Action:**
- Always explicitly add `tabIndex={-1}` and `aria-hidden="true"` to visually hidden file inputs to ensure they are excluded from keyboard navigation and screen readers.
- For overlay buttons, use Tailwind focus utility classes (e.g., `focus-visible:ring-2 focus-visible:ring-offset-2 focus-visible:outline-none`) combined with `shadow-lg` to prevent the focus ring from clipping and ensure visibility. Ensure the ring color matches the action context (e.g., `ring-red-500` for destructive, `ring-blue-500` for standard actions).
- Always ensure icon-only buttons have an explicit `aria-label` and `aria-hidden="true"` on the internal SVG/icon component.
9 changes: 6 additions & 3 deletions src/components/ImageUploader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ export function ImageUploader({ onImageLoad, currentImage, onClear }: ImageUploa
<p className="text-xs text-gray-500 mb-3 sm:mb-4">{t('supportedFormats')}</p>
<button
onClick={() => fileInputRef.current?.click()}
className="px-3 sm:px-4 py-2 text-sm bg-blue-500 text-white rounded-lg hover:bg-blue-600 active:scale-95 transition-all"
className="px-3 sm:px-4 py-2 text-sm bg-blue-500 text-white rounded-lg hover:bg-blue-600 active:scale-95 transition-all focus-visible:ring-2 focus-visible:ring-offset-2 focus-visible:ring-blue-500 focus-visible:outline-none"
>
{t('selectFile')}
</button>
Expand All @@ -92,6 +92,8 @@ export function ImageUploader({ onImageLoad, currentImage, onClear }: ImageUploa
type="file"
accept="image/*"
className="hidden"
tabIndex={-1}
aria-hidden="true"
onChange={(e) => {
const file = e.target.files?.[0];
if (file) handleFileSelect(file);
Expand All @@ -109,10 +111,11 @@ export function ImageUploader({ onImageLoad, currentImage, onClear }: ImageUploa
</div>
<button
onClick={onClear}
className="absolute top-2 right-2 p-1.5 sm:p-2 bg-red-500 text-white rounded-full hover:bg-red-600 active:scale-95 transition-all shadow-lg"
className="absolute top-2 right-2 p-1.5 sm:p-2 bg-red-500 text-white rounded-full hover:bg-red-600 active:scale-95 transition-all shadow-lg focus-visible:ring-2 focus-visible:ring-offset-2 focus-visible:ring-red-500 focus-visible:outline-none"
title={t('removeImage')}
aria-label={t('removeImage')}
>
Comment on lines 115 to 117

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

Having both title and aria-label with the exact same value on an interactive element can cause some screen readers (such as NVDA or VoiceOver) to announce the label twice, leading to a redundant and confusing user experience.

Since the button has no other text content (the <X> icon is correctly marked with aria-hidden="true"), the title attribute already acts as the accessible name for the button. Therefore, aria-label is redundant and can be safely removed to prevent double announcements while retaining the hover tooltip.

Suggested change
title={t('removeImage')}
aria-label={t('removeImage')}
>
title={t('removeImage')}
>

<X size={16} className="sm:w-5 sm:h-5" />
<X size={16} className="sm:w-5 sm:h-5" aria-hidden="true" />
</button>
</div>
)}
Expand Down