From 4ddc894dbf6dcec50cdefd5fe0f131fbbd1f9411 Mon Sep 17 00:00:00 2001 From: Norbert de Langen Date: Mon, 13 Jan 2020 21:07:51 +0100 Subject: [PATCH] FIX https://github.com/storybookjs/storybook/issues/9405 --- addons/knobs/src/components/types/Select.tsx | 2 +- .../stories/addon-knobs/with-knobs.stories.js | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/addons/knobs/src/components/types/Select.tsx b/addons/knobs/src/components/types/Select.tsx index 50a5d52b5648..a81b734be6c4 100644 --- a/addons/knobs/src/components/types/Select.tsx +++ b/addons/knobs/src/components/types/Select.tsx @@ -32,7 +32,7 @@ const SelectType: FunctionComponent & { const { options } = knob; const callbackReduceArrayOptions = (acc: any, option: any, i: number) => { - if (typeof option !== 'object') return { ...acc, [option]: option }; + if (typeof option !== 'object' || option === null) return { ...acc, [option]: option }; const label = option.label || option.key || i; return { ...acc, [label]: option }; }; diff --git a/examples/official-storybook/stories/addon-knobs/with-knobs.stories.js b/examples/official-storybook/stories/addon-knobs/with-knobs.stories.js index e458969cc86e..f497fa12074a 100644 --- a/examples/official-storybook/stories/addon-knobs/with-knobs.stories.js +++ b/examples/official-storybook/stories/addon-knobs/with-knobs.stories.js @@ -45,6 +45,12 @@ export default { decorators: [withKnobs], }; +export const selectKnob = () => { + const value = select('value', [1, 2, 3, undefined, null], 1); + + return
{JSON.stringify({ value: String(value) }, null, 2)}
; +}; + export const TweaksStaticValues = () => { const name = text('Name', 'Storyteller'); const age = number('Age', 70, { range: true, min: 0, max: 90, step: 5 });