2025-12-03 21:56:50 +00:00
|
|
|
import { useState, useEffect, useRef, useCallback } from 'react';
|
2026-02-09 22:05:26 +00:00
|
|
|
import { motion, AnimatePresence } from 'framer-motion';
|
2025-12-03 21:56:50 +00:00
|
|
|
import { cn } from '@/lib/utils';
|
|
|
|
|
|
|
|
|
|
export interface DropdownProps {
|
|
|
|
|
trigger: React.ReactNode;
|
|
|
|
|
children: React.ReactNode;
|
|
|
|
|
align?: 'left' | 'right' | 'center';
|
|
|
|
|
className?: string;
|
2026-02-06 01:27:29 +00:00
|
|
|
/** Controlled open state */
|
|
|
|
|
open?: boolean;
|
|
|
|
|
/** Uncontrolled default open */
|
|
|
|
|
defaultOpen?: boolean;
|
2025-12-03 21:56:50 +00:00
|
|
|
onOpenChange?: (open: boolean) => void;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Composant Dropdown réutilisable avec menu et gestion du clavier.
|
|
|
|
|
*/
|
|
|
|
|
export function Dropdown({
|
|
|
|
|
trigger,
|
|
|
|
|
children,
|
|
|
|
|
align = 'left',
|
|
|
|
|
className,
|
2026-02-06 01:27:29 +00:00
|
|
|
open: openProp,
|
|
|
|
|
defaultOpen = false,
|
2025-12-03 21:56:50 +00:00
|
|
|
onOpenChange,
|
|
|
|
|
}: DropdownProps) {
|
2026-02-06 01:27:29 +00:00
|
|
|
const [internalOpen, setInternalOpen] = useState(defaultOpen);
|
|
|
|
|
const isControlled = openProp !== undefined;
|
|
|
|
|
const open = isControlled ? openProp : internalOpen;
|
|
|
|
|
|
2025-12-03 21:56:50 +00:00
|
|
|
const containerRef = useRef<HTMLDivElement>(null);
|
|
|
|
|
const menuRef = useRef<HTMLDivElement>(null);
|
|
|
|
|
const triggerRef = useRef<HTMLDivElement>(null);
|
|
|
|
|
const focusedIndexRef = useRef<number>(-1);
|
|
|
|
|
|
|
|
|
|
const handleOpenChange = useCallback(
|
|
|
|
|
(newOpen: boolean) => {
|
2026-02-06 01:27:29 +00:00
|
|
|
if (!isControlled) {
|
|
|
|
|
setInternalOpen(newOpen);
|
|
|
|
|
}
|
2025-12-03 21:56:50 +00:00
|
|
|
onOpenChange?.(newOpen);
|
|
|
|
|
if (!newOpen) {
|
|
|
|
|
focusedIndexRef.current = -1;
|
|
|
|
|
}
|
|
|
|
|
},
|
2026-02-06 01:27:29 +00:00
|
|
|
[onOpenChange, isControlled],
|
2025-12-03 21:56:50 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
|
|
// Fermer le dropdown quand on clique en dehors
|
|
|
|
|
useEffect(() => {
|
|
|
|
|
if (!open) return;
|
|
|
|
|
|
|
|
|
|
const handleClickOutside = (event: MouseEvent) => {
|
|
|
|
|
if (
|
|
|
|
|
containerRef.current &&
|
|
|
|
|
!containerRef.current.contains(event.target as Node)
|
|
|
|
|
) {
|
|
|
|
|
handleOpenChange(false);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
document.addEventListener('mousedown', handleClickOutside);
|
|
|
|
|
return () => {
|
|
|
|
|
document.removeEventListener('mousedown', handleClickOutside);
|
|
|
|
|
};
|
|
|
|
|
}, [open, handleOpenChange]);
|
|
|
|
|
|
|
|
|
|
// Gestion du clavier
|
|
|
|
|
useEffect(() => {
|
|
|
|
|
if (!open) return;
|
|
|
|
|
|
|
|
|
|
const handleKeyDown = (event: KeyboardEvent) => {
|
|
|
|
|
if (!menuRef.current) return;
|
|
|
|
|
|
|
|
|
|
const focusableElements = menuRef.current.querySelectorAll<HTMLElement>(
|
2025-12-13 02:34:34 +00:00
|
|
|
'button, [href], input, select, textarea, [role="menuitem"], [tabindex]:not([tabindex="-1"])',
|
2025-12-03 21:56:50 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
|
|
const elements = Array.from(focusableElements);
|
|
|
|
|
|
|
|
|
|
switch (event.key) {
|
|
|
|
|
case 'Escape':
|
|
|
|
|
event.preventDefault();
|
|
|
|
|
handleOpenChange(false);
|
|
|
|
|
triggerRef.current?.focus();
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case 'ArrowDown':
|
|
|
|
|
event.preventDefault();
|
|
|
|
|
focusedIndexRef.current =
|
|
|
|
|
focusedIndexRef.current < elements.length - 1
|
|
|
|
|
? focusedIndexRef.current + 1
|
|
|
|
|
: 0;
|
|
|
|
|
elements[focusedIndexRef.current]?.focus();
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case 'ArrowUp':
|
|
|
|
|
event.preventDefault();
|
|
|
|
|
focusedIndexRef.current =
|
|
|
|
|
focusedIndexRef.current > 0
|
|
|
|
|
? focusedIndexRef.current - 1
|
|
|
|
|
: elements.length - 1;
|
|
|
|
|
elements[focusedIndexRef.current]?.focus();
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case 'Enter':
|
|
|
|
|
case ' ':
|
|
|
|
|
event.preventDefault();
|
2025-12-13 02:34:34 +00:00
|
|
|
if (
|
|
|
|
|
focusedIndexRef.current >= 0 &&
|
|
|
|
|
elements[focusedIndexRef.current]
|
|
|
|
|
) {
|
2025-12-03 21:56:50 +00:00
|
|
|
elements[focusedIndexRef.current].click();
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case 'Home':
|
|
|
|
|
event.preventDefault();
|
|
|
|
|
focusedIndexRef.current = 0;
|
|
|
|
|
elements[0]?.focus();
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case 'End':
|
|
|
|
|
event.preventDefault();
|
|
|
|
|
focusedIndexRef.current = elements.length - 1;
|
|
|
|
|
elements[elements.length - 1]?.focus();
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
document.addEventListener('keydown', handleKeyDown);
|
|
|
|
|
return () => {
|
|
|
|
|
document.removeEventListener('keydown', handleKeyDown);
|
|
|
|
|
};
|
|
|
|
|
}, [open, handleOpenChange]);
|
|
|
|
|
|
|
|
|
|
// Focuser le premier élément quand le menu s'ouvre
|
|
|
|
|
useEffect(() => {
|
|
|
|
|
if (open && menuRef.current) {
|
|
|
|
|
const focusableElements = menuRef.current.querySelectorAll<HTMLElement>(
|
2025-12-13 02:34:34 +00:00
|
|
|
'button, [href], input, select, textarea, [role="menuitem"], [tabindex]:not([tabindex="-1"])',
|
2025-12-03 21:56:50 +00:00
|
|
|
);
|
|
|
|
|
if (focusableElements.length > 0) {
|
|
|
|
|
focusedIndexRef.current = 0;
|
|
|
|
|
// Petit délai pour s'assurer que le menu est rendu
|
|
|
|
|
setTimeout(() => {
|
|
|
|
|
(focusableElements[0] as HTMLElement)?.focus();
|
|
|
|
|
}, 0);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}, [open]);
|
|
|
|
|
|
|
|
|
|
const alignClasses = {
|
|
|
|
|
left: 'left-0',
|
|
|
|
|
right: 'right-0',
|
|
|
|
|
center: 'left-1/2 -translate-x-1/2',
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<div ref={containerRef} className={cn('relative', className)}>
|
fix(a11y): Sprint 7 — semantic HTML and accessibility deep-dive
S7.1: Replace div onClick with semantic button in DialogTrigger.tsx
S7.2: Replace role="button" divs with native <button> elements in 12 files
(PlaylistCard, TrackCard, ConversationItem, NotificationMenuItem,
AudioPlayerTrackInfo, SearchPageResults, ProjectsManagerAddCard,
ProjectsManagerCard, GearInventoryGrid, UploadModal, dropdown.tsx,
LibraryPageGrid)
S7.3: Add focus-visible:ring-2 to 14 form inputs with outline-none across
9 modal files (CreateGroupModal, DataExportModal, EditPlaylistModal,
AddToPlaylistModal, BanUserModal, RefundRequestModal, FlashSaleModal,
TipStreamerModal, CreatePostModal)
S7.4: Add semantic landmarks — <section> in DashboardPage, <article> in
PostCard and CourseCard
Co-authored-by: Cursor <cursoragent@cursor.com>
2026-02-12 09:34:39 +00:00
|
|
|
<button
|
|
|
|
|
type="button"
|
|
|
|
|
ref={triggerRef as React.RefObject<HTMLButtonElement>}
|
2025-12-03 21:56:50 +00:00
|
|
|
onClick={() => handleOpenChange(!open)}
|
|
|
|
|
aria-haspopup="true"
|
|
|
|
|
aria-expanded={open}
|
|
|
|
|
onKeyDown={(e) => {
|
fix(a11y): Sprint 7 — semantic HTML and accessibility deep-dive
S7.1: Replace div onClick with semantic button in DialogTrigger.tsx
S7.2: Replace role="button" divs with native <button> elements in 12 files
(PlaylistCard, TrackCard, ConversationItem, NotificationMenuItem,
AudioPlayerTrackInfo, SearchPageResults, ProjectsManagerAddCard,
ProjectsManagerCard, GearInventoryGrid, UploadModal, dropdown.tsx,
LibraryPageGrid)
S7.3: Add focus-visible:ring-2 to 14 form inputs with outline-none across
9 modal files (CreateGroupModal, DataExportModal, EditPlaylistModal,
AddToPlaylistModal, BanUserModal, RefundRequestModal, FlashSaleModal,
TipStreamerModal, CreatePostModal)
S7.4: Add semantic landmarks — <section> in DashboardPage, <article> in
PostCard and CourseCard
Co-authored-by: Cursor <cursoragent@cursor.com>
2026-02-12 09:34:39 +00:00
|
|
|
if (e.key === 'ArrowDown') {
|
2025-12-03 21:56:50 +00:00
|
|
|
e.preventDefault();
|
|
|
|
|
handleOpenChange(true);
|
|
|
|
|
}
|
|
|
|
|
}}
|
fix(a11y): Sprint 7 — semantic HTML and accessibility deep-dive
S7.1: Replace div onClick with semantic button in DialogTrigger.tsx
S7.2: Replace role="button" divs with native <button> elements in 12 files
(PlaylistCard, TrackCard, ConversationItem, NotificationMenuItem,
AudioPlayerTrackInfo, SearchPageResults, ProjectsManagerAddCard,
ProjectsManagerCard, GearInventoryGrid, UploadModal, dropdown.tsx,
LibraryPageGrid)
S7.3: Add focus-visible:ring-2 to 14 form inputs with outline-none across
9 modal files (CreateGroupModal, DataExportModal, EditPlaylistModal,
AddToPlaylistModal, BanUserModal, RefundRequestModal, FlashSaleModal,
TipStreamerModal, CreatePostModal)
S7.4: Add semantic landmarks — <section> in DashboardPage, <article> in
PostCard and CourseCard
Co-authored-by: Cursor <cursoragent@cursor.com>
2026-02-12 09:34:39 +00:00
|
|
|
className="appearance-none bg-transparent border-0 p-0 inline-flex cursor-pointer text-inherit font-inherit focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-background rounded-lg"
|
2025-12-03 21:56:50 +00:00
|
|
|
>
|
|
|
|
|
{trigger}
|
fix(a11y): Sprint 7 — semantic HTML and accessibility deep-dive
S7.1: Replace div onClick with semantic button in DialogTrigger.tsx
S7.2: Replace role="button" divs with native <button> elements in 12 files
(PlaylistCard, TrackCard, ConversationItem, NotificationMenuItem,
AudioPlayerTrackInfo, SearchPageResults, ProjectsManagerAddCard,
ProjectsManagerCard, GearInventoryGrid, UploadModal, dropdown.tsx,
LibraryPageGrid)
S7.3: Add focus-visible:ring-2 to 14 form inputs with outline-none across
9 modal files (CreateGroupModal, DataExportModal, EditPlaylistModal,
AddToPlaylistModal, BanUserModal, RefundRequestModal, FlashSaleModal,
TipStreamerModal, CreatePostModal)
S7.4: Add semantic landmarks — <section> in DashboardPage, <article> in
PostCard and CourseCard
Co-authored-by: Cursor <cursoragent@cursor.com>
2026-02-12 09:34:39 +00:00
|
|
|
</button>
|
2025-12-03 21:56:50 +00:00
|
|
|
{open && (
|
2026-02-09 22:05:26 +00:00
|
|
|
<div
|
|
|
|
|
className="fixed inset-0 z-40"
|
|
|
|
|
onClick={() => handleOpenChange(false)}
|
|
|
|
|
aria-hidden="true"
|
|
|
|
|
/>
|
|
|
|
|
)}
|
|
|
|
|
<AnimatePresence>
|
|
|
|
|
{open && (
|
|
|
|
|
<motion.div
|
|
|
|
|
key="dropdown-menu"
|
2025-12-03 21:56:50 +00:00
|
|
|
ref={menuRef}
|
|
|
|
|
className={cn(
|
feat(web): UI premium Discord/Spotify-like — tokens, shadows, focus, layout
Plan UI premium 6–8 semaines (design system, shell, Storybook, a11y):
- Design system: DESIGN_TOKENS.md, APP_SHELL.md, FULL_LAYOUT_PAGE.md. Single source
for layout/shell (index.css), shadows (design-system.css), durations/easing.
- Tokens: shadow-cover-depth, shadow-gold-glow, shadow-fab-glow; layout max-height
(max-h-layout-drawer, max-h-layout-panel, max-h-layout-list). All duration-200/300/500
replaced by --duration-fast/normal/slow. Arbitrary shadows replaced by token classes.
- Shell & player: Sidebar, Header, GlobalPlayer, MiniPlayer, PlayerQueue, PlayerControls,
AudioPlayer use tokens; focus-visible on Sidebar, PlayerQueue, DropdownMenuTrigger/Item,
TabsTrigger. Typography: text-[10px]/[9px] → text-xs where applicable.
- ESLint: no-restricted-syntax (warn) for w-/h-/rounded-/shadow-/text-/spacing arbitrary.
- Scripts: report-arbitrary-values.mjs, capture/compare/generate visual; visual-complete.spec.ts.
- Stories full layout: Dashboard, Playlists, Library, Settings, Profile in DashboardLayout.stories.
- .cursorrules + README: DESIGN_TOKENS, APP_SHELL, visual commands, no arbitrary without justification.
- apps/web/.gitignore: e2e test artifacts (test-results-visual, playwright-report-visual).
Co-authored-by: Cursor <cursoragent@cursor.com>
2026-02-08 16:15:58 +00:00
|
|
|
'absolute z-50 mt-2 min-w-32 bg-card border border-border rounded-xl shadow-lg',
|
2026-02-09 22:05:26 +00:00
|
|
|
'overflow-hidden',
|
2025-12-13 02:34:34 +00:00
|
|
|
alignClasses[align],
|
2026-02-08 23:11:25 +00:00
|
|
|
align === 'right' ? 'origin-top-right' : align === 'center' ? 'origin-top' : 'origin-top-left',
|
2025-12-03 21:56:50 +00:00
|
|
|
)}
|
|
|
|
|
role="menu"
|
|
|
|
|
aria-orientation="vertical"
|
2026-02-09 22:05:26 +00:00
|
|
|
initial={{ opacity: 0, y: -4 }}
|
|
|
|
|
animate={{ opacity: 1, y: 0 }}
|
|
|
|
|
exit={{ opacity: 0, y: -4 }}
|
|
|
|
|
transition={{ duration: 0.12, ease: 'easeOut' }}
|
2025-12-03 21:56:50 +00:00
|
|
|
>
|
|
|
|
|
{children}
|
2026-02-09 22:05:26 +00:00
|
|
|
</motion.div>
|
|
|
|
|
)}
|
|
|
|
|
</AnimatePresence>
|
2025-12-03 21:56:50 +00:00
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
}
|