Treeview - 图1

Treeview React Component

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