Treeview - 图1

Treeview Svelte Component

Treeview Svelte component represents Framework7’s Treeview component.

Treeview Components

There are following components included:

  • Treeview - main treeview container
  • TreeviewItem - treeview item

Treeview Properties

PropTypeDefaultDescription
<TreeviewItem> properties
togglebooleanEnables treeview item toggle button. By default enabled if there are children item
itemTogglebooleanfalseEnables whole treeview item as toggle
selectablebooleanfalseMakes item selectable
selectedbooleanMakes item selected
openedbooleanfalseDefines whether the item opened by default or not
labelstringItem label text
loadChildrenbooleanfalseEnable when you need to load children items on open.
linkstring
boolean
Enables link and link URL if specified as string. Same as href attribute
<TreeviewItem> icon related properties
iconSizestring
number
Icon size in px
iconColorstringIcon color. One of the default colors
iconstringCustom icon class
iconF7stringName of F7 Icons font icon
iconMaterialstringName of Material Icons font icon
iconIosstringIcon to be used in case of iOS theme is used. Consists of icon family and icon name divided by colon, e.g. f7:home
iconMdstringIcon to be used in case of MD theme is used. Consists of icon family and icon name divided by colon, e.g. material:home
iconAurorastringIcon to be used in case of Aurora theme is used. Consists of icon family and icon name divided by colon, e.g. f7:home
<TreeviewItem> 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)
reloadCurrentbooleanReloads new page instead of the currently active one
reloadPreviousbooleanReplace the previous page in history with the new one from route
reloadAllbooleanLoad new page and remove all previous pages from history and DOM
reloadDetailbooleanReload Detail page in Master Detail view
animatebooleanDisables pages animation
transitionstringName of the custom page transition
ignoreCachebooleanIgnores caching
routeTabIdstringRoutable Tab id
routePropsobjectObject with additional props that will be passed to target route component
preventRouterbooleanfalseIf set, then it won’t be processed by Framework7 router
<TreeviewItem> action related properties
panelOpenstring
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.
panelClosestring
boolean
Closes panel on click
panelTogglestring
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.
actionsOpenstring
boolean
CSS selector of the action sheet to open on click
actionsClosestring
boolean
CSS selector of the action sheet to close on click. Or boolean property to close currently opened action sheet
popupOpenstring
boolean
CSS selector of the popup to open on click
popupClosestring
boolean
CSS selector of the popup to close on click. Or boolean property to close currently opened popup
popoverOpenstring
boolean
CSS selector of the popover to open on click
popoverClosestring
boolean
CSS selector of the popover to close on click. Or boolean property to close currently opened popover
sheetOpenstring
boolean
CSS selector of the sheet modal to open on click
sheetClosestring
boolean
CSS selector of the sheet modal to close on click. Or boolean property to close currently opened sheet modal
loginScreenOpenstring
boolean
CSS selector of the login screen to open on click
loginScreenClosestring
boolean
CSS selector of the login screen to close on click. Or boolean property to close currently opened login screen
sortableEnablestring
boolean
CSS selector of the Sortable list to open on click
sortableDisablestring
boolean
CSS selector of the Sortable list to close on click. Or boolean property to close currently opened Sortable list
sortableTogglestring
boolean
CSS selector of the Sortable list to toggle on click. Or boolean property to toggle currently opened/closed Sortable list
searchbarEnablestring
boolean
CSS selector of the Expandable Searchbar to be enabled on click. Or boolean property to enable the first found Searchbar
searchbarDisablestring
boolean
CSS selector of the Expandable Searchbar to be disabled on click. Or boolean property to disable the first found Searchbar
searchbarTogglestring
boolean
CSS selector of the Expandable Searchbar to toggle on click. Or boolean property to toggle the first found Searchbar
searchbarClearstring
boolean
CSS selector of the Expandable Searchbar to clear on click. Or boolean property to clear the first found Searchbar
cardOpenstring
boolean
CSS selector of the expandable card to open on click. Or boolean to open first found expandable card
cardClosestring
boolean
CSS selector of the expandable card to close on click. Or boolean property to close currently opened expandable card
cardPreventOpenbooleanClick on element with this prop won’t open its parent expandable card
menuClosebooleanCloses Menu dropdown on click

Treeview Events

EventDescription
<TreeviewItem> events
clickEvent will be triggeres when user clicks on treeview item
treeviewOpenEvent will be triggered on item open
treeviewCloseEvent will be triggered on item close
treeviewLoadChildrenEvent 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 Svelte component (<TreeviewItem>) 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
  1. <TreeviewItem label="Item 1">
  2. <img src="path-to-my-image.jpg" slot="media">
  3. <div slot="root-start">Root Start</div>
  4. <div slot="root">Root End</div>
  5. <div slot="content-start">Content Start</div>
  6. <div slot="content">Content End</div>
  7. <span slot="label-start">Before Label</span>
  8. <TreeviewItem label="Sub Item 1" />
  9. ...
  10. </TreeviewItem>
  11. <!-- Renders to: -->
  12. <div class="treeview-item">
  13. <div class="treeview-item-root">
  14. <div>Root Start</div>
  15. <div class="treeview-toggle"></div>
  16. <div class="treeview-item-content">
  17. <div>Content Start</div>
  18. <img src="path-to-my-image.jpg">
  19. <div class="treeview-item-label">
  20. <span>Before Label</span>
  21. Item 1
  22. </div>
  23. <div>Content End</div>
  24. </div>
  25. </div>
  26. <div class="treeview-item-children">
  27. <div class="treeview-item">
  28. <div class="treeview-item-root">
  29. <div class="treeview-item-content">
  30. <div class="treeview-item-label">Sub Item 1</div>
  31. </div>
  32. </div>
  33. </div>
  34. ...
  35. </div>
  36. <div>Root End</div>
  37. </div>

Examples

  1. <Page>
  2. <Navbar title="Treeview" />
  3. <BlockTitle>Basic tree view</BlockTitle>
  4. <Block strong class="no-padding-horizontal">
  5. <Treeview>
  6. <TreeviewItem label="Item 1">
  7. <TreeviewItem label="Sub Item 1">
  8. <TreeviewItem label="Sub Sub Item 1" />
  9. <TreeviewItem label="Sub Sub Item 2" />
  10. </TreeviewItem>
  11. <TreeviewItem label="Sub Item 2">
  12. <TreeviewItem label="Sub Sub Item 1" />
  13. <TreeviewItem label="Sub Sub Item 2" />
  14. </TreeviewItem>
  15. </TreeviewItem>
  16. <TreeviewItem label="Item 2">
  17. <TreeviewItem label="Sub Item 1">
  18. <TreeviewItem label="Sub Sub Item 1" />
  19. <TreeviewItem label="Sub Sub Item 2" />
  20. </TreeviewItem>
  21. <TreeviewItem label="Sub Item 2">
  22. <TreeviewItem label="Sub Sub Item 1" />
  23. <TreeviewItem label="Sub Sub Item 2" />
  24. </TreeviewItem>
  25. </TreeviewItem>
  26. <TreeviewItem label="Item 3" />
  27. </Treeview>
  28. </Block>
  29. <BlockTitle>With icons</BlockTitle>
  30. <Block strong class="no-padding-horizontal">
  31. <Treeview>
  32. <TreeviewItem label="images" iconF7="folder_fill">
  33. <TreeviewItem label="avatar.png" iconF7="photo_fill" />
  34. <TreeviewItem label="background.jpg" iconF7="photo_fill" />
  35. </TreeviewItem>
  36. <TreeviewItem label="documents" iconF7="folder_fill">
  37. <TreeviewItem label="cv.docx" iconF7="doc_text_fill" />
  38. <TreeviewItem label="info.docx" iconF7="doc_text_fill" />
  39. </TreeviewItem>
  40. <TreeviewItem label=".gitignore" iconF7="logo_github" />
  41. <TreeviewItem label="index.html" iconF7="doc_text_fill" />
  42. </Treeview>
  43. </Block>
  44. <BlockTitle>With checkboxes</BlockTitle>
  45. <Block strong class="no-padding-horizontal">
  46. <Treeview>
  47. <TreeviewItem label="images" iconF7="folder_fill">
  48. <span slot="content-start">
  49. <Checkbox
  50. checked={Object.values(checkboxes.images).indexOf(false) < 0}
  51. indeterminate={Object.values(checkboxes.images).indexOf(false) >= 0 && Object.values(checkboxes.images).indexOf(true) >= 0}
  52. onChange={(e) => {
  53. Object.keys(checkboxes.images).forEach(k => checkboxes.images[k] = e.target.checked);
  54. checkboxes = checkboxes;
  55. }}
  56. />
  57. </span>
  58. <TreeviewItem label="avatar.png" iconF7="photo_fill" toggle={false}>
  59. <span slot="content-start">
  60. <Checkbox
  61. checked={checkboxes.images['avatar.png']}
  62. onChange={(e) => {
  63. checkboxes.images['avatar.png'] = e.target.checked;
  64. checkboxes = checkboxes;
  65. }}
  66. />
  67. </span>
  68. </TreeviewItem>
  69. <TreeviewItem label="background.jpg" iconF7="photo_fill" toggle={false}>
  70. <span slot="content-start">
  71. <Checkbox
  72. checked={checkboxes.images['background.jpg']}
  73. onChange={(e) => {
  74. checkboxes.images['background.jpg'] = e.target.checked;
  75. checkboxes = checkboxes;
  76. }}
  77. />
  78. </span>
  79. </TreeviewItem>
  80. </TreeviewItem>
  81. <TreeviewItem label="documents" iconF7="folder_fill">
  82. <span slot="content-start">
  83. <Checkbox
  84. checked={Object.values(checkboxes.documents).indexOf(false) < 0}
  85. indeterminate={Object.values(checkboxes.documents).indexOf(false) >= 0 && Object.values(checkboxes.documents).indexOf(true) >= 0}
  86. onChange={(e) => {
  87. Object.keys(checkboxes.documents).forEach(k => checkboxes.documents[k] = e.target.checked);
  88. checkboxes = checkboxes;
  89. }}
  90. />
  91. </span>
  92. <TreeviewItem label="cv.docx" iconF7="doc_text_fill" toggle={false}>
  93. <span slot="content-start">
  94. <Checkbox
  95. checked={checkboxes.documents['cv.docx']}
  96. onChange={(e) => {
  97. checkboxes.documents['cv.docx'] = e.target.checked;
  98. checkboxes = checkboxes;
  99. }}
  100. />
  101. </span>
  102. </TreeviewItem>
  103. <TreeviewItem label="info.docx" iconF7="doc_text_fill" toggle={false}>
  104. <span slot="content-start">
  105. <Checkbox
  106. checked={checkboxes.documents['info.docx']}
  107. onChange={(e) => {
  108. checkboxes.documents['info.docx'] = e.target.checked;
  109. checkboxes = checkboxes;
  110. }}
  111. />
  112. </span>
  113. </TreeviewItem>
  114. </TreeviewItem>
  115. <TreeviewItem label=".gitignore" iconF7="logo_github" toggle={false}>
  116. <span slot="content-start">
  117. <Checkbox checked={checkboxes['.gitignore']} onChange={(e) => {
  118. checkboxes['.gitignore'] = e.target.checked;
  119. checkboxes = checkboxes;
  120. }}/>
  121. </span>
  122. </TreeviewItem>
  123. <TreeviewItem label="index.html" iconF7="doc_text_fill" toggle={false}>
  124. <span slot="content-start">
  125. <Checkbox checked={checkboxes['index.html']} onChange={(e) => {
  126. checkboxes['index.html'] = e.target.checked;
  127. checkboxes = checkboxes;
  128. }}/>
  129. </span>
  130. </TreeviewItem>
  131. </Treeview>
  132. </Block>
  133. <BlockTitle>Whole item as toggle</BlockTitle>
  134. <Block strong class="no-padding-horizontal">
  135. <Treeview>
  136. <TreeviewItem itemToggle label="images" iconF7="folder_fill">
  137. <TreeviewItem label="avatar.png" iconF7="photo_fill" />
  138. <TreeviewItem label="background.jpg" iconF7="photo_fill" />
  139. </TreeviewItem>
  140. <TreeviewItem itemToggle label="documents" iconF7="folder_fill">
  141. <TreeviewItem label="cv.docx" iconF7="doc_text_fill" />
  142. <TreeviewItem label="info.docx" iconF7="doc_text_fill" />
  143. </TreeviewItem>
  144. <TreeviewItem label=".gitignore" iconF7="logo_github" />
  145. <TreeviewItem label="index.html" iconF7="doc_text_fill" />
  146. </Treeview>
  147. </Block>
  148. <BlockTitle>Selectable</BlockTitle>
  149. <Block strong class="no-padding-horizontal">
  150. <Treeview>
  151. <TreeviewItem
  152. selectable
  153. selected={selectedItem === 'images'}
  154. label="images"
  155. iconF7="folder_fill"
  156. onClick={(e) => toggleSelectable(e, 'images')}
  157. >
  158. <TreeviewItem
  159. selectable
  160. selected={selectedItem === 'avatar.png'}
  161. label="avatar.png"
  162. iconF7="photo_fill"
  163. onClick={(e) => toggleSelectable(e, 'avatar.png')}
  164. />
  165. <TreeviewItem
  166. selectable
  167. selected={selectedItem === 'background.jpg'}
  168. label="background.jpg"
  169. iconF7="photo_fill"
  170. onClick={(e) => toggleSelectable(e, 'background.jpg')}
  171. />
  172. </TreeviewItem>
  173. <TreeviewItem
  174. selectable
  175. selected={selectedItem === 'documents'}
  176. label="documents"
  177. iconF7="folder_fill"
  178. onClick={(e) => toggleSelectable(e, 'documents')}
  179. >
  180. <TreeviewItem
  181. selectable
  182. selected={selectedItem === 'cv.docx'}
  183. label="cv.docx"
  184. iconF7="doc_text_fill"
  185. onClick={(e) => toggleSelectable(e, 'cv.docx')}
  186. />
  187. <TreeviewItem
  188. selectable
  189. selected={selectedItem === 'info.docx'}
  190. label="info.docx"
  191. iconF7="doc_text_fill"
  192. onClick={(e) => toggleSelectable(e, 'info.docx')}
  193. />
  194. </TreeviewItem>
  195. <TreeviewItem
  196. selectable
  197. selected={selectedItem === '.gitignore'}
  198. label=".gitignore"
  199. iconF7="logo_github"
  200. onClick={(e) => toggleSelectable(e, '.gitignore')}
  201. />
  202. <TreeviewItem
  203. selectable
  204. selected={selectedItem === 'index.html'}
  205. label="index.html"
  206. iconF7="doc_text_fill"
  207. onClick={(e) => toggleSelectable(e, 'index.html')}
  208. />
  209. </Treeview>
  210. </Block>
  211. <BlockTitle>Preload children</BlockTitle>
  212. <Block strong class="no-padding-horizontal">
  213. <Treeview>
  214. <TreeviewItem
  215. toggle
  216. loadChildren
  217. iconF7="person_2_fill"
  218. label="Users"
  219. onTreeviewLoadChildren={(el, done) => loadChildren(done)}
  220. >
  221. {#each loadedChildren as item, index (index)}
  222. <TreeviewItem
  223. iconF7="person_fill"
  224. label={item.name}
  225. />
  226. {/each}
  227. </TreeviewItem>
  228. </Treeview>
  229. </Block>
  230. <BlockTitle>With links</BlockTitle>
  231. <Block strong class="no-padding-horizontal">
  232. <Treeview>
  233. <TreeviewItem iconF7="square_grid_2x2_fill" itemToggle label="Modals">
  234. <TreeviewItem link="/popup/" iconF7="link" label="Popup" />
  235. <TreeviewItem link="/dialog/" iconF7="link" label="Dialog" />
  236. <TreeviewItem link="/action-sheet/" iconF7="link" label="Action Sheet" />
  237. </TreeviewItem>
  238. <TreeviewItem iconF7="square_grid_2x2_fill" itemToggle label="Navigation Bars">
  239. <TreeviewItem link="/navbar/" iconF7="link" label="Navbar" />
  240. <TreeviewItem link="/toolbar-tabbar/" iconF7="link" label="Toolbar & Tabbar" />
  241. </TreeviewItem>
  242. </Treeview>
  243. </Block>
  244. </Page>
  245. <script>
  246. import { f7, Page, Navbar, BlockTitle, Block, Treeview, TreeviewItem, Checkbox } from 'framework7-svelte';
  247. let checkboxes = {
  248. images: {
  249. 'avatar.png': false,
  250. 'background.jpg': false,
  251. },
  252. documents: {
  253. 'cv.docx': false,
  254. 'info.docx': false,
  255. },
  256. '.gitignore': false,
  257. '.index.html': false,
  258. };
  259. let selectedItem = null;
  260. let loadedChildren = [];
  261. function toggleSelectable(e, item) {
  262. var $ = f7.$;
  263. if ($(e.target).is('.treeview-toggle')) return;
  264. selectedItem = item;
  265. }
  266. function loadChildren(done) {
  267. setTimeout(function () {
  268. // call done() to hide preloader
  269. done();
  270. loadedChildren = [
  271. {
  272. name: 'John Doe',
  273. },
  274. {
  275. name: 'Jane Doe',
  276. },
  277. {
  278. name: 'Calvin Johnson',
  279. },
  280. ];
  281. }, 2000);
  282. }
  283. </script>

← Toolbar / Tabbar

View →