← Coinbase Interview InsightsFrontend Engineer
The swap logic itself was straightforward, just slice and reassign.
Start by clarifying requirements and constraints, then outline your component architecture with a focus on stable identity and reordering logic. Walk through the implementation step-by-step, explaining trade-offs and how you handle edge cases like empty states and accessibility.
Pro tip: Mention that you'd use a stable unique identifier (like an id from the data) as the key, not the index, to prevent re-render issues. Also, discuss how you'd optimize performance by memoizing item components and using efficient state updates.
Ask about the framework, expected data size, and any specific UX requirements (e.g., drag-and-drop vs. buttons). Confirm that reordering should be immediate and persistent.
Outline the component tree: a parent list component managing state, and child item components receiving props. Emphasize stable keys and controlled reordering.
Describe how to handle up/down actions: swap items in the array immutably, update state, and disable buttons at boundaries. Discuss using array methods like splice or slice.
Explain how to render a placeholder when the list is empty, and handle single-item lists (both buttons disabled). Mention accessibility: aria-labels, keyboard support.
Talk about memoization to prevent unnecessary re-renders, and trade-offs between using index vs. id for keys. Mention potential optimizations like virtual scrolling for large lists.
AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.
Start by clarifying the requirements for a fully accessible reorderable list, emphasizing keyboard operability, ARIA labeling, and focus management. Then walk through a concrete implementation using semantic HTML, appropriate ARIA roles, and JavaScript event handling, explaining how each aspect ensures accessibility. Finally, discuss trade-offs and testing strategies to validate the solution.
Pro tip: Mention that you would use a live region to announce reorder actions to screen reader users, and ensure focus remains on the moved item so users can continue reordering without losing context.
Confirm the expected keyboard interactions (e.g., arrow keys to move, space/enter to pick up/drop) and the need for ARIA labels that describe each item's position and reorder controls. Discuss any framework or library constraints.
Use a list structure (ul/li) with role='list' and each item having role='listitem'. Add a drag handle button with aria-label like 'Reorder item X' and ensure it's focusable. Consider using aria-grabbed or a custom state to indicate reorder mode.
Enable keyboard users to reorder via arrow keys when an item is focused. Provide clear instructions via aria-describedby. Ensure that pressing space/enter toggles reorder mode, and escape cancels.
After a reorder action, keep focus on the moved item so the user can continue. Use an aria-live region (polite) to announce the new position, e.g., 'Item moved to position 3 of 5'.
Test with screen readers (NVDA, VoiceOver) and keyboard-only navigation. Validate ARIA attributes and ensure no focus traps. Iterate based on feedback and consider automated accessibility testing tools.
AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.