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 update logic for argTypes with custom names #11704

Merged
merged 2 commits into from
Jul 29, 2020

Conversation

jonspalmer
Copy link
Contributor

@jonspalmer jonspalmer commented Jul 28, 2020

Controls with a name don't update when changed. Failing test case against Official Storybook.

What I did

  • changed the Controls props to pass row.key rather row.name as the name prop.
  • changed the Controls API so that onChange just provides the changed value not the arg name/key
  • fixed all the stories

How to test

  • load official example
  • Test the controls under "Controls" ie /?path=/story/controls-boolean--basic
  • Test the Args Table under "Core/Args" ie /?path=/story/core-args--passed-to-story

@jonspalmer
Copy link
Contributor Author

My sense is that ArgControl should be using row.key throughout rather than row.name That has a slightly scary blast radius as each of the Control components take the 'name' and use if for setting DOM ids and names.

@shilman shilman added this to the 6.0 args milestone Jul 28, 2020
@shilman shilman self-assigned this Jul 28, 2020
@jonspalmer jonspalmer self-assigned this Jul 29, 2020
@jonspalmer jonspalmer force-pushed the controls_update_name_not_key branch from 7309560 to beccf74 Compare July 29, 2020 13:18
@jonspalmer jonspalmer force-pushed the controls_update_name_not_key branch from beccf74 to 28b64b6 Compare July 29, 2020 13:50
@@ -32,20 +32,20 @@ export const ArgControl: FC<ArgControlProps> = ({ row, arg, updateArgs }) => {
}, [isFocused, arg]);

const onChange = useCallback(
(argName: string, argVal: any) => {
(argVal: any) => {
Copy link
Contributor Author

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.

);

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
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@shilman and I discussed adding a key prop (which would actually have to be argKey as key is a React reserved property). However, with the onChange adjustment its mostly unnecessary. We're really intending to hand in something that can be used as a DOM Input id/name. This makes for a much smaller change

Copy link
Member

@shilman shilman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Thanks for the fix @jonspalmer!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants