No More Posting New Topics!

If you have a question or an issue, please start a thread in our Github Discussions Forum.
This forum is closed for new threads/ topics.

Navigation

    Quasar Framework

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search

    Opening QCollapsible when a route is matched to one of its items.

    Framework
    layout q-collapsible vue-router
    2
    3
    1009
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • F
      fbmelarpis last edited by

      Regarding Vue Router and Layout integration, how can I dynamically open a QCollapsible that contains the QSideLink with linkExactActiveClass when a route is visited, given I have multiple collapsibles?
      e.g.

      <template>
        <div v-for="link in formattedLinks">
          <q-collapsible v-if="link.isCollapsible" v-bind="link">
            <q-side-link
              item
              exact
              v-for="sublink in link.sublinks"
              v-bind="sublink"
            />
          </q-collapsible>
          ...
        </div>
      </template>
      <script>
      export default {
        name: 'SidebarNavigation',
        ...
        props: {
          link: {
            type: Array,
            required: true,
            ...
          }
        }
      }
      </script>
      

      I was able to create a workaround but I really don’t like it…

      ...
      methods: {
        openActiveCollapsible() {
          // :( 
          const activeCollapsible = this.$el.querySelector(this.linkExactActiveClass);
          
          if (!activeCollapsible) {
            return;
          }
      
          activeCollapsible.parentElement.parentElement.parentElement.firstElementChild.click();
        }
      mounted() {
        this.openActiveCollapsible();
      }
      

      I’m thinking if I should check for the existence of the linkExactActiveClass, or compare the current route with the QSideLink:to and trigger open method of the parent ref.
      Does anyone have an idea on how to do this properly?

      1 Reply Last reply Reply Quote 0
      • benoitranque
        benoitranque last edited by

        Another approach: use route meta:

        // route definition in router.js
        {
          path: 'path',
          component: ParentComponent,
          meta: {
            parent: 'ParentName'
          },
          chilldren: [
            {
              path: 'child',
              component: ChildComponent,
              meta: {
                parent: 'ParentName'
              }
            }
          ]
        }
        // usage in component
        this.$route.meta.parent === 'ParentName' // parent matches
        
        1 Reply Last reply Reply Quote 0
        • F
          fbmelarpis last edited by

          I got it working using events and wrapping <q-side-link> to emit an event when exactActiveClass is present.

          <!-- link.group is a unique string -->
          <q-collapsible :ref="link.group" v-if="link.isCollapsible" v-bind="link">
            <sidebar-navigation-item
              item
              exact
              v-for="sublink in link.sublinks"
              v-bind="sublink"
              :parent-ref="link.group"
              @active="openActiveCollapsible"
            />
          </q-collapsible>
          ...
          methods: {
            openActiveCollapsible(ref) {
              this.$refs[ref][0].open()
            }
          }
          // in <sidebar-navigation-item>
          mounted() {
            if (this.$el.classList.contains(this.exactActiveClass)) {
              this.$emit('active', this.parentRef);
            }
          }
          
          1 Reply Last reply Reply Quote 0
          • First post
            Last post