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

[core] feat(InputGroup): new prop onValueChange #6290

Merged
merged 5 commits into from
Jul 25, 2023

Conversation

thasner
Copy link
Contributor

@thasner thasner commented Jul 19, 2023

Checklist

  • Includes tests
  • Update documentation

Changes proposed in this pull request:

Add a new onValueChange callback prop to <InputGroup> which behaves similarly to the same prop for <NumericInput>.

Motivation: this helps prevent common potential footguns with React 16 Event Pooling where developers sometimes forget to save event.target.value as a variable or use event.persist(), which can lead to null-pointer exceptions at runtime.

Various uses of <InputGroup onChange> within the Blueprint monorepo have also been updated to use the new prop to demonstrate its efficacy.

Reviewers should focus on:

docs & tests for the new prop

Screenshot

N/A

@@ -156,6 +164,12 @@ export class InputGroup extends AbstractPureComponent<InputGroupProps, InputGrou
}
}

private handleInputChange = (event: React.ChangeEvent<HTMLInputElement>) => {
const value = event.currentTarget.value;
this.props.onChange?.(event);
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 wasn't sure if it'd be reasonable to ban native onChange usage, let alone make such a breaking change.

Copy link
Contributor

Choose a reason for hiding this comment

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

No, we won't ban it, and we can't make a breaking change like that right now. We can just update the docs and maybe create a lint rule.

Copy link
Contributor

Choose a reason for hiding this comment

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

Event pooling is going away in React 17, so I think this will become less of a problem: https://legacy.reactjs.org/blog/2020/08/10/react-v17-rc.html#no-event-pooling

I added a note in the JSDoc for the new prop about why users might prefer this handler instead of onChange.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

sounds good.
imo the onValueChange signature is also an ergonomic improvement, so i anticipate it'll still have usage

@adidahiya adidahiya changed the title Add onValueChange to InputGroup [core] feat(InputGroup): new prop onValueChange Jul 21, 2023
@adidahiya adidahiya marked this pull request as ready for review July 25, 2023 18:20
@adidahiya
Copy link
Contributor

docs preview looks fine 👍🏽

@adidahiya adidahiya merged commit b383527 into palantir:develop Jul 25, 2023
const filter = (e.target as HTMLInputElement).value;
this.setState({ filter });
};
private handleFilterChange = (filter: string) => this.setState({ filter });
Copy link
Contributor Author

Choose a reason for hiding this comment

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

nice

@thasner thasner deleted the th/input-group-value-change branch September 3, 2023 18:27
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.

3 participants