Skip to content

Conversation

@gefgu
Copy link
Contributor

@gefgu gefgu commented Sep 14, 2022

What: Closes #7672
Convert Number Input examples to TypeScript.

Additional issues:

@gefgu gefgu changed the title chore(Number): Convert examples to TypeScript chore(Number Input): Convert examples to TypeScript Sep 14, 2022
@patternfly-build
Copy link
Collaborator

patternfly-build commented Sep 14, 2022

@gefgu gefgu force-pushed the chore/convert-number-examples-to-ts branch from e47dc9b to f7e384b Compare September 17, 2022 13:09
Copy link
Contributor

@nicolethoen nicolethoen left a comment

Choose a reason for hiding this comment

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

Could you update the file names of the examples to be NumberInput<ExampleName>.tsx?


export const UnitNumberInput: React.FunctionComponent = () => {
const [value1, setValue1] = React.useState(90);
const [value2, setValue2] = React.useState(Number((1.0).toFixed(2)));
Copy link
Contributor

Choose a reason for hiding this comment

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

So I'm noticing here that the 1.00 which was part of the original example is now displaying at 1 - and it's actually because by passing (1.0).toFixed(2) to a Number constructor, you are casting a string to a number and losing the extra trailing two zeros.

This is necessary because the type of the value prop on NumberInput is number | null, so it cannot accept a string 1.00 value. It's possible we could update the number input value to accept strings and cast them to numbers internally. Not sure what side effects there'd be for that.

@tlabaj I'm not sure if you have thoughts about how we can handle this. I can open a follow up issue if we want - only if we are happy to the update to the example

Copy link
Contributor

Choose a reason for hiding this comment

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

I think getting rid of Number here will fix the issue.

Copy link
Contributor

Choose a reason for hiding this comment

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

But the value prop has the type Number, and type of (1.0).toFixed(2) is string

Copy link
Contributor

Choose a reason for hiding this comment

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

I would say it is fine as is then. The previous implementation was technically incorrect since it had value2: (1.0).toFixed(2)

@nicolethoen nicolethoen requested a review from tlabaj September 19, 2022 17:29
@gefgu gefgu force-pushed the chore/convert-number-examples-to-ts branch from f7e384b to 24a4df0 Compare September 19, 2022 18:17
@gefgu
Copy link
Contributor Author

gefgu commented Sep 19, 2022

@nicolethoen thanks for the kind feedback. This really helps my learning journey :) Once you decide about the issue with 1.00, I would be happy to help.

Copy link
Contributor

@tlabaj tlabaj left a comment

Choose a reason for hiding this comment

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

LGTM

@nicolethoen nicolethoen merged commit a763bf7 into patternfly:main Sep 29, 2022
@patternfly-build
Copy link
Collaborator

Your changes have been released in:

  • @patternfly/react-catalog-view-extension@4.92.15
  • @patternfly/react-code-editor@4.82.15
  • @patternfly/react-console@4.92.15
  • @patternfly/react-core@4.243.1
  • @patternfly/react-docs@5.102.17
  • @patternfly/react-inline-edit-extension@4.86.15
  • demo-app-ts@4.201.15
  • @patternfly/react-log-viewer@4.87.10
  • @patternfly/react-table@4.110.15
  • @patternfly/react-topology@4.88.15
  • @patternfly/react-virtualized-extension@4.88.15

Thanks for your contribution! 🎉

@gefgu gefgu deleted the chore/convert-number-examples-to-ts branch September 29, 2022 19:04
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.

Number input: convert examples to typescript

4 participants