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 });