Skip to content

Commit

Permalink
Merge pull request #25950 from storybookjs/jeppe/25035-bug-boolean-co…
Browse files Browse the repository at this point in the history
…ntrol-in-true-state-in-url-is-ignored

Core: Fix boolean `true` args in URL getting ignored
(cherry picked from commit d77745e)
  • Loading branch information
JReinhold authored and storybook-bot committed Feb 9, 2024
1 parent bc5eb4f commit 491dfb8
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
7 changes: 4 additions & 3 deletions code/lib/preview-api/src/modules/store/args.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,9 @@ describe('mapArgsToTypes', () => {
});

it('maps booleans', () => {
expect(mapArgsToTypes({ a: true }, { a: { type: booleanType } })).toStrictEqual({ a: true });
expect(mapArgsToTypes({ a: 'true' }, { a: { type: booleanType } })).toStrictEqual({ a: true });
expect(mapArgsToTypes({ a: 'false' }, { a: { type: booleanType } })).toStrictEqual({
expect(mapArgsToTypes({ a: false }, { a: { type: booleanType } })).toStrictEqual({
a: false,
});
expect(mapArgsToTypes({ a: 'yes' }, { a: { type: booleanType } })).toStrictEqual({ a: false });
Expand Down Expand Up @@ -129,7 +130,7 @@ describe('mapArgsToTypes', () => {
{
key: {
arr: ['1', '2'],
obj: { bool: 'true' },
obj: { bool: true },
},
},
{
Expand Down Expand Up @@ -159,7 +160,7 @@ describe('mapArgsToTypes', () => {
key: [
{
arr: ['1', '2'],
obj: { bool: 'true' },
obj: { bool: true },
},
],
},
Expand Down
2 changes: 1 addition & 1 deletion code/lib/preview-api/src/modules/store/args.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const map = (arg: unknown, argType: InputType): any => {
case 'number':
return Number(arg);
case 'boolean':
return arg === 'true';
return String(arg) === 'true';
case 'array':
if (!type.value || !Array.isArray(arg)) return INCOMPATIBLE;
return arg.reduce((acc, item, index) => {
Expand Down

0 comments on commit 491dfb8

Please sign in to comment.