-
Notifications
You must be signed in to change notification settings - Fork 186
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
LOOM-1540: tsx migration for splitinput and inputField components #3565
Conversation
@@ -5,4 +5,4 @@ We use [`jest-axe`](https://www.npmjs.com/package/jest-axe) to add automated acc | |||
|
|||
Generally, we only test the public interface of a component to reflect how it would be used in reality. For example, we have an accessibility test for `BpkAccordion` with `BpkAccordionItem` children, but we don't test them separately because they would never be used that way by a consumer. | |||
|
|||
Each package has it's accessibility tests in `accessibility-test.js`. | |||
Each package has its accessibility tests in `accessibility-test.js` or `accessibility-test.tsx`. |
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.
English Grammar 😸
Visit https://backpack.github.io/storybook-prs/3565 to see this build running in a browser. |
Browser supportIf this is a visual change, make sure you've tested it in multiple browsers. |
Visit https://backpack.github.io/storybook-prs/3565 to see this build running in a browser. |
Visit https://backpack.github.io/storybook-prs/3565 to see this build running in a browser. |
@@ -202,11 +216,12 @@ class BpkSplitInput extends Component { | |||
large={large} | |||
value={inputValue && inputValue[index]} | |||
placeholder={placeholder} | |||
onChange={this.handleOnChange} | |||
{...rest} |
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.
Usually this is placed at the end of the component so as not to accidently override any consumer provided props/overrides.
Additional objects should always be placed on the component last
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.
This was a conscious decision to put rest there so we override the below components based on how we handle them. rest at the end was making unwanted changes.
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.
Ok, maybe we need to check this out more, as rest should always come last. Could you clarify the unwanted change this would be making?
Could it be something we are passing in from the examples that overrides this
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.
As far as I understand we want to handle props as we have described in each function for:
onInput={this.handleOnChange}
onKeyDown={this.handleOnKeyDown}
onPaste={this.handleOnPaste}
onFocus={(e: FocusEvent<HTMLInputElement>) => this.handleOnFocus(e, index)}
onChange={this.handleOnChange}
But if we use rest
at the end, it overwrites our functions and how we want to handle our props.
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.
So this Component has all these custom handle event functions for managing behaviour.
If we allow parent onChange functions to override this components onEvent behaviour it could break.. Though I suppose it's up to the consumer... I think I may be wrong about this and rest can be at the end.
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.
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.
That's only if the consumer specifies the on{Event} functions. Which I suppose the onChange is a prop. You can define a default value for onChange? or is it that onChange is set in handleOnChange?
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.
If we defin onChange above then this error should go away? and we can specify if onChange ? onChange : this.handleOnChange
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.
Well turns out this prop was poorly named as it's purpose wasn't to be passed down to the input field it's to just give the consumer a way to add their function to the existing logic.
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.
Could you possibly take a look at moving away from the toMatchSnapshot()
and making it so it does better testing?
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.
Could you please elaborate and provide examples @olliecurtis ?
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.
Sure thing! I mean changing the tests to be more like we have now in the form-test.tsx that you have added in the PR: https://github.com/Skyscanner/backpack/pull/3565/files#diff-f889630b8387e0467cccc8992ea53a16a9fac15ae0fceaf69f9ce9021ca35f95R58
Or like this: https://github.com/Skyscanner/backpack/blob/main/packages/bpk-component-skeleton/src/BpkSkeleton-test.tsx#L28
3616155
to
0a56d23
Compare
Visit https://backpack.github.io/storybook-prs/3565 to see this build running in a browser. |
267a109
to
c7ee841
Compare
Visit https://backpack.github.io/storybook-prs/3565 to see this build running in a browser. |
166c88c
to
8a6c33b
Compare
Visit https://backpack.github.io/storybook-prs/3565 to see this build running in a browser. |
19a48cc
to
df205fb
Compare
Visit https://backpack.github.io/storybook-prs/3565 to see this build running in a browser. |
With the new change to this property this will change the contract with consumers, so we will need to move the label on this PR to be |
Visit https://backpack.github.io/storybook-prs/3565 to see this build running in a browser. |
Giving splitInputs some typescript LOVE.
Add form test for splitInput
FYI: Had to ignore a lint for one of the test because otherwise we'd need to write a recursive promise chain to do it and it's unnecessarily complicated for this simple test. 🙂
Remember to include the following changes:
[KOA-123][BpkButton] Updating the colour
README.md
(If you have created a new component)README.md