Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

react-native-tree-multi-select

JairajJangle1.1kMIT1.9.4TypeScript support: included

A super-fast, customizable tree view component for React Native with multi-selection, checkboxes, and search filtering capabilities.

react-native, ios, android, react-component, treeview, tree-view, tree-select, checkbox, react-tree-view, react-tree-select, react-checkbox-tree, react-native-tree-view, react-native-tree-select, react-native-checkbox-list, react-native-tree-checkbox, tree-structure, hierarchical-list, collapsible-list, nested-list, multi-select, dropdown-menu, expandable-list, customizable, expo, web

readme

react-native-tree-multi-select

⚡️Super-fast Tree view with multi-selection capabilities, using checkboxes and search filtering.

npm version License Workflow Status cov Android iOS Web GitHub issues TS Known Vulnerabilities Expo Snack npm bundle size

Expand/collapse demo Search demo Customization demo

Installation

Using yarn:

yarn add react-native-tree-multi-select

using npm:

npm install react-native-tree-multi-select

Dependencies that need to be installed for this library to work:

  1. @shopify/flash-list
  2. react-native-paper
  3. react-native-vector-icons

Make sure to follow the native-related installation instructions for these dependencies.

Highlighted Features

  • Fast: Designed with performance in mind for smooth scrolling and quick selections.
  • 🛠️ Highly Customizable: Modify styles, behavior, and use your custom list component to suit your application's needs.
  • 🔍 Filterable: Quickly filter through tree nodes and option to select and un-select only the filtered tree nodes.
  • Well Tested: Comprehensive test coverage to ensure reliability and stability.
  • 📚 Well Documented: Detailed documentation to get you started and an example app to demo all the features.
  • 🌳 Multi-Level Selection: Select individual nodes or entire branches with ease.
  • 📦 Supports Large Datasets: Efficiently handles large trees without much performance degradation.
  • 🔒 TypeScript Support: Full TypeScript support for better developer experience.
  • 💻 Cross-Platform: Works seamlessly across iOS, Android, and web (with React Native Web).

Usage

import {
  TreeView,
  type TreeNode,
  type TreeViewRef
} from 'react-native-tree-multi-select';

// Refer to the Properties table below or the example app for the TreeNode type
const myData: TreeNode[] = [...];

export function TreeViewUsageExample(){
  const treeViewRef = React.useRef<TreeViewRef | null>(null);

  // It's recommended to use debounce for the search function (refer to the example app)
  function triggerSearch(text: string){
    // Pass search text to the tree along with the keys on which search is to be done(optional)
    treeViewRef.current?.setSearchText(text, ["name"]);
  }

  // Callback functions for check and expand state changes:
  const handleSelectionChange = (
      _checkedIds: string[],
      _indeterminateIds: string[]
  ) => {
      // NOTE: Handle _checkedIds and _indeterminateIds here
  };
  const handleExpanded = (expandedIds: string[]) => {
    // NOTE: Do something with updated expandedIds here
  };

  // Expand collapse calls using ref
  const expandAllPress = () => treeViewRef.current?.expandAll?.();
  const collapseAllPress = () => treeViewRef.current?.collapseAll?.();
  const expandNodes = (idsToExpand: string[]) => treeViewRef.current?.expandNodes?.(
    idsToExpand
  );
  const collapseNodes = (idsToCollapse: string[]) => treeViewRef.current?.collapseNodes?.(
    idsToCollapse
  );

  // Multi-selection function calls using ref
  const onSelectAllPress = () => treeViewRef.current?.selectAll?.();
  const onUnselectAllPress = () => treeViewRef.current?.unselectAll?.();
  const onSelectAllFilteredPress = () => treeViewRef.current?.selectAllFiltered?.();
  const onUnselectAllFilteredPress = () => treeViewRef.current?.unselectAllFiltered?.();
  const selectNodes = (idsToExpand: string[]) => treeViewRef.current?.selectNodes?.(
    idsToSelect
  );
  const unselectNodes = (idsToCollapse: string[]) => treeViewRef.current?.unselectNodes?.(
    idsToUnselect
  );

  return(
    // ... Remember to keep a fixed height for the parent. Read Flash List docs to know why
    <TreeView
      ref={treeViewRef}
      data={myData}
      onCheck={handleSelectionChange}
      onExpand={handleExpanded}
    />
  );
}

Properties

TreeViewProps<ID = string>

The TreeViewProps interface defines the properties for the tree view component.

Property Type Required Description
data TreeNode<ID = string>[] Yes An array of TreeNode objects
onCheck (checkedIds: ID[], indeterminateIds: ID[]) => void No Callback when a checkbox state changes
onExpand (expandedIds: ID[]) => void No Callback when a node is expanded
preselectedIds ID[] No An array of ids that should be pre-selected
preExpandedIds ID[] No An array of ids that should be pre-expanded
selectionPropagation SelectionPropagation No Control Selection Propagation Behavior. Choose whether you want to auto-select children or parents.
initialScrollNodeID ID No Set node ID to scroll to intiially on tree view render.
indentationMultiplier number No Indentation (marginStart) per level (defaults to 15)
treeFlashListProps TreeFlatListProps No Props for the flash list
checkBoxViewStyleProps BuiltInCheckBoxViewStyleProps No Props for the checkbox view
CheckboxComponent ComponentType<CheckBoxViewProps> No A custom checkbox component. Defaults to React Native Paper's Checkbox
ExpandCollapseIconComponent ComponentType<ExpandIconProps> No A custom expand/collapse icon component
ExpandCollapseTouchableComponent ComponentType<TouchableOpacityProps> No A custom expand/collapse touchable component
CustomNodeRowComponent React.ComponentType<NodeRowProps<ID>> No Custom row item component
Notes
  • The ID type parameter allows flexibility in specifying the type of node identifiers (e.g., string, number, or custom types).
  • ℹ️ If CustomNodeRowComponent is provided then below props are not applied:

    1. indentationMultiplier
    2. checkBoxViewStyleProps
    3. CheckboxComponent
    4. BuiltInCheckBoxViewStyleProps
    5. ExpandCollapseIconComponent
    6. ExpandCollapseTouchableComponent.
  • ⚠️ If the tree view doesn't scroll if rendered in a complex nested scroll view/s then try setting the renderScrollComponent value in treeFlashListProps to ScrollView from react-native-gesture-handler.


TreeNode<ID = string>

The TreeNode interface defines the properties for individual item of the tree view

Property Type Required Description
id ID (default: string) Yes Unique identifier for the node
name string Yes The display name of the node
children TreeNode<ID>[] No An array of child TreeNode<ID> objects
[key: string] any No Any additional properties for the node
(May be useful to perform search on)

TreeViewRef<ID = string>

The TreeViewRef interface defines the properties for the ref object of the tree view component

Property Type Description
selectAll () => void Selects all nodes
unselectAll () => void Unselects all nodes
selectAllFiltered () => void Selects all filtered nodes
unselectAllFiltered () => void Unselects all filtered nodes
expandAll () => void Expands all nodes
collapseAll () => void Collapses all nodes
expandNodes (ids: ID[]) => void Expands specified nodes
collapseNodes (ids: ID[]) => void Collapses specified nodes
selectNodes (ids: ID[]) => void Selects specified nodes
unSelectNodes (ids: ID[]) => void Unselects specified nodes
setSearchText (searchText: string, searchKeys?: string[]) => void Set the search text and optionally the search keys. Default search key is "name"

Recommended to call this inside a debounced function if you find any performance issue otherwise.
scrollToNodeID (params:ScrollToNodeParams<ID>) => void; Scrolls the tree view to the node of the specified ID.
getChildToParentMap () => Map<ID, ID> Get the child to parent tree view map.

ScrollToNodeParams

Property Type Required Description
nodeId ID Yes Node ID to expand and scroll to.
expandScrolledNode boolean No Whether to expand scrolled node to reveal its children. Defaults to false.
animated boolean No Control if scrolling should be animated.
viewOffset number No A fixed number of pixels to offset the scrolled node position.
viewPosition number No A value of 0 places the scrolled node item at the top, 1 at the bottom, and 0.5 centered in the middle.

SelectionPropagation

The SelectionPropagation interface defines the selection propagation behaviour of the tree view

Property Type Required Description
toChildren boolean No Whether to propagate selection to children nodes. Defaults to true.
toParents boolean No Whether to propagate selection to parent nodes. Defaults to true.

TreeFlatListProps

All properties of FlashListProps(from @shopify/flash-list) except for data and renderItem


BuiltInCheckBoxViewStyleProps

This interface allows you to customize the style of the built-in checkbox component that is rendered in the tree view by default. Overriden if CustomNodeRowComponent is used.

Property Type Required Description
outermostParentViewStyle StyleProp<ViewStyle> No Optional style modifier for the outermost parent view.
checkboxParentViewStyle StyleProp<ViewStyle> No Optional style modifier for the checkbox parent view.
textTouchableStyle StyleProp<ViewStyle> No Optional style modifier for the text touchable style.
checkboxProps CheckboxProps No Optional props for the checkbox component.
textProps TextProps
(React Native)
No Optional props for the text component.

CheckboxProps

All properties of RNPaperCheckboxAndroidProps(from react-native-paper) except for onPress and status


CheckBoxViewProps

Property Type Required Description
value CheckboxValueType Yes The current value of the checkbox
onValueChange (value: boolean) => void Yes Function to be called when the checkbox is pressed
text string Yes The display text besides the checkbox

CheckboxValueType

Type: boolean OR "indeterminate"


ExpandIconProps

Property Type Required Description
isExpanded boolean Yes Indicates if the icon is expanded

NodeRowProps<ID = string>

Property Type Required Description
node TreeNode Yes The node to be rendered
level number Yes The depth of the node in the tree
checkedValue CheckboxValueType Yes The current value of the checkbox
isExpanded boolean Yes Whether the node is expanded or not
onCheck () => void Yes Function to be called when the checkbox is pressed
onExpand () => void Yes Function to be called when the expand button is pressed

🙌 Planned features

  • <input checked="" disabled="" type="checkbox"> Row Item full-customization
  • <input checked="" disabled="" type="checkbox"> Prop to control auto children and parents selection. Can now be done using selectionPropagation prop 🎉
  • <input disabled="" type="checkbox"> Prop to set the maximum checked item limit
  • <input disabled="" type="checkbox"> Prop to disable certain nodes from getting checked
  • <input checked="" disabled="" type="checkbox"> Ref function to programatically expand/collapse a certain node
  • <input checked="" disabled="" type="checkbox"> Ref function to programatically un/check a certain node
  • <input checked="" disabled="" type="checkbox"> Ref function to auto-scroll to a certain node's position - available in 1.9.0+

If you do not see what you want in the planned feature list, raise a feature request.


💡 Some Expo Snack Examples

  1. Radio button like selection in tree view: Snack link
  2. Display count of number of checked nodes: Snack link

Contributing

See the contributing guide to learn how to contribute to the repository and the development workflow.

License

MIT

🙏 Support the project

LiberPay_Donation_Button           Paypal_Donation_Button           Paypal_Donation_Button

❤️ Thanks to


changelog

1.9.4 (2025-04-04)

Bug Fixes

  • removed postinstall script and moved patch-package to bootstrap script (d400ea8)

1.9.3 (2025-03-12)

Bug Fixes

  • added missing changes for lodash removal (d42cafc)

Performance Improvements

  • replaced lodash isEqual with fast-is-equal potentially reducing package size (a166c31)

1.9.2 (2025-03-12)

Bug Fixes

  • upgraded zustand to v5 and upgraded other deps (b308de6)

1.9.1 (2025-02-15)

Bug Fixes

1.9.0 (2025-02-14)

Features

  • added ref method to get child to parent map used in the tree view (e496a70)
  • added scroll to node id feature (1f87730)
  • added scroll to node id feature (38d7236)
  • updated example app with new scroll to node id feature (db8dcdd)

1.9.0-beta.1 (2025-02-06)

Features

  • added ref method to get child to parent map used in the tree view (e496a70)
  • added scroll to node id feature (1f87730)
  • added scroll to node id feature (38d7236)
  • updated example app with new scroll to node id feature (db8dcdd)

1.8.1 (2025-02-02)

Bug Fixes

  • upgrade react-native-paper from 5.12.5 to 5.13.1 (36daeea)

1.8.0 (2025-01-17)

Features

  • force release: updated readme (508a45f)

1.7.1 (2025-01-17)

Bug Fixes

  • ci android setup potential fix (fe9b562)

1.7.0 (2024-12-22)

Bug Fixes

  • fixed updated data state not reflecting due to issues in deep compare effect (fb5a745)

Features

  • made data prop reactive (f5f3699)

1.7.0-beta.2 (2024-12-19)

Bug Fixes

  • fixed updated data state not reflecting due to issues in deep compare effect (fb5a745)

Performance Improvements

  • optimized flatten tree helper func (012f981)

1.6.1 (2024-12-17)

Performance Improvements

Features

  • made data prop reactive (f5f3699)

1.6.0 (2024-12-07)

Features

  • #78 added initial support to allow use of multiple tree view components simultaneously (2123101)

1.6.0-beta.1 (2024-11-16)

Features

  • #78 added initial support to allow use of multiple tree view components simultaneously (2123101)

1.5.1 (2024-10-20)

Bug Fixes

  • upgraded example app deps and package details in package json (3472516)

1.5.0 (2024-10-13)

Bug Fixes

  • fixed parent does not get unchecked if all children are unchecked at once in filtered tree (cf2195b)
  • trigger patch release for refactor (c3b9a71)

Features

  • added prop and state to control parent <-> child selection propagation (#81) (4714525)
  • updated toggle checkbox helpers for controlled parent <-> child selection propagation (#81) (9acbca2)

Performance Improvements

  • replaced recursive logic with iterative logic to handle tree expand collapse (b417057)

1.5.0-beta.3 (2024-10-13)

Bug Fixes

  • fixed parent does not get unchecked if all children are unchecked at once in filtered tree (cf2195b)

Performance Improvements

  • replaced recursive logic with iterative logic to handle tree expand collapse (b417057)

1.5.0-beta.2 (2024-10-12)

Bug Fixes

  • trigger patch release for refactor (c3b9a71)

1.5.0-beta.1 (2024-10-08)

Features

  • added prop and state to control parent <-> child selection propagation (#81) (4714525)
  • updated toggle checkbox helpers for controlled parent <-> child selection propagation (#81) (9acbca2)

1.4.1 (2024-08-28)

Bug Fixes

1.4.0 (2024-08-20)

Features

  • added indeterminate state ids to onCheck callback (204b9a0)

1.3.3 (2024-08-03)

Performance Improvements

  • optimized state usage using useShallow and memoization (0c8d9c6)

1.3.2 (2024-06-09)

Bug Fixes

  • deps: update dependency react-native-safe-area-context to v4.10.4 (89db0eb)

1.3.1 (2024-05-20)

Bug Fixes

  • workflow action not upgrading package json version (e51cbd7)

1.3.0 (2024-05-20)

Features

  • added ref function to check/uncheck node ids (caec003)

1.2.8 (2024-05-11)

Bug Fixes

  • semantic_release: remove duplicate release config from package json and updated lock files (dcf432d)

Changelog

All notable changes to this project will be documented in this file. Dates are displayed in UTC.

Generated by auto-changelog.

1.2.6

6 May 2024

v1.2.6

6 May 2024

  • chore: updated gh action npm publish steps #28

1.2.5

6 May 2024

v1.2.5

6 May 2024

  • chore: updated gh action to have write permission to contents to allow tag writing #27
  • chore: added permission to npm publish job #26
  • chore: used yarn install instead of npm ci as the yarn lock file is already present #25
  • chore: removed npm install in favor of npm ci in gh action #24
  • chore: updated gh actions to ignore peer deps in npm install #23
  • chore: kept npm package lock in sync before ci #22
  • chore: added npm publish provenance to gh action #21
  • chore: added npm publish provenance to gh action #20
  • Update CHANGELOG.md for version [skip ci] 78f3754

1.2.3

6 May 2024

v1.2.3

5 May 2024

  • chore: remove unnecessary package json add in github action #19
  • chore: added git pull after cahngelogs push in gh actions #18
  • chore: prevent auto version increment in github actions #17
  • chore: added npm publish to github actions #16
  • Update CHANGELOG.md for version 1.2.3 [skip ci] f398a87
  • chore: added auto changelogs package 837bcd3

v1.2.1

2 May 2024

  • Feature/expand collapse control #15
  • build: cleaned build and updated lock files 363cbd0
  • feat: add functions to expand/collapse nodes by ref or pre-expanded ids 1f8569b
  • fix: removed flipper config from example Podfile 277a16e

v1.2.0

1 May 2024

v1.1.2

20 October 2023

  • fix: updated nvmrc to use node v20 #13
  • chore(deps): bump @babel/traverse from 7.22.6 to 7.23.2 #12
  • fix: updated broken lock files 21fdf25
  • chore: updated pod and yarn lock files 7a8fd1d
  • chore(deps): bump @babel/traverse from 7.22.6 to 7.23.2 in /example 3a8860e

v1.1.1

20 July 2023

  • fix: fixed code outside src causing built folder path mismatch 699159f
  • chore: release 1.1.1 36c9cef

v1.1.0

20 July 2023

  • chore: attempt 2 to fix coverage workflow action #9
  • Prep/release 1 0 0 #8
  • chore(deps): bump word-wrap from 1.2.3 to 1.2.4 #5
  • chore(deps): bump semver from 5.7.1 to 5.7.2 #6
  • Prep/release 1 0 0 #4
  • chore(deps): bump semver from 5.7.1 to 5.7.2 in /example #7
  • chore: replaced hardcoded sample data with dynamically gen data a36e177
  • fix: added missing custom screen files 1809b5d
  • feat: added app showcase template for example app 0000eae

v0.8.11

15 July 2023

  • test: added selectAll helpers to test case and made 100% test coverage 7913f8b
  • chore: release 0.8.11 163df1b

v0.8.10

15 July 2023

  • test: added test cases for helper functions and zustand store 20dfaeb
  • chore: cleanup: seperated some functions from component file into helper file 10ef9ec
  • fix: recursive rendering due to useffect dependency issue 0df57db

v0.8.9

12 July 2023

  • chore: corrected checkbox view style prop types and updated readme 101a600
  • chore: release 0.8.9 c09d1db

v0.8.8

12 July 2023

  • chore: removed unnecessary native files and added indentation multiplier customization prop 409acc5
  • chore: release 0.8.8 76ca8ab

v0.8.7

11 July 2023

  • fix: fixed special single child condition check a2c40ef
  • chore: release 0.8.7 5f3646f

v0.8.6

11 July 2023

v0.8.5

10 July 2023

v0.8.3

10 July 2023

  • fix: transitioned from preact signal to zustand state #3
  • fix: transitioned from preact signal to zustand state due to experimental nature of signals in RN a1bf158
  • chore: updated readme and version bump af493c3
  • chore: ci ios build failure fixes 892f621

v0.5.4

10 July 2023

v0.5.3

10 July 2023

v0.5.2

10 July 2023

  • chore: updated keywords to package json fce3d13
  • chore: release 0.5.2 8a37d68
  • chore: version bump e5d80f0

v0.5.0

10 July 2023

  • Significant performance optimizations in tree filtering and selection and some more feature #2
  • Performance improvements and added many features #1
  • chore: updated readme file dc183f6
  • perf: major optimizations and added expand/collapse functionality 341c982
  • feat: initial commit 7186ca0