Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Addon-knobs: Fix null knob values in select #9416

Merged
merged 1 commit into from Jan 13, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion addons/knobs/src/components/types/Select.tsx
Expand Up @@ -32,7 +32,7 @@ const SelectType: FunctionComponent<SelectTypeProps> & {
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 };
};
Expand Down
Expand Up @@ -45,6 +45,12 @@ export default {
decorators: [withKnobs],
};

export const selectKnob = () => {
const value = select('value', [1, 2, 3, undefined, null], 1);

return <div>{JSON.stringify({ value: String(value) }, null, 2)}</div>;
};

export const TweaksStaticValues = () => {
const name = text('Name', 'Storyteller');
const age = number('Age', 70, { range: true, min: 0, max: 90, step: 5 });
Expand Down