Fix: current
param not being respected by the dark OS color mode
#207
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Issue #206
Motivation
As described in the issue, the
current
param seems not to be respected.When loading the Storybook with OS color schema as
dark
, 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