Skip to content

feat(input, textarea): ionInput and ionChange pass event and value - #26176

Merged
liamdebeasi merged 7 commits into
feature-7.0from
FW-2615
Nov 1, 2022
Merged

liamdebeasi merged 7 commits into
feature-7.0from
FW-2615

Conversation

@liamdebeasi

@liamdebeasi liamdebeasi commented Oct 26, 2022 •

Copy link
Copy Markdown
Contributor

Pull request checklist

Please check if your PR fulfills the following requirements:

  • Tests for the changes have been added (for bug fixes / features)
  • Docs have been reviewed and added / updated if needed (for bug fixes / features)
    • Some docs updates need to be made in the ionic-docs repo, in a separate PR. See the contributing guide for details.
  • Build (npm run build) was run locally and any changes were pushed
  • Lint (npm run lint) has passed locally and any fixes were made for failures

Pull request type

Please check the type of change your PR introduces:

  • Bugfix
  • Feature
  • Code style update (formatting, renaming)
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • Documentation content changes
  • Other (please describe):

What is the current behavior?

Issue URL: N/A Internal Ticket

As a result of our recent ionChange revisions, the team noted that the ionInput and ionChange payloads were inconsistent. ionChange event detail has an object containing the value, but the ionInput event detail has the native event. We were concerned that those switching from ionChange to ionInput may find this migration confusing due to the different information available across events.

What is the new behavior?

  • ionInput and ionChange for ion-input and ion-textarea now have a detail payload of an object that contains the current component value and the native event (if one exists).
  • Created separate ChangeEventDetail and InputEventDetail interfaces. I opted to keep them separate for now despite them having the same contents. This was done to make the interfaces easier to reason above. We can consolidate them in the future if needed.
  • Updated InputCustomEvent and TextareaCustomEvent to use a generic for detail so that developers can specify either the input or the change event detail payload. I made it default to the {Input,Textarea}ChangeEventDetail interface to avoid another breaking change, but I am open to discussing this. This change is not needed at the moment, but it will be needed in case the InputEventDetail or ChangeEventDetail interfaces need to diverge again in the future.

Does this introduce a breaking change?

  • Yes
  • No

Other information

@github-actions github-actions Bot added the package: core @ionic/core package label Oct 26, 2022
@liamdebeasi
liamdebeasi marked this pull request as ready for review October 27, 2022 18:29
@liamdebeasi
liamdebeasi requested a review from a team as a code owner October 27, 2022 18:29
@averyrousseau
averyrousseau requested a review from a team October 28, 2022 18:54

@sean-perkins sean-perkins left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Looks good to me!

One small suggestion on the breaking change wording.

Comment thread BREAKING.md Resolved
Comment thread BREAKING.md Resolved
@github-actions github-actions Bot added the package: angular @ionic/angular package label Oct 31, 2022
@liamdebeasi
liamdebeasi merged commit eea6ba9 into feature-7.0 Nov 1, 2022
@liamdebeasi
liamdebeasi deleted the FW-2615 branch November 1, 2022 16:31
@piotr-cz

Copy link
Copy Markdown

I have an question - why InputChangeEventDetail interface have been changed, so that value may be a number:

eea6ba9#diff-5172cfa7e4dd36c59ff7084a0fcea91a7b910956c334673bb22eb138f84a8bda

value?: string | number | null;

Value of HTMLInputElement may only be a string - see MDN docs

This change hasn't been described in this PR or Ionic 7 migration docs, but in effect when using TypeScript in event handlers there must be added extra type check

@liamdebeasi

Copy link
Copy Markdown
Contributor Author

This looks like a typo. I created a PR to fix this here: #27226

@liamdebeasi liamdebeasi mentioned this pull request Apr 18, 2023
1 of 2 tasks
github-merge-queue Bot pushed a commit that referenced this pull request Apr 18, 2023
Issue number: N/A

---------

<!-- Please refer to our contributing documentation for any questions on
submitting a pull request, or let us know here if you need any help:
https://ionicframework.com/docs/building/contributing -->

<!-- Some docs updates need to be made in the `ionic-docs` repo, in a
separate PR. See
https://github.com/ionic-team/ionic-framework/blob/main/.github/CONTRIBUTING.md#modifying-documentation
for details. -->

<!-- Please do not submit updates to dependencies unless it fixes an
issue. -->

<!-- Please try to limit your pull request to one type (bugfix, feature,
etc). Submit multiple pull requests if needed. -->

## What is the current behavior?
<!-- Please describe the current behavior that you are modifying. -->

The `InputChangeEventDetail` and `InputInputEventDetail` interfaces were
updated to add a number type to the value key:
#26176

This was done to align with the value property on ion-input which allows
for strings and numbers. However, this is incorrect as the value emitted
is always forced to a string:
https://github.com/ionic-team/ionic-framework/blob/c9bddbdb4cd45fea6a7a57d9427a0294db0b4027/core/src/components/input/input.tsx#L416


We likely copied the the type definition for the `value` prop not
realizing that number values are never emitted.

## What is the new behavior?
<!-- Please describe the behavior or changes that are being added by
this PR. -->

- The `InputChangeEventDetail` and `InputInputEventDetail` interfaces no
longer have the `number` type
- The value passed to `ionInput` is converted to a string. (This isn't
really needed since the native `<input>` element will have a type of
string when the user types, but I added it for consistency with the
`ionChange` emission).
- Added a code comment to highlight this behavior

## Does this introduce a breaking change?

- [ ] Yes
- [x] No

Note: This is not a breaking change because `number` values were never
emitted in the first place.

<!-- If this introduces a breaking change, please describe the impact
and migration path for existing applications below. -->


## Other information

<!-- Any other information that is important to this PR such as
screenshots of how the component looks before and after the change. -->
github-merge-queue Bot pushed a commit that referenced this pull request Apr 18, 2023
Issue number: N/A

---------

<!-- Please refer to our contributing documentation for any questions on
submitting a pull request, or let us know here if you need any help:
https://ionicframework.com/docs/building/contributing -->

<!-- Some docs updates need to be made in the `ionic-docs` repo, in a
separate PR. See
https://github.com/ionic-team/ionic-framework/blob/main/.github/CONTRIBUTING.md#modifying-documentation
for details. -->

<!-- Please do not submit updates to dependencies unless it fixes an
issue. -->

<!-- Please try to limit your pull request to one type (bugfix, feature,
etc). Submit multiple pull requests if needed. -->

## What is the current behavior?
<!-- Please describe the current behavior that you are modifying. -->

The `InputChangeEventDetail` and `InputInputEventDetail` interfaces were
updated to add a number type to the value key:
#26176

This was done to align with the value property on ion-input which allows
for strings and numbers. However, this is incorrect as the value emitted
is always forced to a string:
https://github.com/ionic-team/ionic-framework/blob/c9bddbdb4cd45fea6a7a57d9427a0294db0b4027/core/src/components/input/input.tsx#L416


We likely copied the the type definition for the `value` prop not
realizing that number values are never emitted.

## What is the new behavior?
<!-- Please describe the behavior or changes that are being added by
this PR. -->

- The `InputChangeEventDetail` and `InputInputEventDetail` interfaces no
longer have the `number` type
- The value passed to `ionInput` is converted to a string. (This isn't
really needed since the native `<input>` element will have a type of
string when the user types, but I added it for consistency with the
`ionChange` emission).
- Added a code comment to highlight this behavior

## Does this introduce a breaking change?

- [ ] Yes
- [x] No

Note: This is not a breaking change because `number` values were never
emitted in the first place.

<!-- If this introduces a breaking change, please describe the impact
and migration path for existing applications below. -->


## Other information

<!-- Any other information that is important to this PR such as
screenshots of how the component looks before and after the change. -->
@piotr-cz

Copy link
Copy Markdown

@liamdebeasi Thank you 👍

liamdebeasi added a commit that referenced this pull request Apr 18, 2023
Issue number: N/A

---------

<!-- Please refer to our contributing documentation for any questions on
submitting a pull request, or let us know here if you need any help:
https://ionicframework.com/docs/building/contributing -->

<!-- Some docs updates need to be made in the `ionic-docs` repo, in a
separate PR. See
https://github.com/ionic-team/ionic-framework/blob/main/.github/CONTRIBUTING.md#modifying-documentation
for details. -->

<!-- Please do not submit updates to dependencies unless it fixes an
issue. -->

<!-- Please try to limit your pull request to one type (bugfix, feature,
etc). Submit multiple pull requests if needed. -->

## What is the current behavior?
<!-- Please describe the current behavior that you are modifying. -->

The `InputChangeEventDetail` and `InputInputEventDetail` interfaces were
updated to add a number type to the value key:
#26176

This was done to align with the value property on ion-input which allows
for strings and numbers. However, this is incorrect as the value emitted
is always forced to a string:
https://github.com/ionic-team/ionic-framework/blob/c9bddbdb4cd45fea6a7a57d9427a0294db0b4027/core/src/components/input/input.tsx#L416


We likely copied the the type definition for the `value` prop not
realizing that number values are never emitted.

## What is the new behavior?
<!-- Please describe the behavior or changes that are being added by
this PR. -->

- The `InputChangeEventDetail` and `InputInputEventDetail` interfaces no
longer have the `number` type
- The value passed to `ionInput` is converted to a string. (This isn't
really needed since the native `<input>` element will have a type of
string when the user types, but I added it for consistency with the
`ionChange` emission).
- Added a code comment to highlight this behavior

## Does this introduce a breaking change?

- [ ] Yes
- [x] No

Note: This is not a breaking change because `number` values were never
emitted in the first place.

<!-- If this introduces a breaking change, please describe the impact
and migration path for existing applications below. -->


## Other information

<!-- Any other information that is important to this PR such as
screenshots of how the component looks before and after the change. -->
liamdebeasi added a commit that referenced this pull request Apr 19, 2023
Issue number: N/A

---------

<!-- Please refer to our contributing documentation for any questions on
submitting a pull request, or let us know here if you need any help:
https://ionicframework.com/docs/building/contributing -->

<!-- Some docs updates need to be made in the `ionic-docs` repo, in a
separate PR. See
https://github.com/ionic-team/ionic-framework/blob/main/.github/CONTRIBUTING.md#modifying-documentation
for details. -->

<!-- Please do not submit updates to dependencies unless it fixes an
issue. -->

<!-- Please try to limit your pull request to one type (bugfix, feature,
etc). Submit multiple pull requests if needed. -->

## What is the current behavior?
<!-- Please describe the current behavior that you are modifying. -->

The `InputChangeEventDetail` and `InputInputEventDetail` interfaces were
updated to add a number type to the value key:
#26176

This was done to align with the value property on ion-input which allows
for strings and numbers. However, this is incorrect as the value emitted
is always forced to a string:
https://github.com/ionic-team/ionic-framework/blob/c9bddbdb4cd45fea6a7a57d9427a0294db0b4027/core/src/components/input/input.tsx#L416


We likely copied the the type definition for the `value` prop not
realizing that number values are never emitted.

## What is the new behavior?
<!-- Please describe the behavior or changes that are being added by
this PR. -->

- The `InputChangeEventDetail` and `InputInputEventDetail` interfaces no
longer have the `number` type
- The value passed to `ionInput` is converted to a string. (This isn't
really needed since the native `<input>` element will have a type of
string when the user types, but I added it for consistency with the
`ionChange` emission).
- Added a code comment to highlight this behavior

## Does this introduce a breaking change?

- [ ] Yes
- [x] No

Note: This is not a breaking change because `number` values were never
emitted in the first place.

<!-- If this introduces a breaking change, please describe the impact
and migration path for existing applications below. -->


## Other information

<!-- Any other information that is important to this PR such as
screenshots of how the component looks before and after the change. -->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

package: angular @ionic/angular package package: core @ionic/core package

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants