fix(vue): preserve custom classes on IonPage (#24776)

resolves #24772

Co-authored-by: bnachtweh <bnachtweh@users.noreply.github.com>
This commit is contained in:
Liam DeBeasi
2022-02-11 10:11:04 -05:00
committed by GitHub
parent abc36ae80b
commit b401de1ab3
2 changed files with 65 additions and 1 deletions

View File

@ -12,11 +12,12 @@ export const IonPage = /*@__PURE__*/ defineComponent({
setup(props, { attrs, slots }) {
const hidePageClass = (props.isInOutlet) ? 'ion-page-invisible' : '';
return () => {
const existingClasses = attrs.class ?? '';
return h(
'div',
{
['class']: `ion-page ${hidePageClass}`,
...attrs,
['class']: `ion-page ${hidePageClass} ${existingClasses}`,
ref: 'ionPage'
},
slots.default && slots.default()

View File

@ -0,0 +1,63 @@
import { mount } from '@vue/test-utils';
import { createRouter, createWebHistory } from '@ionic/vue-router';
import { IonicVue, IonApp, IonRouterOutlet, IonPage } from '@ionic/vue';
const App = {
components: { IonApp, IonRouterOutlet },
template: '<ion-app><ion-router-outlet /></ion-app>',
}
describe('IonPage', () => {
beforeAll(() => {
(HTMLElement.prototype as HTMLIonRouterOutletElement).commit = jest.fn();
});
it('should add ion-page class', async () => {
const Page1 = {
template: '<ion-page></ion-page>',
components: { IonPage }
};
const router = createRouter({
history: createWebHistory(process.env.BASE_URL),
routes: [
{ path: '/', component: Page1 }
]
});
router.push('/');
await router.isReady();
const wrapper = mount(App, {
global: {
plugins: [router, IonicVue]
}
});
const cmp = wrapper.findComponent(Page1);
expect(cmp.classes('ion-page')).toBe(true);
});
it('should preserve custom classes', async () => {
const Page1 = {
template: '<ion-page class="custom-class"></ion-page>',
components: { IonPage }
};
const router = createRouter({
history: createWebHistory(process.env.BASE_URL),
routes: [
{ path: '/', component: Page1 }
]
});
router.push('/');
await router.isReady();
const wrapper = mount(App, {
global: {
plugins: [router, IonicVue]
}
});
const cmp = wrapper.findComponent(Page1);
expect(cmp.classes('ion-page')).toBe(true);
expect(cmp.classes('custom-class')).toBe(true);
});
})