MCPcopy Index your code
hub / github.com/ionic-team/ionic-framework / createTriggerController

Function createTriggerController

core/src/utils/overlays.ts:951–1000  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

949 * ```
950 */
951export const createTriggerController = () => {
952 let destroyTriggerInteraction: (() => void) | undefined;
953
954 /**
955 * Removes the click listener from the trigger element.
956 */
957 const removeClickListener = (): void => {
958 if (destroyTriggerInteraction) {
959 destroyTriggerInteraction();
960 destroyTriggerInteraction = undefined;
961 }
962 };
963
964 /**
965 * Adds a click listener to the trigger element.
966 * Presents the overlay when the trigger is clicked.
967 * @param el The overlay element.
968 * @param trigger The ID of the element to add a click listener to.
969 */
970 const addClickListener = (el: HTMLIonOverlayElement, trigger: string): void => {
971 removeClickListener();
972
973 const triggerEl = trigger !== undefined ? document.getElementById(trigger) : null;
974 if (!triggerEl) {
975 printIonWarning(
976 `[${el.tagName.toLowerCase()}] - A trigger element with the ID "${trigger}" was not found in the DOM. The trigger element must be in the DOM when the "trigger" property is set on an overlay component.`,
977 el
978 );
979 return;
980 }
981
982 const configureTriggerInteraction = (targetEl: HTMLElement, overlayEl: HTMLIonOverlayElement) => {
983 const openOverlay = () => {
984 overlayEl.present();
985 };
986 targetEl.addEventListener('click', openOverlay);
987
988 return () => {
989 targetEl.removeEventListener('click', openOverlay);
990 };
991 };
992
993 destroyTriggerInteraction = configureTriggerInteraction(triggerEl, el);
994 };
995
996 return {
997 addClickListener,
998 removeClickListener,
999 };
1000};
1001
1002export const FOCUS_TRAP_DISABLE_CLASS = 'ion-disable-focus-trap';

Callers 6

AlertClass · 0.90
ActionSheetClass · 0.90
LoadingClass · 0.90
PickerClass · 0.90
ModalClass · 0.90
ToastClass · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected