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

bug: autocapitalize is required in IonSearchbar types #29193

Closed
3 tasks done
aeharding opened this issue Mar 20, 2024 · 4 comments · Fixed by #29197
Closed
3 tasks done

bug: autocapitalize is required in IonSearchbar types #29193

aeharding opened this issue Mar 20, 2024 · 4 comments · Fixed by #29197
Assignees
Labels
package: core @ionic/core package type: bug a confirmed bug report

Comments

@aeharding
Copy link
Contributor

Prerequisites

Ionic Framework Version

v7.x

Current Behavior

Tried to upgrade to 7.8.1/8.0.0-beta.3, notice the following:

image

Expected Behavior

autocapitalize is optional

Steps to Reproduce

Click repro see type error

Code Reproduction URL

https://stackblitz.com/edit/naskdu?file=src%2FApp.tsx,src%2Fmain.tsx

Ionic Info

N/A

Additional Information

No response

@liamdebeasi
Copy link
Contributor

liamdebeasi commented Mar 21, 2024

Thanks for the report. This was an attempt to add autocapitalize in a backwards compatible way (since autocapitalize is enabled by default on iOS), but looks like we need to do extra work to make this possible. I'll work on a fix.

As a workaround you can add autocapitalize="off" (or other supported keyword) to the searchbar.

@liamdebeasi
Copy link
Contributor

Here's a dev build with a proposed fix if you are interested in testing: 7.8.2-dev.11711027016.13b2a920

github-merge-queue bot pushed a commit that referenced this issue Mar 21, 2024
Issue number: resolves #29193

---------

<!-- 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. -->

In an attempt to preserve backwards compatibility when adding
`autocapitalize` to Searchbar, we used `!` to indicate that the prop was
never undefined. The `autocapitalize` on `HTMLElement` expects this
value to be a string and never undefined.

For the purposes of the property on Searchbar, setting this prop to one
of the accepted values would constitute a breaking change because it
would override the default browser behavior (which we previously relied
upon). As a result, we used `!` to not set a default prop but inform
TypeScript that this prop is always defined. This unintentionally made
it so developers needed to define the `autocapitalize` property every
time which is not what we want.

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

- `autocapitalize` now defaults to the `'default'` keyword. This is an
internal keyword that is used to tell Ionic to **not** set the
`autocapitalize` attribute on the inner `input` element and instead rely
on the default browser behavior. This satisfies the `HTMLElement`
requirement that `autocapitalize` is never undefined. In Ionic 8 this
`'default'` value will be replaced with `'off'`.

[Typescript currently sets the `HTMLElement` `autocapitalize` type to
`string`](https://github.com/microsoft/TypeScript/blob/65812bf3ec3b9208141ef46e43d146a2eef88ae5/src/lib/dom.generated.d.ts#L10087)
which is why we can add a `'default'` keyword here. There is some risk
that if these type definitions change in the future that applications
may encounter errors. However, changing this on the TypeScript side
would itself be a breaking change. Additionally, we are moving away from
`'default'` in Ionic 8, so I think this is an acceptable amount of risk.

## Does this introduce a breaking change?

- [ ] Yes
- [x] No

<!--
  If this introduces a breaking change:
1. Describe the impact and migration path for existing applications
below.
  2. Update the BREAKING.md file with the breaking change.
3. Add "BREAKING CHANGE: [...]" to the commit description when merging.
See
https://github.com/ionic-team/ionic-framework/blob/main/.github/CONTRIBUTING.md#footer
for more information.
-->


## Other information

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


Dev build: `7.8.2-dev.11711027016.13b2a920`

Tested in a React starter app with Searchbar, and I verified this fix
works.
@liamdebeasi
Copy link
Contributor

Thanks for the issue. This has been resolved via #29197, and a fix will be available in an upcoming release of Ionic Framework. Feel free to keep testing the dev build, and let me know if you have any questions.

Copy link

ionitron-bot bot commented Apr 20, 2024

Thanks for the issue! This issue is being locked to prevent comments that are not relevant to the original issue. If this is still an issue with the latest version of Ionic, please create a new issue and ensure the template is fully filled out.

@ionitron-bot ionitron-bot bot locked and limited conversation to collaborators Apr 20, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
package: core @ionic/core package type: bug a confirmed bug report
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants