fix(searchbar): autocapitalize is initialized correctly #29197
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Issue number: resolves #29193
What is the current behavior?
In an attempt to preserve backwards compatibility when adding
autocapitalize
to Searchbar, we used!
to indicate that the prop was never undefined. Theautocapitalize
onHTMLElement
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 theautocapitalize
property every time which is not what we want.What is the new behavior?
autocapitalize
now defaults to the'default'
keyword. This is an internal keyword that is used to tell Ionic to not set theautocapitalize
attribute on the innerinput
element and instead rely on the default browser behavior. This satisfies theHTMLElement
requirement thatautocapitalize
is never undefined. In Ionic 8 this'default'
value will be replaced with'off'
.Typescript currently sets the
HTMLElement
autocapitalize
type tostring
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?
Other information
Dev build:
7.8.2-dev.11711027016.13b2a920
Tested in a React starter app with Searchbar, and I verified this fix works.