Skip to content

Listen to Storybook events in preview.ts in Storybook 8 #28407

Answered by doubleedesign
dmy-leanix asked this question in Help
Discussion options

You must be logged in to vote

I just had a very similar problem when debugging something in the a11y addon. I was trying to use channel.on() to detect events, but it was only picking up events I emitted myself. I had tried importing both via @storybook/addons and @storybook/manager-api, neither worked.

When digging into the a11y addon's code to see how it was accessing and using the channel, I found it was importing addons from storybook/internal/preview-api. I updated my code to import addons like so:

import { addons } from '@storybook/preview-api';

and now everything works how I expected it to! For example:

channel.on('storybook/a11y/result', (data) => {
    console.log('A11y result', data);
})

As per your example, …

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@dmy-leanix
Comment options

Answer selected by dmy-leanix
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Help
Labels
None yet
2 participants