Skip to content

Commit ea846e2

Browse files
🤖 fix: blur after click in storybook play functions for deterministic snapshots (#1013)
## Summary Fixes flaky Chromatic snapshots where the AIView container sometimes shows a focus outline and sometimes doesn't. ## Problem The AIView container has `tabIndex={0}` for keyboard scrolling accessibility. When storybook play functions use `userEvent.click()` to expand tool calls, the click can non-deterministically trigger `focus-visible` on the container, causing intermittent focus outlines in visual snapshots. ## Solution Add `blur()` after clicks in affected play functions to ensure the visual snapshot captures the intended state (expanded tool) without unrelated focus styling. This preserves the accessibility feature (focus outline) in production while making the stories test what they're meant to test. _Generated with `mux`_
1 parent 30a8a91 commit ea846e2

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

‎src/browser/stories/App.chat.stories.tsx‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,8 @@ npm test 2>&1 | head -20`,
249249
const toolHeader = canvas.getByText(/set -e/);
250250
await userEvent.click(toolHeader);
251251
});
252+
// Remove unintended focus state for deterministic visual snapshot
253+
(document.activeElement as HTMLElement)?.blur();
252254
},
253255
};
254256

@@ -297,6 +299,8 @@ export const WithBashToolWaiting: AppStory = {
297299
const toolHeader = canvas.getByText(/npm test/);
298300
await userEvent.click(toolHeader);
299301
});
302+
// Remove unintended focus state for deterministic visual snapshot
303+
(document.activeElement as HTMLElement)?.blur();
300304
},
301305
};
302306

@@ -444,6 +448,8 @@ export const GenericTool: AppStory = {
444448
const toolHeader = canvas.getByText("fetch_data");
445449
await userEvent.click(toolHeader);
446450
});
451+
// Remove unintended focus state for deterministic visual snapshot
452+
(document.activeElement as HTMLElement)?.blur();
447453
},
448454
};
449455

0 commit comments

Comments
 (0)