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-controls: Fix uncontrolled to controlled warning for booleans #12322

Merged
merged 3 commits into from Aug 31, 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
@@ -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