Socket
Socket
Sign inDemoInstall

intelligent-tree-select

Package Overview
Dependencies
15
Maintainers
2
Versions
71
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    intelligent-tree-select

React tree select component based on [react-select](https://github.com/JedWatson/react-select#react-select) with [react-window](https://github.com/bvaughn/react-window)-based rendering of options.


Version published
Weekly downloads
125
decreased by-5.3%
Maintainers
2
Created
Weekly downloads
 

Readme

Source

Intelligent-tree-select

React tree select component based on react-select and virtualization with react-window.

Before start

Before you can use this component you will need Node.js in version 14+, but we recommend using the latest available version.

Getting started

Easiest way is to install via NPM

npm install intelligent-tree-select --save

Then import it

import { IntelligentTreeSelect } from "intelligent-tree-select"
import "intelligent-tree-select/lib/styles.css"

Usage example can be found in examples/demo.js

Intelligent Tree Select Props

Props types are the same as the ones introduced by react-select.

Additional parameters introduced by intelligent-tree-select are:

PropertyTypeDefault ValueDescription
fetchOptionsfunc-Function used to fetch options. See below for argument description.
fetchLimitnumber100Size of a page loaded in one request via fetchOptions
searchDelaynumber-Delay in milliseconds between the input change and fetchOptions invocation. Allows to wait for reasonable user input before actually invoking search on the server. By default the search is invoked with no delay.
optionsArray<Object>-Options to render in the menu list. If fetchOptions is not specified (it takes precedence over this property if specified), this property can be used to provide options to select from. Note that it is recommended to memoize them.
expandedboolfalsewhether the options are expanded by default
isMenuOpenboolfalseWhether the menu is open. Setting this to true force menu to me always opened
multibooltrueWhether multiple selection is supported
maxHeightnumber300Maximum height of the dropdown menu
minHeightnumber0Minimum height of the dropdown menu
optionRendererReact component/func-overriding built-in option render component
valueRendererReact component/func-overriding built-in value render component. Receives the selected option's label and the option itself as parameter (works for both multi and single select).
optionHeightnumber or func25pxOption height. Dynamic height can be supported via a function with the signature ({ option: Object }): number
optionLeftOffsetnumber16pxOption base left offset. Left offset is calculated as depth level of the option * optionLeftOffset
renderAsTreebooltrueWhether options should be rendered as a tree.
noResultsTextstring-Text displayed when no matching options were found.
loadingTextstring-Text displayed while options are being loaded.
labelKeystring'label'Attribute of an option that contains the display text.
valueKeystring'value'Attribute of an option that represents the option's value.
childrenKeystring'children'Attribute of an option that represents its children.
getOptionLabelFunction-Function to extract label from an option. If specified, overrides labelKey.
onOptionCreatefunction-callback when the new option is created. Signature ({ option: Object}): none Currently disabled.
optionLifetimestring'5m'String representing how long the options should be cached. Syntax: XdXhXmXs where X is some number, d stands for days, h hours ,m minutes, s seconds.
simpleTreeDatabooltrueWhether the options are in a simple format. (One node == one option). In this case, children are just an array of identifiers (values).
namestring--Unique name for the component. Whenever this prop is set then the options will be cached.
valueIsControlledbooleantrueSets if the passed value is changed over time. If not, the value can be used only to set the initial values.
menuIsFloatingbooleantrueSets if the dropdown is rendered above content or as a part of it. Useful when isMenuOpen is true.
Fetch Options Function

The component can either be provided all options to render in props, or a function used to fetch options as necessary. This function should support:

  1. Searching by string (component input). If search string is provided, options should be provided including their ancestors.
  2. Paging
  3. Fetching children of a node

The function is passed an object with the following attributes:

AttributeTypeDescription
searchStringstringSearch string entered by the user. Possibly empty.
optionIDstringIdentifier of the option being expanded (whose children should be fetched). Possibly undefined/empty.
limitnumberNumber of options to fetch (page size). Based on fetchLimit property.
offsetnumberFetch offset.
optionobjectTh option being expanded. Possibly undefined.
Custom Option Renderer

You can override the built-in option renderer by specifying your own optionRenderer property. Your renderer should return a React element that represents the specified option. It will be passed the following named parameters:

PropertyTypeDescription
dataArray<Object>Options to render in the menu list.
keystringA unique identifier for each element created by the renderer.
optionStyleObjectPassed styles for option.
selectPropsSelectPropsProps of Select.
isFocusedboolWhether the option is focused.
isDisabledboolWhether the option is focused.
isSelectedboolWhether the option is selected.
SelectProps

If you override the optionRenderer the react-select props are passed in the selectProps property. It gives you access to the internals of the select. Some useful properties are listed below.

PropertyTypeDescription
childrenKeystringAttribute of option that contains the children key.
keystringA unique identifier for each element created by the renderer.
labelKeystringAttribute of option that contains the display text.
getOptionLabelFunctionFunction to extract label from an option. If specified, overrides labelKey.
renderAsTreeboolWhether the options should be render as a tree.
searchStringstringCurrent content of the search input.
onOptionSelectFunctionCallback to update the selected values; for example, you may want to call this function on click.
onOptionToggleFunctionExpand/Collapse option if it has children.
valueKeystringAttribute of option that contains the value.

IntelligentTreeSelect public API

The following methods can be called on instances of the intelligent-tree-select component (accessed via a ref).

MethodDescription
resetOptionsForce reloading of options when fetchOptions property is used to specify how to load options. If options are specified in props, this reloads them from the current props.
getOptionsGets the options (flattened) currently provided by the component.
focusFocus the tree select input.
blurInputBlur the tree select input.

Keywords

FAQs

Last updated on 03 Apr 2024

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc