From e83e8ce24e8f8d9a67252605f553215b129c715e Mon Sep 17 00:00:00 2001 From: Angelina Gadzhieva Date: Fri, 29 Sep 2023 15:44:34 +0300 Subject: [PATCH] fix(storybook): add focus on story iframe --- .storybook/focus-addon/register.tsx | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 .storybook/focus-addon/register.tsx diff --git a/.storybook/focus-addon/register.tsx b/.storybook/focus-addon/register.tsx new file mode 100644 index 0000000..9284281 --- /dev/null +++ b/.storybook/focus-addon/register.tsx @@ -0,0 +1,11 @@ +import {addons, } from '@storybook/addons'; + +addons.register('initialFocus', () => { + addons.getChannel().on('currentStoryWasSet', () => focusIframe()); +}) + +const focusIframe = () => { + const previewIframe: HTMLInputElement | null = document.querySelector('#storybook-preview-iframe'); + + previewIframe?.focus?.(); + }