Repository navigation
Description
Prerequisites
- I have read the Contributing Guidelines.
- I agree to follow the Code of Conduct.
- I have searched for existing issues that already report this problem, without success.
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:
- all: line is not highlighted anymore( when the component got focus)
- ion-input: placeholder gets shown all the time (previously, will only be shown when the component gets focus)
- ion-select: the arrow of the select box is not at the end of component and no transition animation
- ion-select: Header in alert interface is not shown anymore
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
- Wrap ion-input or ion-select or ion-textarea in ion-item
- Add aria-label or label property
- Behavior get altered
Code Reproduction URL
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
Activity
liamdebeasi commentedon Apr 19, 2023
Thanks for the report. There are a few issues here:
Inputs do not receive the blue highlight line.
Inputs inside of
ion-itemno longer receive the blue highlight. This was done to match the Material Design spec. Inputs used outside ofion-itemcontinue to receive the blue highlight.Placeholder is always show on the input
This is happening because you did not migrate your input correctly. The warning states that you should use the
labelproperty onion-inputfor visible text and removeion-label. However, you usedaria-labelwhich should be used if you do not have visible text. When migrating to the new syntax,ion-inputignores theion-labelwhich is why the unexpected behavior is happening.Here is the correct syntax:
(I omitted the other attributes for brevity)
This is the same issue as 2 but with
ion-select. Here is the correct syntax:Making the changes in step 3 fixes the issue.
liamdebeasi commentedon Apr 19, 2023
Our documentation also has more examples on how to migrate: https://ionicframework.com/docs/api/input#migrating-from-legacy-input-syntax
Wasenshi123 commentedon Apr 19, 2023
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?)
Wasenshi123 commentedon Apr 19, 2023
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.
liamdebeasi commentedon Apr 19, 2023
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
label-placement="fixed"which gives labels a fixed width.Inputs don't have support for custom HTML at the moment, but you can do something like this:
Wasenshi123 commentedon Apr 19, 2023
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
12 remaining items
lincolnthree commentedon Apr 20, 2023
@Wasenshi123 Does this address part of your issue? #26838 (comment) (see code in comment)
Wasenshi123 commentedon Apr 20, 2023
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.
liamdebeasi commentedon Apr 21, 2023
Thanks for the additional info. Sounds like there are a few requests:
1. An easy way of adding a bottom border on
ion-inputThis is tracked in #27239
2. A way to add the ripple effect to components when not used in
ion-itemOur recommended solution is to use
ion-ripple-effectdirectly. I provided a code sample in #27239.3. A way to pass custom HTML to input and textarea
This is tracked in #27061.
I am going to close this in favor of #27239 and #27061, but let me know if you have questions.
Wasenshi123 commentedon Apr 25, 2023
@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.)
liamdebeasi commentedon Apr 25, 2023
Your selector is incorrect. It should be
ion-input.custom-input .label-text::after(note I removed the space between.andcustom-input). If that still does not work, then I would check with browser dev tools to see if the styles are being overridden.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)
ion-inputdoes not use the Shadow DOM so you could probably add the styles yourself, though you should not do this if you want to align with the Material Design specification.Wasenshi123 commentedon Apr 25, 2023
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.
liamdebeasi commentedon Apr 25, 2023
Your component has Angular's style encapsulation enabled, so your CSS is compiled to:
The
.label-textelement is insideion-inputand never receives that__ngcontentscoping so the CSS never matches. You can either disable style scoping or move this specific block of CSS to a global stylesheet such asglobal.scssWasenshi123 commentedon Apr 25, 2023
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?
liamdebeasi commentedon Apr 25, 2023
Style scoping/view encapsulation is an Angular feature, so I recommend looking at their docs: https://angular.io/guide/view-encapsulation
ionitron-bot commentedon May 25, 2023
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.