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
Upgraded to IONIC 7 RC a couple of day ago. I got all of the warnings about the ion label being deprected and needing to replace with label="something" labelPlacement="stacked" etc...
I have a reusable component in which i am passing the label via attribute like so:
<app-frequency-select controlName="medfrequency" label="When will this be taken?" [required]="true"></app-frequency-select>
Inside the component you see i'm trying to pass an input to customize the value of the select.
HTML:
<ion-item>
<ion-select
required
[label]="label"
labelPlacement="stacked"
#frequencySelect
[formControlName]="controlName"
placeholder="Please Select"
>
<ion-select-option [value]="f.frequencyid" *ngFor="let f of frequencies">{{ f.frequency }}</ion-select-option>
</ion-select>
</ion-item>
component.ts:
@Component({
selector: 'app-frequency-select',
standalone: true,
templateUrl: './frequency-select.component.html',
styleUrls: ['./frequency-select.component.scss'],
imports: [CommonModule, IonicModule, FormsModule, ReactiveFormsModule, RequiredDirective, SelectLabelFixDirective],
viewProviders: [
{
provide: ControlContainer,
useFactory: (container: ControlContainer) => container,
deps: [[new SkipSelf(), ControlContainer]]
}
]
})
export class FrequencySelectComponent {
@ViewChild('frequencySelect') fs: IonSelect;
@Input() label: string;
@Input() required: boolean = false;
@Input() controlName: string;
frequencies: any[] = [];
disabled: boolean;
constructor(private _referenceService: ReferenceService) {}
async ngOnInit() {
await this.buildReferences();
console.log('The label for FS:', this.label); //this is coming through just fine..
}
async buildReferences() {
const t = setTimeout(async () => {
this.frequencies = await lastValueFrom(this._referenceService.getFrequencies());
clearTimeout(t);
}, 1000);
}
}
As you can see in my comment the label comes through just fine but when i try to render it into [label]="label"
it does not work. No label gets rendered.
I am forced for the time being to put static text like label="something" which works.
Expected Behavior
I should be able to pass a string to the label in my reusable component and the [label] attribute render the text that I have sent as an @input() label;
Steps to Reproduce
Create and input and try passing dynamic text to the label with brackets like so
<ion-input [label]="somevariableforlabel"></ion-input>
in the component file:
public somevariableforlabel = 'My label';
Code Reproduction URL
No response
Ionic Info
Ionic:
Ionic CLI : 7.0.0 (/Users/abcd/.nvm/versions/node/v16.18.0/lib/node_modules/@ionic/cli)
Ionic Framework : not installed
@angular-devkit/build-angular : 15.2.4
@angular-devkit/schematics : 15.2.4
@angular/cli : 15.2.4
@ionic/angular-toolkit : 6.1.0
Capacitor:
Capacitor CLI : 4.6.1
@capacitor/android : 4.6.1
@capacitor/core : 4.6.1
@capacitor/ios : 4.6.1
Utility:
cordova-res : 0.15.4
native-run (update available: 1.7.2) : 1.7.1
System:
NodeJS : v16.18.0 (/Users/abcd/.nvm/versions/node/v16.18.0/bin/node)
npm : 9.6.2
OS : macOS Unknown
Additional Information
Let me know if you need anymore information. Thank you.
Activity
[-]bug: [/-][+]bug: Cannot pass dynamic label to ion-input[/+]judsonmusic commentedon Apr 2, 2023
I have created a stackblitz to show the issue on both parent and child:


https://stackblitz.com/edit/ionic7-label-test?file=src/app/app.component.ts
Notice initially it might work with dynamic label but change some label text in the ts files and it breaks.
Also despite having the correct [label] attr. getting this in the console:
However you can see my code is correct:
If i refresh the page they seem to work, but they do not work in my application when entering into new views etc.
JustinPierce commentedon Apr 3, 2023
I would add that I have noticed this behavior with any Ionic component that I've tried to set a dynamic label on, and not just
<ion-input>. All of our labels are run through an i18n package, so dynamic labels are non-negotiable for us.muuvmuuv commentedon Apr 4, 2023
Also noticed that the shadow-root changes on navigation/re-hydration. Our label just prints fine but when navigating its gone. And we do not use the
[legacy]="true"attr.[-]bug: Cannot pass dynamic label to ion-input[/-][+]bug: v7, cannot pass dynamic label to form controls[/+]Julien-Marcou commentedon Apr 10, 2023
I made a reproduction repository which demonstrates the bug when using
translocoto translate input labels inside a modal:https://github.com/Julien-Marcou/ionic-issue-27085
The first time the modal opens:
And the second time the modal opens:
Julien-Marcou commentedon Apr 10, 2023
Btw, I just found another problem after the second modal opening 😅
The
<ion-input>"focus" state is not the same (there is a colored underline that is not present after the initial opening):Record.2023-04-10.184247.mp4
sean-perkins commentedon Apr 10, 2023
Hello everyone, thanks for the reproductions and conversation around this issue.
Can someone test with this dev-build and let me know if the problem persists or if new issues are observed:
For example, installing for an Angular project:
Thanks!
Julien-Marcou commentedon Apr 10, 2023
I can confirm it fixes the problem for me 🚀
sean-perkins commentedon Apr 10, 2023
Thank you!
Here is the latest/most up-to-date dev-build:
I still need to get a team review, but the end result changes here is that we are trying to default to the modern syntax instead of the legacy syntax.
Developers can still get the legacy UI by either doing:
or by assigning the
legacy="true"property on the control directly:Implementations that are similar to:
will be force updated to the modern syntax. It is the only discovered way that I can maintain the modern syntax in a scenario where a label is initially unset, but later has a value (translations, shared components, etc.)
ceotrammell commentedon Apr 16, 2023
Can confirm as well for @ionic/angular that @ionic/angular@^7.0.2-dev.11681157690.1060bc7f fixed this issue!
Thank you :)
fleboulch commentedon Apr 17, 2023
The dev build fixed also the issue for me 🎉
sean-perkins commentedon Apr 17, 2023
The fix for this issue is queued to be merged and will be available in this week's release
v7.0.3. Thank you everyone for reporting the issue + helping validate the fix 🎉fix(many): dynamic label support for modern form controls (#27156)
fix(many): dynamic label support for modern form controls (#27156)
ceotrammell commentedon Apr 20, 2023
I am unsure if this correlates or not but before I did not have this issue...
In ionic 6 angular, the below worked:
In ionic 7.0.3 angular, the first 'LABEL' translation does not seem to work, it gives me a warning and does not show the label:
I am unsure if this is strictly component related or not but I have seen it mainly happen in components but it is random it seems. I am using '@ngx-translate/core ^14.0.0 via:
import { TranslateModule } from '@ngx-translate/core';The fix for me is to not pipe a translation on the first ion item label and it works and then the rest of the page is fine to allow translation pipes. But this could be annoying for someone who has a wider language base instead of just EN.
ionic info:
EinfachHans commentedon Apr 20, 2023
@ceotrammell your ionic info says you have
7.0.2installed. Make sure to install7.0.3correctly than it should work!ceotrammell commentedon Apr 20, 2023
@EinfachHans GOOD CATCH! I forgot to push my tests to .3 after 7.0.2-dev.11681157690.1060bc7f!
Silly me. All is back to normal.
ionitron-bot commentedon May 20, 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.