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] refactor(InputGroup): improve interface #4441

Merged
merged 7 commits into from
Jan 19, 2021

Conversation

ejose19
Copy link
Contributor

@ejose19 ejose19 commented Dec 1, 2020

Checklist

  • Includes tests
  • Update documentation

Changes proposed in this pull request:

This PR reduces the friction between InputGroup and HTMLInputElement by only replacing the properties that aren't supported { defaultValue: string[], value: string[] }

This has 2 benefits:

  • Users can now make reusable components by declaring the prop as just IInputGroupProps instead of IInputGroupProps & HTMLInputProps (just like the rest of Blueprint components)
  • No need to declare an explicit (and redundant) typing for onChange when the function is declared in the prop
<InputGroup onChange={(e) => e.currentTarget.value} /> // Previously e would be of type "any" triggering "noImplicitAny" rule

Copy link
Contributor

@adidahiya adidahiya left a comment

Choose a reason for hiding this comment

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

This is a good change but in its current state, it is a breaking change for anyone importing IInputGroupProps (yes, that type is used in many places by consumers). I suggest you mark the current interface as /** @deprecated */ and introduce a new one called IInputGroupProps2 which we can migrate to in the next major version.

@ejose19 ejose19 requested a review from adidahiya January 8, 2021 16:46
packages/core/src/common/props.ts Outdated Show resolved Hide resolved
@adidahiya
Copy link
Contributor

@ejose19 after #4475, do you think you could do the same kind of thing for Button and AnchorButton as you did for InputGroup in this PR?

@ejose19
Copy link
Contributor Author

ejose19 commented Jan 11, 2021

@adidahiya Done with all the review issues, I also replaced IInputGroupProps and IInputGroupProps & HTMLInputProps in other places that weren't update.

Can you tell me what's the issue with Button and AnchorButton exactly?

@adidahiya
Copy link
Contributor

adidahiya commented Jan 11, 2021

In the same way you've refactored IInputGroupProps & HTMLInputProps -> IInputGroupProps2 here, I think we could do something like IButtonProps & React.HTMLButtonAttributes<HTMLButtonElement> -> IButtonProps2

@ejose19
Copy link
Contributor Author

ejose19 commented Jan 11, 2021

@adidahiya I've checked the code and what you want can't be done with an interface, as ts will error with: An interface can only extend an object type or intersection of object types with statically known members.. However with a type there's not an issue, does that works for you? and if it does should the type name be named with an I as well?

@@ -94,6 +98,14 @@ export interface IControlledProps {
value?: string;
}

export interface IControlledProps2 {
Copy link
Contributor

Choose a reason for hiding this comment

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

sorry to revisit this -- why are you making this change to remove onChange from the interface? you're Omiting those fields anyway in IInputGroupProps2 below..?

Copy link
Contributor Author

@ejose19 ejose19 Jan 12, 2021

Choose a reason for hiding this comment

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

The point of IControlledProps (as far I understand it) is to define the correct types we support, which is only value: string on value and defaultValue props, however onChange is compatible without any other change, so we're defining unnecessary properties (and not following the original typing which is React.ChangeEvent not React.FormEventHandler [even though React.ChangeEventHandler could be used]).

So unless there's an specific reason so not use the native type, I don't see why it should be redefined.

@adidahiya
Copy link
Contributor

@ejose19 yeah I think a type is fine. we can discuss further about that in a separate issue or PR. I would keep the I prefix for now, and I am considering removing that prefix in v4.0 across the whole repo

@adidahiya adidahiya merged commit 7167c44 into palantir:develop Jan 19, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants