# react-treeviewselect

> A react based select control where the drop down is a tree view.

Latest version **1.0.4** (published 2017-08-16) · MIT license · 0 weekly downloads

## Install

```sh
npm install react-treeviewselect
pnpm add react-treeviewselect
yarn add react-treeviewselect
bun add react-treeviewselect
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; esm support; no vulnerabilities.

Warnings: low downloads.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.4 |
| Published | 2017-08-16 |
| First published | 2017-08-14 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 3 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Cleve Littlefield |
| Maintainers | cleverguy25 |
| Keywords | react, tree, select |

## Links

- npm: https://www.npmjs.com/package/react-treeviewselect
- Repository: https://github.com/cleverguy25/react-treeviewselect
- Homepage: https://github.com/cleverguy25/react-treeviewselect#readme
- Issues: https://github.com/cleverguy25/react-treeviewselect/issues
- npm.io page: https://npm.io/package/react-treeviewselect

## Dependencies (3)

- [react](https://npm.io/package/react.md) ^15.6.1
- [classnames](https://npm.io/package/classnames.md) ^2.2.5
- [prop-types](https://npm.io/package/prop-types.md) ^15.5.10

## Alternatives

- [mobx-react](https://npm.io/package/mobx-react.md) — 2.8M weekly downloads
- [rc-tree](https://npm.io/package/rc-tree.md) — 2.6M weekly downloads
- [@react-oauth/google](https://npm.io/package/@react-oauth/google.md) — 1.3M weekly downloads
- [@wagmi/connectors](https://npm.io/package/@wagmi/connectors.md) — 877.0K weekly downloads
- [vee-validate](https://npm.io/package/vee-validate.md) — 836.4K weekly downloads

## Recent versions

- 1.0.4 (latest) — 2017-08-16
- 1.0.3 — 2017-08-16
- 1.0.2 — 2017-08-16
- 1.0.1 — 2017-08-15
- 1.0.0 — 2017-08-14

## README

# react-treeviewselect
A react based select control where the drop down is a tree view.

React/JS is not my first language, so open to suggestions for improvements as I have not seen a useful version of this control elsewhere, so I want this to be robust.

## Features

* Attempts to be [WAI-ARIA compliant](https://rawgit.com/w3c/aria-practices/master/aria-practices-DeletedSectionsArchive.html#autocomplete) compliant although not thoroughly tested.  Support for ARIA attributes and keyboard interactions.  Issues welcome
* Mobile friendly
* Full control over item rendering.
* Can use with any structure, as it uses callbacks for composing tree.
* Typescript typings.

## Installation

```shell
yarn add react-treeviewselect
```

or

```shell
npm install react-treeviewselect --save
```

## Basic Usage

```js
import { TreeViewSelect } from "react-treeviewselect";

function renderManagerLink(manager) {
    return <span
        key={manager.id}
    >
        {manager.name}
    </span>;
}

function renderSelectedManager(manager) {
    return <div className="d-inline-block">{manager.name}</div>;
}

function getChildren(item) {
    return item.reports;
}

function getParent(item) {
    return item.manager;
}

function getKey(item) {
    return item.id;
}

function onSelectedItemChange(item: IManager) {
    console.log(item.name);
}

class Example extends React.Component {
  constructor(props) {
        super(props);

        this.state = {};
        this.onSelectedItemChange = this.onSelectedItemChange.bind(this);
    }

  render() {

    return (
      <TreeViewSelect
                        style={{ width: "20rem" }}
                        defaultCollapsed={1}
                        renderSelectedItem={renderSelectedManager}
                        selectedItem={manager}
                        item={hierarchy.manager}
                        getChildren={getChildren}
                        getParent={getParent}
                        getKey={getKey}
                        renderItem={renderManagerLink}
                        onSelectedItemChange={onSelectedItemChange}
                    />
    );
  }
}
```

## Props

| Prop | Type | Required | Description |
| :--- | :--- | :---: | :--- |
| `className` | String | | Set a class name for outer TreeViewSelect element. |
| `style` | Object | | Sets a style for TreeViewSelect, can be useful to set a fixed width. |
| `defaultCollapsed` | Number | | Use this to define what level should default to collapsed.  Can be useful for big trees to keep just the first few levels open by default. |
| `renderSelectedItem` | Function | ✓ | How do we render the selected item. |
| `selectedItem` | Object | ✓ | Currently selected item. |
| `item` | Object | ✓ | Root node of the tree. |
| `getChildren` | Function | ✓ | Used on a node to get the children.  This allows a flexible data structure as input. |
| `getParent` | Function | ✓ | Get parent for an item.  This is used to make sure that selected items are not collapsed. |
| `getKey` | Function | ✓ | Get the key for a node.  Used for item equivalency as well as for React key. |
| `renderItem` | Function | ✓ | Used to render an item in the treeview. |
| `onSelectedItemChange` | Function | ✓ | Callback when the selected item changes. |


## License

[MIT](https://github.com/cleverguy25/react-treeviewselect/blob/master/LICENSE)

---
_Source: https://npm.io/package/react-treeviewselect · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
