-
Notifications
You must be signed in to change notification settings - Fork 13.5k
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: ion-input changes HTML structure on visibility change #27597
Comments
@muuvmuuv thanks for reporting this issue! I am able to reproduce this issue. This happens due to this property binding:
When the control is re-rendered from the toggle, Ionic parses the attributes to see if there is an In your example, is there a reason you cannot use a static binding? <ion-input aria-labelledby="label"></ion-input> |
Yeah, because the hole form is coming as a config from the backend so too many variables for a static ID. Does that also behaves the same for aria-label? Or could I hack a re-render for ion-input? |
I tested a bit with <ion-item [class.mandatory]="control.required" form-element>
<div class="label-group">
<ion-label [hidden]="field.hideLabel" position="stacked" [id]="field.htmlId + '-label'">
{{ field.name | localize }}{{ control.required ? "*" : "" }}
</ion-label>
<div
class="save-contact"
(click)="form.promptSaveContact(field)"
*ngIf="
!isWeb &&
(field.bcRelation === 'person_email' ||
field.bcRelation === 'person_mobile' ||
field.bcRelation === 'person_phone') &&
(control.value || (control.valueChanges | async))
"
>
<fa-icon name="address-book"></fa-icon>
</div>
</div>
<ion-input
[autocapitalize]="'on'"
[autocorrect]="'on'"
[class.no-label]="field.hideLabel"
[clearInput]="true"
[attr.aria-label]="field.name | localize"
[attr.aria-labelledby]="field.htmlId + '-label'"
[legacy]="true"
[formControl]="control"
[id]="field.htmlId"
[maxlength]="254"
[type]="field.inputType"
></ion-input>
</ion-item> We would have to change our hole form UI to get something like this to work, but unfortunately I cannot style the new labels or cannot consistently across ion-input and the others. IMO, This is far from being ready and warnings should be limited. |
Ok, I finally found a working workaround. <ion-label [attr.id]="option.id + '-label'" id="label-fix">
<h3 [innerHTML]="asset.values.name | localize | safeHtml"></h3>
<p [innerHTML]="asset.values.description | localize | safeHtml"></p>
</ion-label>
<ion-checkbox
(ionChange)="toggle(option.id)"
[checked]="values[option.id]"
[attr.aria-labelledby]="option.id + '-label'"
aria-labelledby="label-fix"
slot="end"
></ion-checkbox> Normaly the browser and other tools would report errors if ID's occur multiple times, but since Angular overrides them later on with |
Can you clarify why you are unable to use the new form syntax? |
Since #27061 is closed I must revisit, but previously we were unable to put everything in the new label syntax for all form inputs. ion-checkbox and ion-option uses slots, so this was way easier. We primarily have stacked labels and add more stuff into the stacked section (see label-group). I am willed to refactor our inputs, but ion-input still has the problem that styling isn't that easy. |
Can you clarify what you are trying to do in |
All form controls (checkbox, radio, etc) allow for custom HTML to be passed in to the component. We also added Shadow Parts to It sounds like the root issue here is that there were blockers that prevented you from upgrading to the modern form syntax. Are there any remaining blockers after the v7.1 release? |
Not any longer, just tested and with a little effort all should be migrateable now. Thanks for the work in that on all that. Will follow the issue you mentioned which would perfectly fit to our need since we use labels on these a lot. |
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. |
Prerequisites
Ionic Framework Version
v7.x
Current Behavior
When using
ion-input
witharia-
-attribute it does work on first load, but if I toggle the visibility of that page or the element itself, it changes the HTML structure tolegacy-input
which breaks a lot of styling...Expected Behavior
Don't change the HTML structure.
Steps to Reproduce
Code Reproduction URL
https://stackblitz.com/edit/angular-unkh29?file=src%2Fapp%2Fexample.component.html
Ionic Info
See Stackblitz, it's forked from ion-input docs
Additional Information
No response
The text was updated successfully, but these errors were encountered: