Skip to content

Commit b401de1

Browse files
fix(vue): preserve custom classes on IonPage (#24776)
resolves #24772 Co-authored-by: bnachtweh <[email protected]>
1 parent abc36ae commit b401de1

File tree

2 files changed

+65
-1
lines changed

2 files changed

+65
-1
lines changed

packages/vue/src/components/IonPage.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,12 @@ export const IonPage = /*@__PURE__*/ defineComponent({
1212
setup(props, { attrs, slots }) {
1313
const hidePageClass = (props.isInOutlet) ? 'ion-page-invisible' : '';
1414
return () => {
15+
const existingClasses = attrs.class ?? '';
1516
return h(
1617
'div',
1718
{
18-
['class']: `ion-page ${hidePageClass}`,
1919
...attrs,
20+
['class']: `ion-page ${hidePageClass} ${existingClasses}`,
2021
ref: 'ionPage'
2122
},
2223
slots.default && slots.default()
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
import { mount } from '@vue/test-utils';
2+
import { createRouter, createWebHistory } from '@ionic/vue-router';
3+
import { IonicVue, IonApp, IonRouterOutlet, IonPage } from '@ionic/vue';
4+
5+
const App = {
6+
components: { IonApp, IonRouterOutlet },
7+
template: '<ion-app><ion-router-outlet /></ion-app>',
8+
}
9+
10+
describe('IonPage', () => {
11+
beforeAll(() => {
12+
(HTMLElement.prototype as HTMLIonRouterOutletElement).commit = jest.fn();
13+
});
14+
it('should add ion-page class', async () => {
15+
const Page1 = {
16+
template: '<ion-page></ion-page>',
17+
components: { IonPage }
18+
};
19+
20+
const router = createRouter({
21+
history: createWebHistory(process.env.BASE_URL),
22+
routes: [
23+
{ path: '/', component: Page1 }
24+
]
25+
});
26+
27+
router.push('/');
28+
await router.isReady();
29+
const wrapper = mount(App, {
30+
global: {
31+
plugins: [router, IonicVue]
32+
}
33+
});
34+
35+
const cmp = wrapper.findComponent(Page1);
36+
expect(cmp.classes('ion-page')).toBe(true);
37+
});
38+
it('should preserve custom classes', async () => {
39+
const Page1 = {
40+
template: '<ion-page class="custom-class"></ion-page>',
41+
components: { IonPage }
42+
};
43+
44+
const router = createRouter({
45+
history: createWebHistory(process.env.BASE_URL),
46+
routes: [
47+
{ path: '/', component: Page1 }
48+
]
49+
});
50+
51+
router.push('/');
52+
await router.isReady();
53+
const wrapper = mount(App, {
54+
global: {
55+
plugins: [router, IonicVue]
56+
}
57+
});
58+
59+
const cmp = wrapper.findComponent(Page1);
60+
expect(cmp.classes('ion-page')).toBe(true);
61+
expect(cmp.classes('custom-class')).toBe(true);
62+
});
63+
})

0 commit comments

Comments
 (0)