但是我们的 content should not be reachable via tab key 这个测试案例为什么无法通过
- User
但是我们的
content should not be reachable via tab key这个测试案例为什么无法通过 Assistant
Investigating failing test focus behaviorSearching collapsible component codeInspecting dataset usage in componentsOpening src directoryVerifying connectionAnalyzing focus and hidden attribute behaviorAnalyzing failing tab key testAnalyzing focus and animation interaction定位原因
- 在
connect.ts里,内容面板的hidden属性只会在state.matches('open', 'closing')为false时才设置;当触发第二次点击进入closing状态时,visible仍为true以便播放收起动画,因此该阶段hidden仍为false。 - 测试中在第二次点击后立刻执行了
userEvent.tab();此时动画尚未结束,DOM 里<a href="#">仍处于可聚焦状态,焦点会先跳到它而不是控件区的 “Open” 按钮,断言因此失败。 - 如果等待动画发送
ANIMATION.END并让状态进入closed,焦点就会按照预期跳到“Open”按钮。
可选方案
- 在组件层面,于
closing状态就让内容不可聚焦(例如临时加上inert或aria-hidden+tabindex=-1),确保收起动画期间也阻止 Tab 导航。 - 在测试里等待收起动画结束(比如监听
page.waitFor某个属性变化或显式等待contentEl.hidden为true)后再触发tab()。
你可以根据更符合产品期望的行为选择其一,或先加等待验证现象。
- 在
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.