@@ -253,6 +253,27 @@ export class ActionSheet implements ComponentInterface, OverlayInterface {
253253 return eventMethod ( this . el , 'ionActionSheetWillDismiss' ) ;
254254 }
255255
256+ private focusFirstElement ( ) {
257+ if ( ! this . wrapperEl ) return ; // Check if wrapperEl is defined
258+ const firstFocusable = this . wrapperEl ?. querySelector (
259+ 'button, [href], input, select, textarea, [tabindex]:not([tabindex="-1"])'
260+ ) ;
261+ if ( firstFocusable ) {
262+ ( firstFocusable as HTMLElement ) . focus ( ) ;
263+ }
264+ }
265+
266+ // Method to focus the last focusable element
267+ private focusLastElement ( ) {
268+ if ( ! this . wrapperEl ) return ; // Check if wrapperEl is defined
269+ const focusableElements = this . wrapperEl . querySelectorAll (
270+ 'button, [href], input, select, textarea, [tabindex]:not([tabindex="-1"])'
271+ ) ;
272+ if ( focusableElements . length > 0 ) {
273+ ( focusableElements [ focusableElements . length - 1 ] as HTMLElement ) . focus ( ) ;
274+ }
275+ }
276+
256277 private async buttonClick ( button : ActionSheetButton ) {
257278 const role = button . role ;
258279 if ( isCancel ( role ) ) {
@@ -385,7 +406,7 @@ export class ActionSheet implements ComponentInterface, OverlayInterface {
385406 >
386407 < ion-backdrop tappable = { this . backdropDismiss } />
387408
388- < div tabindex = "0" > </ div >
409+ < div tabindex = "0" aria-hidden = "true" onFocus = { ( ) => this . focusLastElement ( ) } > </ div >
389410
390411 < div class = "action-sheet-wrapper ion-overlay-wrapper" ref = { ( el ) => ( this . wrapperEl = el ) } >
391412 < div class = "action-sheet-container" >
@@ -446,7 +467,7 @@ export class ActionSheet implements ComponentInterface, OverlayInterface {
446467 </ div >
447468 </ div >
448469
449- < div tabindex = "0" > </ div >
470+ < div tabindex = "0" aria-hidden = "true" onFocus = { ( ) => this . focusFirstElement ( ) } > </ div >
450471 </ Host >
451472 ) ;
452473 }
0 commit comments