BUG | useDark
| Cannot use useDark with Storybook
#4444
Replies: 11 comments · 2 replies
-
If it is the same origin, you should be able to specify the parent window. const isDark = useDark({
window:window.parent.window,
disableTransition: false // For some reason an error occurs, so set it to false for now.
}); |
Beta Was this translation helpful? Give feedback.
-
Thank you for the reply. Were you able to confirm this issue with my reproduction case? Unfortunately, that did not work. In Button.vue, I did:
I then started storybook ( I did confirm that the |
Beta Was this translation helpful? Give feedback.
-
I am not sure that |
Beta Was this translation helpful? Give feedback.
-
ah. I misunderstood the problem! |
Beta Was this translation helpful? Give feedback.
-
@eric-g-97477 decorators: [
withThemeByClassName({
themes: {
light: 'light',
dark: 'dark'
},
defaultTheme: 'light'
}),
(Story, context) => {
const [globals] = useGlobals()
const isDark = useDark();
nextTick(() => {
isDark.value = globals.theme === 'dark'
})
return Story(context)
},
] |
Beta Was this translation helpful? Give feedback.
-
I am curious as to why it is not able to detect the changing class in the html tag...? In my reproduction project, I changed my preview.ts file to look like:
|
Beta Was this translation helpful? Give feedback.
-
@eric-g-97477 (Story, context) => {
const isDark = useDark();
nextTick(() => {
isDark.value = context.globals.theme === 'dark';
});
return Story(context);
}, |
Beta Was this translation helpful? Give feedback.
-
Yep. That one worked. I wonder what was different about our environments. Why were you able to use useGlobals and I was not...? It is also interesting that useDark does not monitor the DOM. I would have thought that would be necessary. I will have to look into how it is actually working when I get the chance. Perhaps there would be a way to have useDark work regardless of environment. In any case, thank you for the workaround. |
Beta Was this translation helpful? Give feedback.
-
Oh, I did see one more issue with this solution, but it is a minor one. There is an initialization problem. I did:
When the story is first run (make sure you use a new browser window), what is logged is:
|
Beta Was this translation helpful? Give feedback.
-
if the function can be async you can |
Beta Was this translation helpful? Give feedback.
-
this does not seem to be a vueuse issue. ill transfer this into a discussion. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Describe the bug
I do
const isDark = useDark()
. When I try to access the value from my component inside of Storybook (npm run storybook
), it will always report false even thought I can see the tag containsclass="dark"
. When I run the app withnpm run dev
, it works as expected. The only reason I can think of is that when running in storybook, the component is operating within an iframe.Is this a known issue? Is there a workaround? Have I not configured something correctly?
Reproduction
https://github.com/eric-g-97477-vue/storybook-vueuse
System Info
Used Package Manager
npm
Validations
Beta Was this translation helpful? Give feedback.
All reactions