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

LOOM-1540: tsx migration for splitinput and inputField components #3565

Merged
merged 12 commits into from
Aug 7, 2024

Conversation

Parisistan
Copy link
Contributor

@Parisistan Parisistan commented Jul 30, 2024

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:

  • Ensure the PR title includes the name of the component you are changing so it's clear in the release notes for consumers of the changes in the version e.g [KOA-123][BpkButton] Updating the colour
  • README.md (If you have created a new component)
  • Component README.md
  • Tests
  • Accessibility tests
    • The following checks were performed:
      • Ability to navigate using a keyboard only
      • Zoom functionality (Deque University explanation):
        • The page SHOULD be functional AND readable when only the text is magnified to 200% of its initial size
        • Pages must reflow as zoom increases up to 400% so that content continues to be presented in only one column i.e. Content MUST NOT require scrolling in two directions (both vertically and horizontally)
      • Ability to navigate using a screen reader only
  • Storybook examples created/updated
  • For breaking changes or deprecating components/properties, migration guides added to the description of the PR. If the guide has large changes, consider creating a new Markdown page inside the component's docs folder and link it here

@Parisistan Parisistan added enhancement minor Non breaking change labels Jul 30, 2024
@Parisistan Parisistan self-assigned this Jul 30, 2024
@@ -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`.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

English Grammar 😸

Copy link

Visit https://backpack.github.io/storybook-prs/3565 to see this build running in a browser.

Copy link

github-actions bot commented Jul 31, 2024

Warnings
⚠️

Package source files (e.g. packages/package-name/src/Component.js) were updated, but snapshots weren't. Have you checked that the tests still pass?

⚠️

Package source files (e.g. packages/package-name/src/Component.tsx) were updated, but type files weren't. Have you checked that no types have changed?

Browser support

If this is a visual change, make sure you've tested it in multiple browsers.

Generated by 🚫 dangerJS against b1c3647

Copy link

github-actions bot commented Aug 1, 2024

Visit https://backpack.github.io/storybook-prs/3565 to see this build running in a browser.

@Parisistan Parisistan marked this pull request as ready for review August 1, 2024 16:21
Copy link

github-actions bot commented Aug 2, 2024

Visit https://backpack.github.io/storybook-prs/3565 to see this build running in a browser.

packages/bpk-component-split-input/src/BpkInputField.tsx Outdated Show resolved Hide resolved
packages/bpk-component-split-input/src/BpkInputField.tsx Outdated Show resolved Hide resolved
packages/bpk-component-split-input/src/BpkSplitInput.tsx Outdated Show resolved Hide resolved
packages/bpk-component-split-input/src/BpkSplitInput.tsx Outdated Show resolved Hide resolved
packages/bpk-component-split-input/src/BpkSplitInput.tsx Outdated Show resolved Hide resolved
packages/bpk-component-split-input/src/BpkSplitInput.tsx Outdated Show resolved Hide resolved
packages/bpk-component-split-input/src/BpkSplitInput.tsx Outdated Show resolved Hide resolved
@@ -202,11 +216,12 @@ class BpkSplitInput extends Component {
large={large}
value={inputValue && inputValue[index]}
placeholder={placeholder}
onChange={this.handleOnChange}
{...rest}
Copy link
Member

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

Copy link
Contributor Author

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.

Copy link
Member

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

Copy link
Contributor Author

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.

Copy link
Contributor

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Alright ... If I move {...rest} down, it means they are overwiring the handle fuctions which makes the handle functions irrelevant and creating error below:
image
How do we handle that?

Copy link
Contributor

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?

Copy link
Contributor

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

Copy link
Contributor

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.

Copy link
Member

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?

Copy link
Contributor Author

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 ?

Copy link
Member

Choose a reason for hiding this comment

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

@Parisistan Parisistan force-pushed the LOOM-1540-splitinput_enhancements branch from 3616155 to 0a56d23 Compare August 5, 2024 15:22
Copy link

github-actions bot commented Aug 5, 2024

Visit https://backpack.github.io/storybook-prs/3565 to see this build running in a browser.

@Parisistan Parisistan force-pushed the LOOM-1540-splitinput_enhancements branch from 267a109 to c7ee841 Compare August 6, 2024 10:18
Copy link

github-actions bot commented Aug 6, 2024

Visit https://backpack.github.io/storybook-prs/3565 to see this build running in a browser.

@Parisistan Parisistan force-pushed the LOOM-1540-splitinput_enhancements branch from 166c88c to 8a6c33b Compare August 6, 2024 10:27
Copy link

github-actions bot commented Aug 6, 2024

Visit https://backpack.github.io/storybook-prs/3565 to see this build running in a browser.

@Parisistan Parisistan force-pushed the LOOM-1540-splitinput_enhancements branch from 19a48cc to df205fb Compare August 6, 2024 11:35
Copy link

github-actions bot commented Aug 6, 2024

Visit https://backpack.github.io/storybook-prs/3565 to see this build running in a browser.

@olliecurtis
Copy link
Member

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 major :)

@Parisistan Parisistan added major Breaking change and removed minor Non breaking change labels Aug 7, 2024
Copy link

github-actions bot commented Aug 7, 2024

Visit https://backpack.github.io/storybook-prs/3565 to see this build running in a browser.

@Parisistan Parisistan merged commit 99ead74 into main Aug 7, 2024
11 checks passed
@Parisistan Parisistan deleted the LOOM-1540-splitinput_enhancements branch August 7, 2024 11:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement major Breaking change
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants