Skip to content

Commit 9a11077

Browse files
authored
feat(vue): support autoMountComponent (#25538)
1 parent 60d0db5 commit 9a11077

File tree

6 files changed

+147
-4
lines changed

6 files changed

+147
-4
lines changed

packages/vue/src/vue-component-lib/overlays.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ export const defineOverlayContainer = <Props extends object>(name: string, defin
162162
return h(
163163
name,
164164
{ ...restOfProps, ref: elementRef },
165-
(isOpen.value) ? slots : undefined
165+
(isOpen.value || restOfProps.autoMountComponent) ? slots : undefined
166166
)
167167
}
168168
});

packages/vue/test-app/src/components/PopoverContent.vue

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,16 @@
11
<template>
22
<ion-content class="ion-padding">
3-
{{ title }}
3+
<ion-button id="dismiss" @click="dismiss">Dismiss</ion-button> <br />
4+
5+
<div id="title">
6+
{{ title }}
7+
</div>
48
</ion-content>
59
</template>
610

711
<script lang="ts">
812
import {
13+
IonButton,
914
IonContent,
1015
popoverController
1116
} from '@ionic/vue';
@@ -16,6 +21,7 @@ export default defineComponent({
1621
title: { type: String, default: 'Default Title' }
1722
},
1823
components: {
24+
IonButton,
1925
IonContent
2026
},
2127
setup() {

packages/vue/test-app/src/router/index.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@ const routes: Array<RouteRecordRaw> = [
2525
path: '/overlays',
2626
component: () => import('@/views/Overlays.vue')
2727
},
28+
{
29+
path: '/overlays-auto-mount',
30+
component: () => import('@/views/OverlaysAutoMount.vue')
31+
},
2832
{
2933
path: '/inputs',
3034
component: () => import('@/views/Inputs.vue')
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
<template>
2+
<ion-page data-pageid="overlays-automount">
3+
<ion-header :translucent="true">
4+
<ion-toolbar>
5+
<ion-buttons>
6+
<ion-back-button></ion-back-button>
7+
</ion-buttons>
8+
<ion-title>Overlays - Auto Mount</ion-title>
9+
</ion-toolbar>
10+
</ion-header>
11+
12+
<ion-content class="ion-padding" :fullscreen="true">
13+
<ion-button id="open-auto-mount-modal">Open Auto Mount Modal</ion-button>
14+
15+
<ion-button id="open-auto-mount-popover">Open Auto Mount Popover</ion-button>
16+
17+
<br /><br />
18+
19+
<ion-modal
20+
id="auto-mount-modal"
21+
:auto-mount-component="true"
22+
trigger="open-auto-mount-modal"
23+
>
24+
<ModalContent :title="overlayProps.title"></ModalContent>
25+
</ion-modal>
26+
27+
<ion-popover
28+
id="auto-mount-popover"
29+
:auto-mount-component="true"
30+
trigger="open-auto-mount-popover"
31+
>
32+
<PopoverContent :title="overlayProps.title"></PopoverContent>
33+
</ion-popover>
34+
</ion-content>
35+
</ion-page>
36+
</template>
37+
38+
<script lang="ts">
39+
import {
40+
IonBackButton,
41+
IonButton,
42+
IonButtons,
43+
IonContent,
44+
IonHeader,
45+
IonPage,
46+
IonTitle,
47+
IonToolbar,
48+
IonModal,
49+
IonPopover,
50+
} from '@ionic/vue';
51+
import { defineComponent, ref } from 'vue';
52+
import { trash, share, caretForwardCircle, heart, close } from 'ionicons/icons';
53+
import ModalContent from '@/components/ModalContent.vue';
54+
import PopoverContent from '@/components/PopoverContent.vue';
55+
56+
export default defineComponent({
57+
components: {
58+
ModalContent,
59+
PopoverContent,
60+
IonBackButton,
61+
IonButton,
62+
IonButtons,
63+
IonContent,
64+
IonHeader,
65+
IonPage,
66+
IonTitle,
67+
IonToolbar,
68+
IonModal,
69+
IonPopover,
70+
},
71+
setup() {
72+
const overlayProps = {
73+
title: 'Custom Title'
74+
}
75+
76+
return {
77+
overlayProps
78+
}
79+
}
80+
});
81+
</script>
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
describe('overlays - autoMountComponent', () => {
2+
beforeEach(() => {
3+
cy.viewport(1000, 900);
4+
cy.visit('http://localhost:8080/overlays-auto-mount')
5+
})
6+
describe('modal', () => {
7+
it('should not mount component if false', () => {
8+
cy.get('ion-modal#default-modal ion-content').should('not.exist');
9+
});
10+
11+
it('should mount component if true', () => {
12+
cy.get('ion-modal#auto-mount-modal ion-content').should('exist');
13+
});
14+
15+
it('should keep component mounted after dismissing if true', () => {
16+
cy.get('#open-auto-mount-modal').click();
17+
18+
cy.get('ion-modal#auto-mount-modal ion-content').should('exist');
19+
20+
cy.get('ion-modal#auto-mount-modal #dismiss').click();
21+
22+
cy.get('ion-modal#auto-mount-modal')
23+
.should('not.be.visible')
24+
.should('have.class', 'overlay-hidden');
25+
26+
cy.get('ion-modal#auto-mount-modal ion-content').should('exist');
27+
});
28+
})
29+
describe('popover', () => {
30+
it('should not mount component if false', () => {
31+
cy.get('ion-popover#default-popover ion-content').should('not.exist');
32+
});
33+
34+
it('should mount component if true', () => {
35+
cy.get('ion-popover#auto-mount-popover ion-content').should('exist');
36+
});
37+
38+
it('should keep component mounted after dismissing if true', () => {
39+
cy.get('#open-auto-mount-popover').click();
40+
41+
cy.get('ion-popover#auto-mount-popover ion-content').should('exist');
42+
43+
cy.get('ion-popover#auto-mount-popover #dismiss').click();
44+
45+
cy.get('ion-popover#auto-mount-popover')
46+
.should('not.be.visible')
47+
.should('have.class', 'overlay-hidden');
48+
49+
cy.get('ion-popover#auto-mount-popover ion-content').should('exist');
50+
});
51+
})
52+
})

packages/vue/test-app/tests/e2e/specs/overlays.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ describe('Overlays', () => {
134134
cy.get('ion-button#present-overlay').click();
135135
cy.get('ion-popover.ion-popover-controller').should('exist');
136136

137-
cy.get('ion-popover.ion-popover-controller ion-content').should('have.text', 'Custom Title');
137+
cy.get('ion-popover.ion-popover-controller ion-content #title').should('have.text', 'Custom Title');
138138
});
139139

140140
it('should pass props to popover via component', () => {
@@ -144,7 +144,7 @@ describe('Overlays', () => {
144144
cy.get('ion-button#present-overlay').click();
145145
cy.get('ion-popover').should('exist');
146146

147-
cy.get('ion-popover.popover-inline ion-content').should('have.text', 'Custom Title');
147+
cy.get('ion-popover.popover-inline ion-content #title').should('have.text', 'Custom Title');
148148
});
149149

150150
it('should only open one instance at a time when props change quickly on component', () => {

0 commit comments

Comments
 (0)