Skip to content

Commit 60303aa

Browse files
Ericlmsean-perkins
andauthored
fix(vue): nav component accepts kebab-case component properties (#28615)
Issue number: resolves #28611 --------- <!-- Please do not submit updates to dependencies unless it fixes an issue. --> <!-- Please try to limit your pull request to one type (bugfix, feature, etc). Submit multiple pull requests if needed. --> ## What is the current behavior? <!-- Please describe the current behavior that you are modifying. --> It's not possible to pass props that are not camelCase to the `IonNav` component. ## What is the new behavior? <!-- Please describe the behavior or changes that are being added by this PR. --> - It is now possible to set a props with kebab-case instead of camelCase (for example, `root-params` instead of `rootParams`) ## Does this introduce a breaking change? - [ ] Yes - [X] No <!-- If this introduces a breaking change, please describe the impact and migration path for existing applications below. --> ## Other information <!-- Any other information that is important to this PR such as screenshots of how the component looks before and after the change. --> ⚠️ This is my first PR for ionic so I hope I didn't miss important steps into the process. I also checked on my project that the fix is working well. Thank you! 🙂 --------- Co-authored-by: Sean Perkins <[email protected]>
1 parent a3cd204 commit 60303aa

File tree

4 files changed

+66
-38
lines changed

4 files changed

+66
-38
lines changed

packages/vue/src/components/IonNav.ts

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { defineComponent, h, shallowRef } from "vue";
44

55
import { VueDelegate } from "../framework-delegate";
66

7-
export const IonNav = /*@__PURE__*/ defineComponent(() => {
7+
export const IonNav = /*@__PURE__*/ defineComponent((props) => {
88
defineCustomElement();
99
const views = shallowRef([]);
1010

@@ -19,8 +19,39 @@ export const IonNav = /*@__PURE__*/ defineComponent(() => {
1919

2020
const delegate = VueDelegate(addView, removeView);
2121
return () => {
22-
return h("ion-nav", { delegate }, views.value);
22+
return h("ion-nav", { ...props, delegate }, views.value);
2323
};
2424
});
2525

2626
IonNav.name = "IonNav";
27+
28+
/**
29+
* The default values follow what is defined at
30+
* https://ionicframework.com/docs/api/nav#properties
31+
* otherwise the default values on the Web Component
32+
* may be overridden. For example, if the default animated value
33+
* is not `true` below, then Vue would default the prop to `false`
34+
* which would override the Web Component default of `true`.
35+
*/
36+
IonNav.props = {
37+
animated: {
38+
type: Boolean,
39+
default: true,
40+
},
41+
animation: {
42+
type: Function,
43+
default: undefined,
44+
},
45+
root: {
46+
type: [Function, Object, String],
47+
default: undefined,
48+
},
49+
rootParams: {
50+
type: Object,
51+
default: undefined,
52+
},
53+
swipeGesture: {
54+
type: Boolean,
55+
default: undefined,
56+
},
57+
};
Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,12 @@
11
<template>
2-
<ion-nav :root="NavRoot"></ion-nav>
2+
<ion-nav :root="NavRoot" :root-params="rootParams"></ion-nav>
33
</template>
44

5-
<script lang="ts">
6-
import { defineComponent } from 'vue';
7-
import { IonNav } from '@ionic/vue';
8-
import NavRoot from '@/components/NavRoot.vue';
5+
<script setup lang="ts">
6+
import { IonNav } from "@ionic/vue";
7+
import NavRoot from "@/components/NavRoot.vue";
98
10-
export default defineComponent({
11-
components: { IonNav },
12-
setup() {
13-
return { NavRoot }
14-
}
15-
});
9+
const rootParams = {
10+
message: "Hello World!",
11+
};
1612
</script>

packages/vue/test/base/src/components/NavRoot.vue

Lines changed: 20 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -8,40 +8,35 @@
88
</ion-toolbar>
99
</ion-header>
1010
<ion-content class="ion-padding">
11-
<ion-button expand="block" @click="pushPage" id="push-nav-child">Go to Nav Child</ion-button>
11+
<div id="nav-root-params">Message: {{ message }}</div>
12+
<ion-button expand="block" @click="pushPage" id="push-nav-child"
13+
>Go to Nav Child</ion-button
14+
>
1215
</ion-content>
1316
</template>
1417

15-
<script lang="ts">
18+
<script setup lang="ts">
1619
import {
1720
IonButtons,
1821
IonButton,
1922
IonContent,
2023
IonHeader,
2124
IonTitle,
2225
IonToolbar,
23-
modalController
24-
} from '@ionic/vue';
25-
import { defineComponent } from 'vue';
26-
import NavChild from '@/components/NavChild.vue';
26+
modalController,
27+
} from "@ionic/vue";
28+
import NavChild from "@/components/NavChild.vue";
2729
28-
export default defineComponent({
29-
components: {
30-
IonButtons,
31-
IonButton,
32-
IonContent,
33-
IonHeader,
34-
IonTitle,
35-
IonToolbar
36-
},
37-
methods: {
38-
pushPage: function() {
39-
const ionNav = document.querySelector('ion-nav') as any;
40-
ionNav.push(NavChild, { title: 'Custom Title' });
41-
},
42-
dismiss: async function() {
43-
await modalController.dismiss();
44-
}
45-
}
46-
})
30+
defineProps<{
31+
message: string;
32+
}>();
33+
34+
function pushPage() {
35+
const ionNav = document.querySelector("ion-nav") as any;
36+
ionNav.push(NavChild, { title: "Custom Title" });
37+
}
38+
39+
async function dismiss() {
40+
await modalController.dismiss();
41+
}
4742
</script>

packages/vue/test/base/tests/e2e/specs/navigation.cy.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,10 @@ describe('Navigation', () => {
1010

1111
cy.get('#nav-child-content').should('have.text', 'Custom Title');
1212
});
13+
14+
it('nav should support kebab-case root-params', () => {
15+
cy.get('#open-nav-modal').click();
16+
17+
cy.get('#nav-root-params').should('have.text', 'Message: Hello World!');
18+
});
1319
});

0 commit comments

Comments
 (0)