-
Notifications
You must be signed in to change notification settings - Fork 3.1k
docs(modal): playground example to prevent swipe to dismiss #2820
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
d81a5b5
docs(modal): playground example to prevent swipe to dismiss
sean-perkins 7038409
chore: v6 example and updates
sean-perkins fb49046
chore: update description for v6
sean-perkins cc336b0
fix: rework vue examples to use composition API
sean-perkins 1d1915b
fix: simplify angular example
sean-perkins f41855c
fix: use function name reference for event handlers in vue examples
sean-perkins c6008ca
chore: simplify vue examples
sean-perkins ab8717b
chore: simplify react examples
sean-perkins 24a5691
chore: limit to iOS mode
sean-perkins ad814d7
revert: react example presenting element
sean-perkins File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
...e/v6/modal/can-dismiss/prevent-swipe-to-close/angular/example_component_html.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
```html | ||
<div class="ion-page" #page> | ||
<ion-header> | ||
<ion-toolbar> | ||
<ion-title>App</ion-title> | ||
</ion-toolbar> | ||
</ion-header> | ||
<ion-content class="ion-padding"> | ||
<ion-button id="open-modal" expand="block">Open</ion-button> | ||
<ion-modal #modal trigger="open-modal" [canDismiss]="canDismiss" [presentingElement]="page"> | ||
<ng-template> | ||
<ion-header> | ||
<ion-toolbar> | ||
<ion-title>Modal</ion-title> | ||
<ion-buttons slot="end"> | ||
<ion-button (click)="modal.dismiss()">Close</ion-button> | ||
</ion-buttons> | ||
</ion-toolbar> | ||
</ion-header> | ||
<ion-content class="ion-padding"> | ||
<p> | ||
To close this modal, please use the "Close" button provided. Note that swiping the modal will not dismiss | ||
it. | ||
</p> | ||
</ion-content> | ||
</ng-template> | ||
</ion-modal> | ||
</ion-content> | ||
</div> | ||
``` |
13 changes: 13 additions & 0 deletions
13
...age/v6/modal/can-dismiss/prevent-swipe-to-close/angular/example_component_ts.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
```ts | ||
import { Component } from '@angular/core'; | ||
|
||
@Component({ | ||
selector: 'app-example', | ||
templateUrl: 'example.component.html', | ||
}) | ||
export class ExampleComponent { | ||
async canDismiss(data?: any, role?: string) { | ||
return role !== 'gesture'; | ||
} | ||
} | ||
``` |
57 changes: 57 additions & 0 deletions
57
static/usage/v6/modal/can-dismiss/prevent-swipe-to-close/demo.html
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
|
||
<head> | ||
<meta charset="UTF-8" /> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> | ||
<title>Modal | Can Dismiss</title> | ||
<link rel="stylesheet" href="../../../../common.css" /> | ||
<script src="../../../../common.js"></script> | ||
<script type="module" src="https://cdn.jsdelivr.net/npm/@ionic/core@6/dist/ionic/ionic.esm.js"></script> | ||
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@ionic/core@6/css/ionic.bundle.css" /> | ||
|
||
</head> | ||
|
||
<body> | ||
<ion-app> | ||
<div class="ion-page"> | ||
<ion-header> | ||
<ion-toolbar> | ||
<ion-title>App</ion-title> | ||
</ion-toolbar> | ||
</ion-header> | ||
<ion-content class="ion-padding"> | ||
<ion-button id="open-modal" expand="block">Open</ion-button> | ||
|
||
<ion-modal trigger="open-modal"> | ||
<ion-header> | ||
<ion-toolbar> | ||
<ion-title>Modal</ion-title> | ||
<ion-buttons slot="end"> | ||
<ion-button onclick="dismiss()">Close</ion-button> | ||
</ion-buttons> | ||
</ion-toolbar> | ||
</ion-header> | ||
<ion-content class="ion-padding"> | ||
<p>To close this modal, please use the "Close" button provided. Note that swiping the modal will not dismiss | ||
it.</p> | ||
</ion-content> | ||
</ion-modal> | ||
</ion-content> | ||
</div> | ||
</ion-app> | ||
|
||
<script> | ||
const modal = document.querySelector('ion-modal'); | ||
|
||
modal.canDismiss = (data, role) => role !== 'gesture'; | ||
modal.presentingElement = document.querySelector('.ion-page'); | ||
|
||
function dismiss() { | ||
modal.dismiss(); | ||
} | ||
|
||
</script> | ||
</body> | ||
|
||
</html> |
27 changes: 27 additions & 0 deletions
27
static/usage/v6/modal/can-dismiss/prevent-swipe-to-close/index.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import Playground from '@site/src/components/global/Playground'; | ||
|
||
import javascript from './javascript.md'; | ||
import vue from './vue.md'; | ||
|
||
import react from './react.md'; | ||
|
||
import angular_example_component_html from './angular/example_component_html.md'; | ||
import angular_example_component_ts from './angular/example_component_ts.md'; | ||
|
||
<Playground | ||
version="6" | ||
code={{ | ||
javascript, | ||
react, | ||
vue, | ||
angular: { | ||
files: { | ||
'src/app/example.component.html': angular_example_component_html, | ||
'src/app/example.component.ts': angular_example_component_ts, | ||
}, | ||
}, | ||
}} | ||
src="usage/v6/modal/can-dismiss/prevent-swipe-to-close/demo.html" | ||
devicePreview | ||
mode="ios" | ||
/> |
39 changes: 39 additions & 0 deletions
39
static/usage/v6/modal/can-dismiss/prevent-swipe-to-close/javascript.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
```html | ||
<div class="ion-page"> | ||
<ion-header> | ||
<ion-toolbar> | ||
<ion-title>App</ion-title> | ||
</ion-toolbar> | ||
</ion-header> | ||
<ion-content class="ion-padding"> | ||
<ion-button id="open-modal" expand="block">Open</ion-button> | ||
|
||
<ion-modal trigger="open-modal"> | ||
<ion-header> | ||
<ion-toolbar> | ||
<ion-title>Modal</ion-title> | ||
<ion-buttons slot="end"> | ||
<ion-button onclick="dismiss()">Close</ion-button> | ||
</ion-buttons> | ||
</ion-toolbar> | ||
</ion-header> | ||
<ion-content class="ion-padding"> | ||
<p> | ||
To close this modal, please use the "Close" button provided. Note that swiping the modal will not dismiss it. | ||
</p> | ||
</ion-content> | ||
</ion-modal> | ||
</ion-content> | ||
</div> | ||
|
||
<script> | ||
var modal = document.querySelector('ion-modal'); | ||
|
||
modal.canDismiss = (data, role) => role !== 'gesture'; | ||
modal.presentingElement = document.querySelector('.ion-page'); | ||
|
||
function dismiss() { | ||
modal.dismiss(); | ||
} | ||
</script> | ||
``` |
56 changes: 56 additions & 0 deletions
56
static/usage/v6/modal/can-dismiss/prevent-swipe-to-close/react.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
```tsx | ||
import React, { useState, useRef, useEffect } from 'react'; | ||
import { IonButtons, IonButton, IonModal, IonHeader, IonContent, IonToolbar, IonTitle, IonPage } from '@ionic/react'; | ||
|
||
function Example() { | ||
const modal = useRef<HTMLIonModalElement>(null); | ||
const page = useRef(null); | ||
|
||
const [presentingElement, setPresentingElement] = useState<HTMLElement | null>(null); | ||
|
||
useEffect(() => { | ||
setPresentingElement(page.current); | ||
}, []); | ||
|
||
function dismiss() { | ||
modal.current?.dismiss(); | ||
} | ||
|
||
async function canDismiss(data?: any, role?: string) { | ||
return role !== 'gesture'; | ||
} | ||
|
||
return ( | ||
<IonPage ref={page}> | ||
<IonHeader> | ||
<IonToolbar> | ||
<IonTitle>App</IonTitle> | ||
</IonToolbar> | ||
</IonHeader> | ||
<IonContent className="ion-padding"> | ||
<IonButton id="open-modal" expand="block"> | ||
Open | ||
</IonButton> | ||
<IonModal ref={modal} trigger="open-modal" canDismiss={canDismiss} presentingElement={presentingElement!}> | ||
<IonHeader> | ||
<IonToolbar> | ||
<IonTitle>Modal</IonTitle> | ||
<IonButtons slot="end"> | ||
<IonButton onClick={() => dismiss()}>Close</IonButton> | ||
</IonButtons> | ||
</IonToolbar> | ||
</IonHeader> | ||
<IonContent className="ion-padding"> | ||
<p> | ||
To close this modal, please use the "Close" button provided. Note that swiping the modal will not dismiss | ||
it. | ||
</p> | ||
</IonContent> | ||
</IonModal> | ||
</IonContent> | ||
</IonPage> | ||
); | ||
} | ||
|
||
export default Example; | ||
``` |
47 changes: 47 additions & 0 deletions
47
static/usage/v6/modal/can-dismiss/prevent-swipe-to-close/vue.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
```html | ||
<template> | ||
<ion-page ref="page"> | ||
<ion-header> | ||
<ion-toolbar> | ||
<ion-title>App</ion-title> | ||
</ion-toolbar> | ||
</ion-header> | ||
<ion-content class="ion-padding"> | ||
<ion-button id="open-modal" expand="block">Open</ion-button> | ||
|
||
<ion-modal ref="modal" trigger="open-modal" :can-dismiss="canDismiss" :presenting-element="page?.$el"> | ||
<ion-header> | ||
<ion-toolbar> | ||
<ion-title>Modal</ion-title> | ||
<ion-buttons slot="end"> | ||
<ion-button @click="dismiss">Close</ion-button> | ||
</ion-buttons> | ||
</ion-toolbar> | ||
</ion-header> | ||
<ion-content class="ion-padding"> | ||
<p> | ||
To close this modal, please use the "Close" button provided. Note that swiping the modal will not dismiss | ||
it. | ||
</p> | ||
</ion-content> | ||
</ion-modal> | ||
</ion-content> | ||
</ion-page> | ||
</template> | ||
|
||
<script setup lang="ts"> | ||
import { IonButtons, IonButton, IonModal, IonHeader, IonContent, IonToolbar, IonTitle, IonPage } from '@ionic/vue'; | ||
import { ref } from 'vue'; | ||
|
||
const page = ref(null); | ||
const modal = ref(null); | ||
|
||
function dismiss() { | ||
modal.value.$el.dismiss(); | ||
} | ||
|
||
async function canDismiss(data?: any, role?: string) { | ||
return role !== 'gesture'; | ||
} | ||
</script> | ||
``` |
30 changes: 30 additions & 0 deletions
30
...e/v7/modal/can-dismiss/prevent-swipe-to-close/angular/example_component_html.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
```html | ||
<div class="ion-page" #page> | ||
<ion-header> | ||
<ion-toolbar> | ||
<ion-title>App</ion-title> | ||
</ion-toolbar> | ||
</ion-header> | ||
<ion-content class="ion-padding"> | ||
<ion-button id="open-modal" expand="block">Open</ion-button> | ||
<ion-modal #modal trigger="open-modal" [canDismiss]="canDismiss" [presentingElement]="page"> | ||
<ng-template> | ||
<ion-header> | ||
<ion-toolbar> | ||
<ion-title>Modal</ion-title> | ||
<ion-buttons slot="end"> | ||
<ion-button (click)="modal.dismiss()">Close</ion-button> | ||
</ion-buttons> | ||
</ion-toolbar> | ||
</ion-header> | ||
<ion-content class="ion-padding"> | ||
<p> | ||
To close this modal, please use the "Close" button provided. Note that swiping the modal will not dismiss | ||
it. | ||
</p> | ||
</ion-content> | ||
</ng-template> | ||
</ion-modal> | ||
</ion-content> | ||
</div> | ||
``` |
13 changes: 13 additions & 0 deletions
13
...age/v7/modal/can-dismiss/prevent-swipe-to-close/angular/example_component_ts.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
```ts | ||
import { Component } from '@angular/core'; | ||
|
||
@Component({ | ||
selector: 'app-example', | ||
templateUrl: 'example.component.html', | ||
}) | ||
export class ExampleComponent { | ||
async canDismiss(data?: any, role?: string) { | ||
return role !== 'gesture'; | ||
} | ||
} | ||
``` |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.