Skip to content

bug: RootParams of ion-nav not detected if in kebab-case #28611

Closed

Description

@Ericlm

Prerequisites

Ionic Framework Version

v7.x

Current Behavior

I created an Ionic-Vue project, and when using the ion-nav component, the root component doesn't get any props if ion-nav uses kebab-case but it works perfectly with camelCase.

Expected Behavior

The ion-nav component should not be sensitive to casing, just like other Vue components, and recommended by the linter rules: https://eslint.vuejs.org/rules/attribute-hyphenation.html#vue-attribute-hyphenation

Steps to Reproduce

  1. Clone https://github.com/Ericlm/ionic-vue-nav-root-params
  2. Go to Tab1Page.vue file and look for the two IonNav components in the template
  3. The second one doesn't work (because it is in kebab-case)

Code Reproduction URL

https://github.com/Ericlm/ionic-vue-nav-root-params

Ionic Info

ionic info doesn't seem to work with my project (?)

[ERROR] Invalid project type: vue-vite (project config: ./ionic.config.json).
        
        Project type must be one of: angular, ionic-angular, ionic1, custom, react, vue

Bad project type: undefined

Additional Information

No response

Activity

  1. Ericlm commented on Nov 30, 2023

    @Ericlm
    ContributorAuthor

    *Maybe the same issue with componentProps on ion-nav-link.

  2. liamdebeasi commented on Nov 30, 2023

    @liamdebeasi
    Contributor

    Can you make your repo public?

  3. added
    needs: reply
    on Nov 30, 2023
  4. Ericlm commented on Nov 30, 2023

    @Ericlm
    ContributorAuthor

    Sorry didn't see that 🤦‍♂️ It should be public now.

  5. added and removed
    needs: reply
    on Nov 30, 2023
  6. liamdebeasi commented on Nov 30, 2023

    @liamdebeasi
    Contributor

    Thanks! This is a bug in Ionic. We aren't setting component props in https://github.com/ionic-team/ionic-framework/blob/a3cd204f616606ccffc35082655e55fdfb19fe28/packages/vue/src/components/IonNav.ts.

    Are you interested in making a PR to fix this? We'll need to make the following changes:

    1. Define properties on the component. (basically all the props defined at https://ionicframework.com/docs/api/nav#properties)
    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
      }
    }

    There's probably a better solution for not overriding the Web Component default values, but I think it's fine to stick with this approach for now and the team can look into a better solution in the future.

    1. Pass props to the render function.
    - export const IonNav = /*@__PURE__*/ defineComponent(() => {
    + export const IonNav = /*@__PURE__*/ defineComponent((props) => {
      defineCustomElement();
      const views = shallowRef([]);
    
      /**
       * Allows us to create the component
       * within the Vue application context.
       */
      const addView = (component: VNode) =>
        (views.value = [...views.value, component]);
      const removeView = (component: VNode) =>
        (views.value = views.value.filter((cmp) => cmp !== component));
    
      const delegate = VueDelegate(addView, removeView);
      return () => {
    -    return h("ion-nav", { delegate }, views.value);
    +    return h("ion-nav", { ...props, delegate }, views.value);
      };
    });
  7. added
    help wanted
    on Nov 30, 2023
  8. ionitron-bot commented on Nov 30, 2023

    @ionitron-bot

    This issue has been labeled as help wanted. This label is added to issues that we believe would be good for contributors.

    If you'd like to work on this issue, please comment here letting us know that you would like to submit a pull request for it. This helps us to keep track of the pull request and make sure there isn't duplicated effort.

    For a guide on how to create a pull request and test this project locally to see your changes, see our contributing documentation.

    Thank you!

  9. Ericlm commented on Nov 30, 2023

    @Ericlm
    ContributorAuthor

    I may take a look at it! 🙂

  10. added a commit that references this issue on Dec 1, 2023
    60303aa
  11. liamdebeasi commented on Dec 1, 2023

    @liamdebeasi
    Contributor

    Thanks for the issue. This has been resolved via #28615, and a fix will be available in an upcoming release of Ionic Framework.

  12. ionitron-bot commented on Dec 31, 2023

    @ionitron-bot

    Thanks for the issue! This issue is being locked to prevent comments that are not relevant to the original issue. If this is still an issue with the latest version of Ionic, please create a new issue and ensure the template is fully filled out.

  13. locked and limited conversation to collaborators on Dec 31, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    help wanted

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions