-
Notifications
You must be signed in to change notification settings - Fork 13.5k
bug: aria-label/label cause undesired changes on ionic components #27236
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
Comments
Thanks for the report. There are a few issues here:
Here is the correct syntax: <ion-input label="Name" label-placement="floating"></ion-input> (I omitted the other attributes for brevity)
This is the same issue as 2 but with <ion-select label="Gender" label-placement="floating">...</ion-select>
Making the changes in step 3 fixes the issue. |
Our documentation also has more examples on how to migrate: https://ionicframework.com/docs/api/input#migrating-from-legacy-input-syntax |
If you expand the window you will see that I have another set of labels on the other ion-cols for wider screen. How can I make your solution applied to this case? (And also, note that the labels have red '*' to indicate for user that it's required, how can I apply that to 'label' property?) |
Here I tried your solution: https://stackblitz.com/edit/3we1ad-ox58un?file=index.html You can see that it still does not solve my problem entirely. When size of window is more than sm, the labels will be doubled. And the red '*' cannot be shown on those built-in label from 'label' property. |
This isn't something you should be doing. The reason is that screen readers (like VoiceOver and TalkBack) are unable to associate the label with the form control which makes for a confusing experience for people who are using assistive technology. It looks like what you are trying to do is make sure the labels/inputs are all lined up consistently. In that case, I recommend using
Inputs don't have support for custom HTML at the moment, but you can do something like this: ion-input.custom-input .label-text::after {
content: "*";
color: red;
} |
Yes, partly, but not just that. I also want to make it floating when the screen is smaller to make it more user friendly and responsive.
how to apply this to ion-select too? I tried it here, but you can see the ion-select is not receiving that: https://stackblitz.com/edit/3we1ad-kzmne4?file=index.html |
You can update the
You can't apply this to |
Okay, that feature request seems to be what I need. Does ion-input has this feature request as well? And a quote from that thread:
Are you implying that we shouldn't use ion-item wrapping each form control anymore? |
It does not.
No. The change we made in Ionic 7 was to remove the requirement that developers must use |
Oh, okay. I think that's fair enough. I would rather not use ion-item if it's not necessary. But I do like to keep the 'grey line' (when idle, no focus) on each form control like the original I have shown. (it resemble the underline for user to fill in like in paper form) And the ripple effect is what I find interesting for those form control under ion-item which I would like to keep also. (as you can see, I customized the css for those) Do you have any suggestion to achieve that without ion-item wrapping each form control ? |
For the gray line you could add a ion-input {
border-bottom: 1px solid #aaa;
} It might be interesting to have this "underline" behavior as a built-in feature for For the ripple effect, you can use <div class="ion-activatable wrapper">
<ion-toggle>toggle</ion-toggle>
<ion-ripple-effect></ion-ripple-effect>
</div> Here are some examples: https://codepen.io/liamdebeasi/pen/rNqMQev |
@Wasenshi123 Does this address part of your issue? #26838 (comment) (see code in comment) |
Thank you, I will have to try that. But I think the solution/workaround is too much of an extra code involved. So for the time being, I would rather wait for ionic update and your feature request and some other to come in. Only then I will start implement this whole new syntax. Until then, I will keep using old structure and code for now. That's my current solution. |
Thanks for the additional info. Sounds like there are a few requests: 1. An easy way of adding a bottom border on 2. A way to add the ripple effect to components when not used in 3. A way to pass custom HTML to input and textarea I am going to close this in favor of #27239 and #27061, but let me know if you have questions. |
@liamdebeasi I have a few questions: first, regarding how to apply this custom css inside a component for ionic-angular project
I try to set custom css for any child components of ion-input but seems like it doesn't work at all. (including .native-input, .label-text-wrapper, to name some) second, do you know why Material says that there shouldn't be highlight for input used in item/list?
And is it possible for me to have highlight for input inside ion-item? and should I? (I still have some form controls that need to be inside list/ion-item because it's a list apparently.) |
Your selector is incorrect. It should be
The Material Design specification doesn't provide guidance as to why, but if you compare with stock Android apps you should see that inputs in a list do not receive the highlight (Such as the "Create Event" modal in Google Calendar)
|
https://github.com/Wasenshi123/Ionic7 Well, I have updated my code in this repo to showcase what I mean regarding custom css for ion-input. The code is in home component. As you can see, it's like the css never existed. |
Your component has Angular's style encapsulation enabled, so your CSS is compiled to: .required[_ngcontent-nhh-c86] .label-text[_ngcontent-nhh-c86]::after {
content: "*";
color: red;
} The |
I see, thank you. I guess I will move it to global.scss then.. When should I disable style scoping for a component? what is the best practice about this? |
Style scoping/view encapsulation is an Angular feature, so I recommend looking at their docs: https://angular.io/guide/view-encapsulation |
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 I upgraded to ionic 7, I noticed the warning in console about aria-label or label needed on various component (mainly, ion-input, ion-select, ion-textarea).
I have my own layout structure for look & responsive purpose, so I cannot just use "label" property. Thus, I tried to add aria-label instead.
But I found out that, after I added aria-label (or label property for that matter), the look and behavior of those components got changed.
namely:
Those structure and issues have been demonstrated here:
https://stackblitz.com/edit/3we1ad-cymjmo?file=index.html
Expected Behavior
The behavior and appearance of ion-input/ion-select/ion-textarea should not be altered after adding aria-label or label property.
Steps to Reproduce
Code Reproduction URL
https://stackblitz.com/edit/3we1ad-cymjmo?file=index.html
Ionic Info
Ionic:
Ionic CLI : 7.0.1 (C:\Users\User\AppData\Roaming\npm\node_modules@ionic\cli)
Ionic Framework : @ionic/angular 7.0.1
@angular-devkit/build-angular : 15.2.5
@angular-devkit/schematics : 10.1.7
@angular/cli : 15.2.5
@ionic/angular-toolkit : 9.0.0
Capacitor:
Capacitor CLI : 4.7.3
@capacitor/android : 4.7.3
@capacitor/core : 4.7.3
@capacitor/ios : 4.7.3
Utility:
cordova-res : not installed globally
native-run : 1.7.2
System:
NodeJS : v16.18.0 (C:\Program Files\nodejs\node.exe)
npm : 8.19.2
OS : Windows 10
Additional Information
No response
The text was updated successfully, but these errors were encountered: