Skip to content

Commit b90f24e

Browse files
committed
MOBILE-4842 chore: Migrate complex ContentChild
1 parent b5ef95e commit b90f24e

File tree

2 files changed

+21
-22
lines changed

2 files changed

+21
-22
lines changed
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
<ng-content />
2-
@if (!this.ionInput) {
3-
<ion-input-password-toggle slot="end" showIcon="fas-eye" hideIcon="fas-eye-slash" />
2+
@if (!ionInput()) {
3+
<ion-input-password-toggle slot="end" />
44
}

src/core/components/show-password/show-password.ts

Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15-
import { Component, AfterViewInit, Input, ContentChild, ViewEncapsulation } from '@angular/core';
15+
import { Component, ViewEncapsulation, input, contentChild, effect } from '@angular/core';
1616
import { IonInput } from '@ionic/angular';
1717
import { convertTextToHTMLElement } from '@/core/utils/create-html-element';
1818

@@ -51,43 +51,42 @@ import { CoreBaseModule } from '@/core/base.module';
5151
encapsulation: ViewEncapsulation.None,
5252
imports: [CoreBaseModule],
5353
})
54-
export class CoreShowPasswordComponent implements AfterViewInit {
54+
export class CoreShowPasswordComponent {
5555

5656
/**
5757
* @deprecated since 4.5. Not used anymore.
5858
*/
59-
@Input() initialShown = '';
59+
readonly initialShown = input('');
6060

6161
/**
6262
* @deprecated since 4.4. Not used anymore.
6363
*/
64-
@Input() name = '';
64+
readonly name = input('');
6565

6666
/**
6767
* @deprecated since 4.4. Use slotted solution instead.
6868
*/
69-
@ContentChild(IonInput) ionInput?: IonInput | HTMLIonInputElement;
69+
readonly ionInput = contentChild<IonInput | HTMLIonInputElement>(IonInput);
7070

71-
/**
72-
* @inheritdoc
73-
*/
74-
async ngAfterViewInit(): Promise<void> {
71+
constructor() {
7572
CoreLogger.getInstance('CoreShowPasswordComponent')
7673
.warn('Deprecated component, use <ion-input-password-toggle /> instead.');
7774

78-
// eslint-disable-next-line @typescript-eslint/no-deprecated
79-
if (!this.ionInput) {
80-
return;
81-
}
75+
effect(async () => {
76+
// eslint-disable-next-line @typescript-eslint/no-deprecated
77+
const ionInput = this.ionInput();
78+
if (!ionInput) {
79+
return;
80+
}
8281

83-
// eslint-disable-next-line @typescript-eslint/no-deprecated
84-
const input = await CorePromiseUtils.ignoreErrors(this.ionInput.getInputElement());
85-
if (!input) {
86-
return;
87-
}
82+
const input = await CorePromiseUtils.ignoreErrors(ionInput.getInputElement());
83+
if (!input) {
84+
return;
85+
}
8886

89-
const toggle = convertTextToHTMLElement('<ion-input-password-toggle slot="end" />');
90-
input.parentElement?.appendChild(toggle.children[0]);
87+
const toggle = convertTextToHTMLElement('<ion-input-password-toggle slot="end" />');
88+
input.parentElement?.appendChild(toggle.children[0]);
89+
});
9190
}
9291

9392
}

0 commit comments

Comments
 (0)