实现一个 Autocomplete(输入建议)组件:支持防抖、键盘导航、选择项高亮、无障碍、异步请求取消与缓存。
Implement an autocomplete component: debounced input, keyboard navigation, highlighted selection, a11y, async cancelation and caching.
题目类型: 技术面试题
这是一道技术面试题,常见于澳洲IT公司面试中。
难度: hard
标签: Lyft, Autocomplete, A11y, Debounce
目标岗位: Frontend Engineer, Front End Engineer, Web Developer
目标公司: Lyft
参考答案摘要
答案(实现清单) 输入防抖: 避免每次输入都请求。 异步竞态处理: 用 AbortController 取消上一次请求;或用递增 requestId 丢弃过期响应。 缓存: Map 缓存 query->results。 键盘交互: ArrowUp/Down 移动高亮;Enter 选择;Escape 关闭。 无障碍(WAI-ARIA combobox 模式): input: role="combob...
本题提供 STAR 原则详细解答和技术解析,登录匠人学院学习中心即可查看完整答案。