Skip to content

Commit

Permalink
Merge pull request #12322 from storybookjs/11839-undefined-boolean-prop
Browse files Browse the repository at this point in the history
Addon-controls: Fix uncontrolled to controlled warning for booleans
  • Loading branch information
shilman committed Aug 31, 2020
2 parents a000606 + 143364d commit 039583b
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 1 deletion.
@@ -0,0 +1,7 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`Storyshots Issues/11839 undefined boolean Primary 1`] = `
<div>
Disabled: false
</div>
`;
@@ -0,0 +1,14 @@
<template>
<div>Disabled: {{disabled}}</div>
</template>

<script>
export default {
props: {
disabled: Boolean,
},
mounted() {
console.log(this.disabled); // notice this line
},
};
</script>
@@ -0,0 +1,15 @@
import Comp from './component.vue';

export default {
title: 'Issues/11839 undefined boolean',
component: Comp,
};

export const Primary = (args, { argTypes }) => {
return {
props: Object.keys(argTypes),
components: { Comp },
// template: '<Comp />', // this will log out `false`
template: '<Comp v-bind="$props" />', // this will log out `undefined`
};
};
2 changes: 1 addition & 1 deletion lib/components/src/controls/Boolean.tsx
Expand Up @@ -86,7 +86,7 @@ export const BooleanControl: FC<BooleanProps> = ({ name, value, onChange, onBlur
id={name}
type="checkbox"
onChange={(e) => onChange(e.target.checked)}
checked={value}
checked={value || false}
{...{ name, onBlur, onFocus }}
/>
<span>True</span>
Expand Down

0 comments on commit 039583b

Please sign in to comment.