As described in the issue, the current param seems not to be respected.
When loading the Storybook with OS color schema as dark, a default initialMode is always created with the dark value, so the re-evaluation of the current param value never happens again.
I wrote my initial thoughts here in the issue.
Solution proposed
Respect the param
For this purpose, I added a new property in the store to explicitly control if the user has clicked in the theme handler. If so, we respect the user decision. If not, we respect the current param, and at the end we look at the preferred color schema.
Why a new property? I think relying on the initialMode is not safe because it is set from multiple side effects. Having a unique property ensure we know if the user has set a preference.
Not reacting to OS color schema changes
I decided to add a check to NOT react to color schema changes in the OS because of this two cases:
To respect current property if set
To respect the user decision, if interaction has occur.
How to test
Run the example Storybook with the current param set to light
Issue #206
Motivation
As described in the issue, the
current
param seems not to be respected. When loading the Storybook with OS color schema asdark
, a defaultinitialMode
is always created with thedark
value, so the re-evaluation of thecurrent
param value never happens again. I wrote my initial thoughts here in the issue.Solution proposed
Respect the param
For this purpose, I added a new property in the store to explicitly control if the user has clicked in the theme handler. If so, we respect the user decision. If not, we respect the
current
param, and at the end we look at the preferred color schema.Why a new property? I think relying on the
initialMode
is not safe because it is set from multiple side effects. Having a unique property ensure we know if the user has set a preference.Not reacting to OS color schema changes
I decided to add a check to NOT react to color schema changes in the OS because of this two cases:
current
property if setHow to test
current
param set tolight
localStorage.clear()
current
param