-
-
Notifications
You must be signed in to change notification settings - Fork 9.3k
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 update logic for argTypes with custom names #11704
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,7 +21,7 @@ export interface ArgControlProps { | |
const NoControl = () => <>-</>; | ||
|
||
export const ArgControl: FC<ArgControlProps> = ({ row, arg, updateArgs }) => { | ||
const { name, control } = row; | ||
const { key, control } = row; | ||
|
||
const [isFocused, setFocused] = useState(false); | ||
// box because arg can be a fn (e.g. actions) and useState calls fn's | ||
|
@@ -32,20 +32,22 @@ export const ArgControl: FC<ArgControlProps> = ({ row, arg, updateArgs }) => { | |
}, [isFocused, arg]); | ||
|
||
const onChange = useCallback( | ||
(argName: string, argVal: any) => { | ||
(argVal: any) => { | ||
setBoxedValue({ value: argVal }); | ||
updateArgs({ [name]: argVal }); | ||
updateArgs({ [key]: argVal }); | ||
return argVal; | ||
}, | ||
[updateArgs, name] | ||
[updateArgs, key] | ||
); | ||
|
||
const onBlur = useCallback(() => setFocused(false), []); | ||
const onFocus = useCallback(() => setFocused(true), []); | ||
|
||
if (!control || control.disable) return <NoControl />; | ||
|
||
const props = { name, argType: row, value: boxedValue.value, onChange, onBlur, onFocus }; | ||
// 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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @shilman and I discussed adding a |
||
const props = { name: key, argType: row, value: boxedValue.value, onChange, onBlur, onFocus }; | ||
switch (control.type) { | ||
case 'array': | ||
return <ArrayControl {...props} {...control} />; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't see any reason for the callback to have the key. Before we were ignoring it anyway. The Controls shouldn't need to know this detail.