Treeview Vue Component

Treeview Vue component represents Framework7's Treeview component.

Treeview Components

There are following components included:

  • f7-treeview - main treeview container
  • f7-treeview-item - treeview item

Treeview Properties

PropTypeDefaultDescription
<f7-treeview-item> properties
togglebooleanEnables treeview item toggle button. By default enabled if there are children item
item-togglebooleanfalseEnables whole treeview item as toggle
selectablebooleanfalseMakes item selectable
selectedbooleanMakes item selected
openedbooleanfalseDefines whether the item opened by default or not
labelstringItem label text
load-childrenbooleanfalseEnable when you need to load children items on open.
linkstring
boolean
Enables link and link URL if specified as string. Same as href attribute
<f7-treeview-item> icon related properties
icon-sizestring
number
Icon size in px
icon-colorstringIcon color. One of the default colors
iconstringCustom icon class
icon-f7stringName of F7 Icons font icon
icon-materialstringName of Material Icons font icon
icon-iosstringIcon to be used in case of iOS theme is used. Consists of icon family and icon name divided by colon, e.g. f7:house
icon-mdstringIcon to be used in case of MD theme is used. Consists of icon family and icon name divided by colon, e.g. material:home
icon-aurorastringIcon to be used in case of Aurora theme is used. Consists of icon family and icon name divided by colon, e.g. material:home
<f7-treeview-item> navigation/router related properties
hrefstring
boolean
#URL of the page to load. In case of boolean href="false" it won't add href tag
targetstringValue of link target attribute, e.g. _blank, _self, etc.
viewstringCSS selector of the View to load the page. Or current to load in current view.
externalbooleanEnable to bypass Framework7's link click handler
backbooleanEnables back navigation link
forcebooleanForce page to load and ignore previous page in history (use together with back prop)
reload-currentbooleanReloads new page instead of the currently active one
reload-previousbooleanReplace the previous page in history with the new one from route
reload-allbooleanLoad new page and remove all previous pages from history and DOM
reload-detailbooleanReload Detail page in Master Detail view
animatebooleanDisables pages animation
transitionstringName of the custom page transition
ignore-cachebooleanIgnores caching
route-tab-idstringRoutable Tab id
route-propsobjectObject with additional props that will be passed to target route component
prevent-routerbooleanfalseIf set, then it won't be processed by Framework7 router
<f7-treeview-item> action related properties
panel-openstring
boolean
CSS selector of panel to open on click. Or can be left or right if there is only left or right panel in DOM.
panel-closestring
boolean
Closes panel on click
panel-togglestring
boolean
CSS selector of panel to toggle on click. Or can be left or right if there is only left or right panel in DOM.
actions-openstring
boolean
CSS selector of the action sheet to open on click
actions-closestring
boolean
CSS selector of the action sheet to close on click. Or boolean property to close currently opened action sheet
popup-openstring
boolean
CSS selector of the popup to open on click
popup-closestring
boolean
CSS selector of the popup to close on click. Or boolean property to close currently opened popup
popover-openstring
boolean
CSS selector of the popover to open on click
popover-closestring
boolean
CSS selector of the popover to close on click. Or boolean property to close currently opened popover
sheet-openstring
boolean
CSS selector of the sheet modal to open on click
sheet-closestring
boolean
CSS selector of the sheet modal to close on click. Or boolean property to close currently opened sheet modal
login-screen-openstring
boolean
CSS selector of the login screen to open on click
login-screen-closestring
boolean
CSS selector of the login screen to close on click. Or boolean property to close currently opened login screen
sortable-enablestring
boolean
CSS selector of the Sortable list to be enabled on click
sortable-disablestring
boolean
CSS selector of the Sortable list to be disabled on click. Or boolean property to close currently opened Sortable list
sortable-togglestring
boolean
CSS selector of the Sortable list to toggle on click. Or boolean property to toggle currently opened/closed Sortable list
searchbar-enablestring
boolean
CSS selector of the Expandable Searchbar to be enabled on click. Or boolean property to enable the first found Searchbar
searchbar-disablestring
boolean
CSS selector of the Expandable Searchbar to be disabled on click. Or boolean property to disable the first found Searchbar
searchbar-togglestring
boolean
CSS selector of the Expandable Searchbar to toggle on click. Or boolean property to toggle the first found Searchbar
searchbar-clearstring
boolean
CSS selector of the Expandable Searchbar to clear on click. Or boolean property to clear the first found Searchbar
card-openstring
boolean
CSS selector of the expandable card to open on click. Or boolean to open first found expandable card
card-closestring
boolean
CSS selector of the expandable card to close on click. Or boolean property to close currently opened expandable card
card-prevent-openbooleanClick on element with this prop won't open its parent expandable card
menu-closebooleanCloses Menu dropdown on click

Treeview Events

EventDescription
<f7-treeview-item> events
clickEvent will be triggeres when user clicks on treeview item
treeview:openEvent will be triggered on item open
treeview:closeEvent will be triggered on item close
treeview:loadchildrenEvent will be triggered on first open of Treeview item with loadChildren prop. In event.detail it contains function to hide loading preloader.

Treeview Item Slots

Treeview Vue component (<f7-treeview-item>) has additional slots for custom elements:

  • root-start - element will be inserted in the beginning of treeview item element
  • root / root-end - element will be inserted in the end of treeview item element
  • content-start - element will be inserted in the beginning of <div class="treeview-item-content"> element
  • content / content-end - element will be inserted in the end of <div class="treeview-item-content"> element
  • children-start - element will be inserted in the beginning of the <div class="treeview-item-children"> element
  • default - element will be inserted in the end of the <div class="treeview-item-children"> element
  • media - element will be inserted before <div class="treeview-item-label"> element
  • label-start - element will be inserted in the beginning <div class="treeview-item-label"> element
  • label - element will be inserted in the end of <div class="treeview-item-label"> element
<f7-treeview-item label="Item 1">
  <img src="path-to-my-image.jpg" slot="media">
  <div slot="root-start">Root Start</div>
  <div slot="root">Root End</div>
  <div slot="content-start">Content Start</div>
  <div slot="content">Content End</div>
  <span slot="label-start">Before Label</span>
  <f7-treeview-item label="Sub Item 1" />
  ...
</f7-treeview-item>

<!-- Renders to: -->
<div class="treeview-item">
  <div class="treeview-item-root">
    <div>Root Start</div>
    <div class="treeview-toggle"></div>
    <div class="treeview-item-content">
      <div>Content Start</div>
      <img src="path-to-my-image.jpg">
      <div class="treeview-item-label">
        <span>Before Label</span>
        Item 1
      </div>
      <div>Content End</div>
    </div>
  </div>
  <div class="treeview-item-children">
    <div class="treeview-item">
      <div class="treeview-item-root">
        <div class="treeview-item-content">
          <div class="treeview-item-label">Sub Item 1</div>
        </div>
      </div>
    </div>
    ...
  </div>
  <div>Root End</div>
</div>

Examples

<template>
  <f7-page>
    <f7-navbar title="Treeview" />

    <f7-block-title>Basic tree view</f7-block-title>
    <f7-block strong class="no-padding-horizontal">
      <f7-treeview>
        <f7-treeview-item label="Item 1">
          <f7-treeview-item label="Sub Item 1">
            <f7-treeview-item label="Sub Sub Item 1" />
            <f7-treeview-item label="Sub Sub Item 2" />
          </f7-treeview-item>
          <f7-treeview-item label="Sub Item 2">
            <f7-treeview-item label="Sub Sub Item 1" />
            <f7-treeview-item label="Sub Sub Item 2" />
          </f7-treeview-item>
        </f7-treeview-item>
        <f7-treeview-item label="Item 2">
          <f7-treeview-item label="Sub Item 1">
            <f7-treeview-item label="Sub Sub Item 1" />
            <f7-treeview-item label="Sub Sub Item 2" />
          </f7-treeview-item>
          <f7-treeview-item label="Sub Item 2">
            <f7-treeview-item label="Sub Sub Item 1" />
            <f7-treeview-item label="Sub Sub Item 2" />
          </f7-treeview-item>
        </f7-treeview-item>
        <f7-treeview-item label="Item 3" />
      </f7-treeview>
    </f7-block>

    <f7-block-title>With icons</f7-block-title>
    <f7-block strong class="no-padding-horizontal">
      <f7-treeview>
        <f7-treeview-item label="images" icon-f7="folder_fill">
          <f7-treeview-item label="avatar.png" icon-f7="photo_fill" />
          <f7-treeview-item label="background.jpg" icon-f7="photo_fill" />
        </f7-treeview-item>
        <f7-treeview-item label="documents" icon-f7="folder_fill">
          <f7-treeview-item label="cv.docx" icon-f7="doc_text_fill" />
          <f7-treeview-item label="info.docx" icon-f7="doc_text_fill" />
        </f7-treeview-item>
        <f7-treeview-item label=".gitignore" icon-f7="logo_github" />
        <f7-treeview-item label="index.html" icon-f7="doc_text_fill" />
      </f7-treeview>
    </f7-block>

    <f7-block-title>With checkboxes</f7-block-title>
    <f7-block strong class="no-padding-horizontal">
      <f7-treeview>
        <f7-treeview-item label="images" icon-f7="folder_fill">
          <f7-checkbox slot="content-start"
            :checked="Object.values(checkboxes.images).indexOf(false) < 0"
            :indeterminate="Object.values(checkboxes.images).indexOf(false) >= 0 && Object.values(checkboxes.images).indexOf(true) >= 0"
            @change="(e) => Object.keys(checkboxes.images).forEach(k => checkboxes.images[k] = e.target.checked)"
          />
          <f7-treeview-item label="avatar.png" icon-f7="photo_fill">
            <f7-checkbox slot="content-start"
              :checked="checkboxes.images['avatar.png']"
              @change="checkboxes.images['avatar.png'] = $event.target.checked"
            />
          </f7-treeview-item>
          <f7-treeview-item label="background.jpg" icon-f7="photo_fill">
            <f7-checkbox slot="content-start"
              :checked="checkboxes.images['background.jpg']"
              @change="checkboxes.images['background.jpg'] = $event.target.checked"
            />
          </f7-treeview-item>
        </f7-treeview-item>
        <f7-treeview-item label="documents" icon-f7="folder_fill">
          <f7-checkbox slot="content-start"
            :checked="Object.values(checkboxes.documents).indexOf(false) < 0"
            :indeterminate="Object.values(checkboxes.documents).indexOf(false) >= 0 && Object.values(checkboxes.documents).indexOf(true) >= 0"
            @change="(e) => Object.keys(checkboxes.documents).forEach(k => checkboxes.documents[k] = e.target.checked)"
          />
          <f7-treeview-item label="cv.docx" icon-f7="doc_text_fill">
            <f7-checkbox slot="content-start"
              :checked="checkboxes.documents['cv.docx']"
              @change="checkboxes.documents['cv.docx'] = $event.target.checked"
            />
          </f7-treeview-item>
          <f7-treeview-item label="info.docx" icon-f7="doc_text_fill">
            <f7-checkbox slot="content-start"
              :checked="checkboxes.documents['info.docx']"
              @change="checkboxes.documents['info.docx'] = $event.target.checked"
            />
          </f7-treeview-item>
        </f7-treeview-item>
        <f7-treeview-item label=".gitignore" icon-f7="logo_github">
          <f7-checkbox slot="content-start"
            :checked="checkboxes['.gitignore']"
            @change="checkboxes['.gitignore'] = $event.target.checked"
          />
        </f7-treeview-item>
        <f7-treeview-item label="index.html" icon-f7="doc_text_fill">
          <f7-checkbox slot="content-start"
            :checked="checkboxes['index.html']"
            @change="checkboxes['index.html'] = $event.target.checked"
          />
        </f7-treeview-item>
      </f7-treeview>
    </f7-block>

    <f7-block-title>Whole item as toggle</f7-block-title>
    <f7-block strong class="no-padding-horizontal">
      <f7-treeview>
        <f7-treeview-item item-toggle label="images" icon-f7="folder_fill">
          <f7-treeview-item label="avatar.png" icon-f7="photo_fill" />
          <f7-treeview-item label="background.jpg" icon-f7="photo_fill" />
        </f7-treeview-item>
        <f7-treeview-item item-toggle label="documents" icon-f7="folder_fill">
          <f7-treeview-item label="cv.docx" icon-f7="doc_text_fill" />
          <f7-treeview-item label="info.docx" icon-f7="doc_text_fill" />
        </f7-treeview-item>
        <f7-treeview-item label=".gitignore" icon-f7="logo_github" />
        <f7-treeview-item label="index.html" icon-f7="doc_text_fill" />
      </f7-treeview>
    </f7-block>

    <f7-block-title>Selectable</f7-block-title>
    <f7-block strong class="no-padding-horizontal">
      <f7-treeview>
        <f7-treeview-item
          selectable
          :selected="selectedItem === 'images'"
          label="images"
          icon-f7="folder_fill"
          @click="toggleSelectable($event, 'images')"
        >
          <f7-treeview-item
            selectable
            :selected="selectedItem === 'avatar.png'"
            label="avatar.png"
            icon-f7="photo_fill"
            @click="toggleSelectable($event, 'avatar.png')"
          />
          <f7-treeview-item
            selectable
            :selected="selectedItem === 'background.jpg'"
            label="background.jpg"
            icon-f7="photo_fill"
            @click="toggleSelectable($event, 'background.jpg')"
          />
        </f7-treeview-item>
        <f7-treeview-item
          selectable
          :selected="selectedItem === 'documents'"
          label="documents"
          icon-f7="folder_fill"
          @click="toggleSelectable($event, 'documents')"
        >
          <f7-treeview-item
            selectable
            :selected="selectedItem === 'cv.docx'"
            label="cv.docx"
            icon-f7="doc_text_fill"
            @click="toggleSelectable($event, 'cv.docx')"
          />
          <f7-treeview-item
            selectable
            :selected="selectedItem === 'info.docx'"
            label="info.docx"
            icon-f7="doc_text_fill"
            @click="toggleSelectable($event, 'info.docx')"
          />
        </f7-treeview-item>
        <f7-treeview-item
          selectable
          :selected="selectedItem === '.gitignore'"
          label=".gitignore"
          icon-f7="logo_github"
          @click="toggleSelectable($event, '.gitignore')"
        />
        <f7-treeview-item
          selectable
          :selected="selectedItem === 'index.html'"
          label="index.html"
          icon-f7="doc_text_fill"
          @click="toggleSelectable($event, 'index.html')"
        />
      </f7-treeview>
    </f7-block>

    <f7-block-title>Preload children</f7-block-title>
    <f7-block strong class="no-padding-horizontal">
      <f7-treeview>
        <f7-treeview-item
          toggle
          load-children
          icon-f7="person_2_fill"
          label="Users"
          @treeview:loadchildren="loadChildren"
        >
          <f7-treeview-item
            v-for="(item, index) in loadedChildren"
            :key="index"
            icon-f7="person_fill"
            :label="item.name"
          />
        </f7-treeview-item>
      </f7-treeview>
    </f7-block>

    <f7-block-title>With links</f7-block-title>
    <f7-block strong class="no-padding-horizontal">
      <f7-treeview>
        <f7-treeview-item icon-f7="square_grid_2x2_fill" item-toggle label="Modals">
          <f7-treeview-item link="/popup/" icon-f7="link" label="Popup" />
          <f7-treeview-item link="/dialog/" icon-f7="link" label="Dialog" />
          <f7-treeview-item link="/action-sheet/" icon-f7="link" label="Action Sheet" />
        </f7-treeview-item>
        <f7-treeview-item icon-f7="square_grid_2x2_fill" item-toggle label="Navigation Bars">
          <f7-treeview-item link="/navbar/" icon-f7="link" label="Navbar" />
          <f7-treeview-item link="/toolbar-tabbar/" icon-f7="link" label="Toolbar & Tabbar" />
        </f7-treeview-item>
      </f7-treeview>
    </f7-block>
  </f7-page>
</template>
<script>
  import { f7Page, f7Navbar, f7BlockTitle, f7Block, f7Treeview, f7TreeviewItem, f7Checkbox } from 'framework7-vue';

  export default {
    components: {
      f7Page, f7Navbar, f7BlockTitle, f7Block, f7Treeview, f7TreeviewItem, f7Checkbox
    },
    data: function () {
      return {
        checkboxes: {
          images: {
            'avatar.png': false,
            'background.jpg': false,
          },
          documents: {
            'cv.docx': false,
            'info.docx': false,
          },
          '.gitignore': false,
          'index.html': false,
        },
        selectedItem: null,
        loadedChildren: [],
      };
    },
    methods: {
      toggleSelectable: function (e, item) {
        var self = this;
        var $ = self.$$;
        if ($(e.target).is('.treeview-toggle')) return;
        self.selectedItem = item;
      },
      loadChildren: function (e, done) {
        var self = this;
        setTimeout(function () {
          // call done() to hide preloader
          done();
          self.loadedChildren = [
            {
              name: 'John Doe',
            },
            {
              name: 'Jane Doe',
            },
            {
              name: 'Calvin Johnson',
            },
          ];
        }, 2000);
      },
    },
  };
</script>