mirror of
https://github.com/ionic-team/ionic-framework.git
synced 2025-11-09 08:09:32 +08:00
feat(modal, popover): add ability to temporarily disable focus trapping (#29379)
Issue number: resolves #24646
This commit is contained in:
@ -16,6 +16,7 @@ import {
|
||||
present,
|
||||
createTriggerController,
|
||||
setOverlayId,
|
||||
FOCUS_TRAP_DISABLE_CLASS,
|
||||
} from '@utils/overlays';
|
||||
import { getClassMap } from '@utils/theme';
|
||||
import { deepReady, waitForMount } from '@utils/transition';
|
||||
@ -257,6 +258,25 @@ export class Modal implements ComponentInterface, OverlayInterface {
|
||||
*/
|
||||
@Prop() keepContentsMounted = false;
|
||||
|
||||
/**
|
||||
* If `true`, focus will not be allowed to move outside of this overlay.
|
||||
* If `false`, focus will be allowed to move outside of the overlay.
|
||||
*
|
||||
* In most scenarios this property should remain set to `true`. Setting
|
||||
* this property to `false` can cause severe accessibility issues as users
|
||||
* relying on assistive technologies may be able to move focus into
|
||||
* a confusing state. We recommend only setting this to `false` when
|
||||
* absolutely necessary.
|
||||
*
|
||||
* Developers may want to consider disabling focus trapping if this
|
||||
* overlay presents a non-Ionic overlay from a 3rd party library.
|
||||
* Developers would disable focus trapping on the Ionic overlay
|
||||
* when presenting the 3rd party overlay and then re-enable
|
||||
* focus trapping when dismissing the 3rd party overlay and moving
|
||||
* focus back to the Ionic overlay.
|
||||
*/
|
||||
@Prop() focusTrap = true;
|
||||
|
||||
/**
|
||||
* Determines whether or not a modal can dismiss
|
||||
* when calling the `dismiss` method.
|
||||
@ -905,7 +925,8 @@ export class Modal implements ComponentInterface, OverlayInterface {
|
||||
};
|
||||
|
||||
render() {
|
||||
const { handle, isSheetModal, presentingElement, htmlAttributes, handleBehavior, inheritedAttributes } = this;
|
||||
const { handle, isSheetModal, presentingElement, htmlAttributes, handleBehavior, inheritedAttributes, focusTrap } =
|
||||
this;
|
||||
|
||||
const showHandle = handle !== false && isSheetModal;
|
||||
const mode = getIonMode(this);
|
||||
@ -926,6 +947,7 @@ export class Modal implements ComponentInterface, OverlayInterface {
|
||||
[`modal-card`]: isCardModal,
|
||||
[`modal-sheet`]: isSheetModal,
|
||||
'overlay-hidden': true,
|
||||
[FOCUS_TRAP_DISABLE_CLASS]: focusTrap === false,
|
||||
...getClassMap(this.cssClass),
|
||||
}}
|
||||
onIonBackdropTap={this.onBackdropTap}
|
||||
|
||||
Reference in New Issue
Block a user