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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Controls: Fix esm is not defined error with built Storybook #15812

Merged
merged 1 commit into from Aug 12, 2021
Merged
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
9 changes: 5 additions & 4 deletions lib/components/src/blocks/ArgsTable/ArgControl.tsx
Expand Up @@ -42,15 +42,16 @@ export const ArgControl: FC<ArgControlProps> = ({ row, arg, updateArgs }) => {
const { key, control } = row;

const [isFocused, setFocused] = useState(false);
const [value, setValue] = useState(() => arg);
// box because arg can be a fn (e.g. actions) and useState calls fn's
const [boxedValue, setBoxedValue] = useState({ value: arg });

useEffect(() => {
if (!isFocused) setValue(arg);
if (!isFocused) setBoxedValue({ value: arg });
}, [isFocused, arg]);

const onChange = useCallback(
(argVal: any) => {
setValue(argVal);
setBoxedValue({ value: argVal });
updateArgs({ [key]: argVal });
return argVal;
},
Expand All @@ -64,7 +65,7 @@ export const ArgControl: FC<ArgControlProps> = ({ row, arg, updateArgs }) => {

// row.name is a display name and not a suitable DOM input id or name - i might contain whitespace etc.
// row.key is a hash key and therefore a much safer choice
const props = { name: key, argType: row, value, onChange, onBlur, onFocus };
const props = { name: key, argType: row, value: boxedValue.value, onChange, onBlur, onFocus };
const Control = Controls[control.type] || NoControl;
return <Control {...props} {...control} controlType={control.type} />;
};