From 60303aad23f823488afc8f8824e9c72e3ab86acc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89ric=20Le=20Ma=C3=AEtre?= Date: Fri, 1 Dec 2023 16:30:13 +0100 Subject: [PATCH] fix(vue): nav component accepts kebab-case component properties (#28615) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Issue number: resolves #28611 --------- ## What is the current behavior? It's not possible to pass props that are not camelCase to the `IonNav` component. ## What is the new behavior? - 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 ## Other information ⚠️ 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 --- packages/vue/src/components/IonNav.ts | 35 ++++++++++++++- packages/vue/test/base/src/components/Nav.vue | 18 +++----- .../vue/test/base/src/components/NavRoot.vue | 45 +++++++++---------- .../base/tests/e2e/specs/navigation.cy.js | 6 +++ 4 files changed, 66 insertions(+), 38 deletions(-) diff --git a/packages/vue/src/components/IonNav.ts b/packages/vue/src/components/IonNav.ts index 437734d159..47124a19ff 100644 --- a/packages/vue/src/components/IonNav.ts +++ b/packages/vue/src/components/IonNav.ts @@ -4,7 +4,7 @@ import { defineComponent, h, shallowRef } from "vue"; import { VueDelegate } from "../framework-delegate"; -export const IonNav = /*@__PURE__*/ defineComponent(() => { +export const IonNav = /*@__PURE__*/ defineComponent((props) => { defineCustomElement(); const views = shallowRef([]); @@ -19,8 +19,39 @@ export const IonNav = /*@__PURE__*/ defineComponent(() => { const delegate = VueDelegate(addView, removeView); return () => { - return h("ion-nav", { delegate }, views.value); + return h("ion-nav", { ...props, delegate }, views.value); }; }); IonNav.name = "IonNav"; + +/** + * The default values follow what is defined at + * https://ionicframework.com/docs/api/nav#properties + * otherwise the default values on the Web Component + * may be overridden. For example, if the default animated value + * is not `true` below, then Vue would default the prop to `false` + * which would override the Web Component default of `true`. + */ +IonNav.props = { + animated: { + type: Boolean, + default: true, + }, + animation: { + type: Function, + default: undefined, + }, + root: { + type: [Function, Object, String], + default: undefined, + }, + rootParams: { + type: Object, + default: undefined, + }, + swipeGesture: { + type: Boolean, + default: undefined, + }, +}; diff --git a/packages/vue/test/base/src/components/Nav.vue b/packages/vue/test/base/src/components/Nav.vue index f4ca025094..69dc6d7175 100644 --- a/packages/vue/test/base/src/components/Nav.vue +++ b/packages/vue/test/base/src/components/Nav.vue @@ -1,16 +1,12 @@ - diff --git a/packages/vue/test/base/src/components/NavRoot.vue b/packages/vue/test/base/src/components/NavRoot.vue index ec2fe1c513..ffd18e6765 100644 --- a/packages/vue/test/base/src/components/NavRoot.vue +++ b/packages/vue/test/base/src/components/NavRoot.vue @@ -8,11 +8,14 @@ - Go to Nav Child + + Go to Nav Child - diff --git a/packages/vue/test/base/tests/e2e/specs/navigation.cy.js b/packages/vue/test/base/tests/e2e/specs/navigation.cy.js index d8f75e7163..25788bf759 100644 --- a/packages/vue/test/base/tests/e2e/specs/navigation.cy.js +++ b/packages/vue/test/base/tests/e2e/specs/navigation.cy.js @@ -10,4 +10,10 @@ describe('Navigation', () => { cy.get('#nav-child-content').should('have.text', 'Custom Title'); }); + + it('nav should support kebab-case root-params', () => { + cy.get('#open-nav-modal').click(); + + cy.get('#nav-root-params').should('have.text', 'Message: Hello World!'); + }); });