From 668b2dac57f9b4ad4cda28f18c887cbf31aa95fb Mon Sep 17 00:00:00 2001 From: Brandy Carney Date: Tue, 1 Oct 2024 14:27:03 -0400 Subject: [PATCH] docs(app): add setFocus to the documentation (#29916) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Issue number: resolves #29830 --------- ## What is the current behavior? The `setFocus` method on `ion-app` is marked internal. ## What is the new behavior? Document the `setFocus` method as a way for developers to programmatically focus elements. ## Does this introduce a breaking change? - [ ] Yes - [x] No ## Other information The method isn’t new, it was just marked as internal, which prevented it from being documented. I can mark this as a `feat` though if anyone thinks it should be. Related documentation PR: https://github.com/ionic-team/ionic-docs/pull/3842 --- core/api.txt | 1 + core/src/components.d.ts | 3 +++ core/src/components/app/app.tsx | 1 - packages/angular/src/directives/proxies.ts | 1 + packages/angular/standalone/src/directives/proxies.ts | 3 ++- 5 files changed, 7 insertions(+), 2 deletions(-) diff --git a/core/api.txt b/core/api.txt index 9c620e0c085..bd0490e45fc 100644 --- a/core/api.txt +++ b/core/api.txt @@ -143,6 +143,7 @@ ion-alert,css-prop,--width,ios ion-alert,css-prop,--width,md ion-app,none +ion-app,method,setFocus,setFocus(elements: HTMLElement[]) => Promise ion-avatar,shadow ion-avatar,css-prop,--border-radius,ios diff --git a/core/src/components.d.ts b/core/src/components.d.ts index 7c725cf2c89..db9530b3404 100644 --- a/core/src/components.d.ts +++ b/core/src/components.d.ts @@ -304,6 +304,9 @@ export namespace Components { "trigger": string | undefined; } interface IonApp { + /** + * Used to set focus on an element that uses `ion-focusable`. Do not use this if focusing the element as a result of a keyboard event as the focus utility should handle this for us. This method should be used when we want to programmatically focus an element as a result of another user action. (Ex: We focus the first element inside of a popover when the user presents it, but the popover is not always presented as a result of keyboard action.) + */ "setFocus": (elements: HTMLElement[]) => Promise; } interface IonAvatar { diff --git a/core/src/components/app/app.tsx b/core/src/components/app/app.tsx index d38b0bd37a3..fadfed3f04b 100644 --- a/core/src/components/app/app.tsx +++ b/core/src/components/app/app.tsx @@ -61,7 +61,6 @@ export class App implements ComponentInterface { } /** - * @internal * Used to set focus on an element that uses `ion-focusable`. * Do not use this if focusing the element as a result of a keyboard * event as the focus utility should handle this for us. This method diff --git a/packages/angular/src/directives/proxies.ts b/packages/angular/src/directives/proxies.ts index f448236a161..0f10c6bb5b5 100644 --- a/packages/angular/src/directives/proxies.ts +++ b/packages/angular/src/directives/proxies.ts @@ -188,6 +188,7 @@ Shorthand for ionAlertDidDismiss. @ProxyCmp({ + methods: ['setFocus'] }) @Component({ selector: 'ion-app', diff --git a/packages/angular/standalone/src/directives/proxies.ts b/packages/angular/standalone/src/directives/proxies.ts index c84717dfd1c..bc90bec4d03 100644 --- a/packages/angular/standalone/src/directives/proxies.ts +++ b/packages/angular/standalone/src/directives/proxies.ts @@ -266,7 +266,8 @@ Shorthand for ionAlertDidDismiss. @ProxyCmp({ - defineCustomElementFn: defineIonApp + defineCustomElementFn: defineIonApp, + methods: ['setFocus'] }) @Component({ selector: 'ion-app',