Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ A lightweight and fast control to render a select component that can display hie
- [keepOpenOnSelect](#keepopenonselect)
- [mode](#mode)
- [multiSelect](#multiSelect)
- [hierarchical](#hierarchical)
- [simpleSelect](#simpleSelect)
- [radioSelect](#radioSelect)
- [showPartiallySelected](#showpartiallyselected)
Expand Down Expand Up @@ -327,7 +328,13 @@ Defines how the dropdown is rendered / behaves

#### multiSelect

This is the default mode. A multi selectable dropdown which supports hierarchical data.
A multi selectable dropdown which supports tree data with parent-child relationships. This is the default mode.

#### hierarchical

A multi selectable dropdown which supports tree data **without** parent-child relationships. In this mode, selecting a node has no ripple effects on its descendants or ancestors. Subsequently, `showPartiallySelected` becomes a moot flag and has no effect as well.

⚠️ Note that `hierarchical=true` negates/overrides `showPartiallySelected`.

#### simpleSelect

Expand Down
4 changes: 1 addition & 3 deletions docs/src/stories/Options/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ class WithOptions extends PureComponent {
showPartiallySelected,
disabled,
readOnly,
hierarchical,
} = this.state

return (
Expand All @@ -66,6 +65,7 @@ class WithOptions extends PureComponent {
<option value="multiSelect">Multi select</option>
<option value="simpleSelect">Simple select</option>
<option value="radioSelect">Radio select</option>
<option value="hierarchical">Hierarchical</option>
</select>
</div>
<Checkbox
Expand Down Expand Up @@ -94,7 +94,6 @@ class WithOptions extends PureComponent {
/>
<Checkbox label="Disabled" value="disabled" checked={disabled} onChange={this.onOptionsChange} />
<Checkbox label="Read Only" value="readOnly" checked={readOnly} onChange={this.onOptionsChange} />
<Checkbox label="Hierarchical" value="hierarchical" checked={hierarchical} onChange={this.onOptionsChange} />
</div>
<div>
<DropdownTreeSelect
Expand All @@ -110,7 +109,6 @@ class WithOptions extends PureComponent {
showPartiallySelected={showPartiallySelected}
disabled={disabled}
readOnly={readOnly}
hierarchical={hierarchical}
/>
</div>
</div>
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@
}
},
"lint-staged": {
"*.{js,json,css,md}": [
"*.{js,json,css,md,ts}": [
"prettier --write",
"git add -f"
]
Expand Down
10 changes: 4 additions & 6 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,10 @@ class DropdownTreeSelect extends Component {
onNodeToggle: PropTypes.func,
onFocus: PropTypes.func,
onBlur: PropTypes.func,
mode: PropTypes.oneOf(['multiSelect', 'simpleSelect', 'radioSelect']),
mode: PropTypes.oneOf(['multiSelect', 'simpleSelect', 'radioSelect', 'hierarchical']),
showPartiallySelected: PropTypes.bool,
disabled: PropTypes.bool,
readOnly: PropTypes.bool,
hierarchical: PropTypes.bool,
id: PropTypes.string,
}

Expand All @@ -67,12 +66,11 @@ class DropdownTreeSelect extends Component {
this.clientId = props.id || clientIdGenerator.get(this)
}

initNewProps = ({ data, mode, showPartiallySelected, hierarchical }) => {
initNewProps = ({ data, mode, showPartiallySelected }) => {
this.treeManager = new TreeManager({
data,
mode,
showPartiallySelected,
hierarchical,
rootPrefixId: this.clientId,
})
// Restore focus-state
Expand All @@ -94,8 +92,8 @@ class DropdownTreeSelect extends Component {
}

componentWillMount() {
const { data, hierarchical } = this.props
this.initNewProps({ data, hierarchical, ...this.props })
const { data, mode, showPartiallySelected } = this.props
this.initNewProps({ data, mode, showPartiallySelected })
}

componentWillUnmount() {
Expand Down
9 changes: 5 additions & 4 deletions src/tree-manager/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,24 @@ import nodeVisitor from './nodeVisitor'
import keyboardNavigation, { FocusActionNames } from './keyboardNavigation'

class TreeManager {
constructor({ data, mode, showPartiallySelected, hierarchical, rootPrefixId }) {
constructor({ data, mode, showPartiallySelected, rootPrefixId }) {
this._src = data
this.simpleSelect = mode === 'simpleSelect'
this.radioSelect = mode === 'radioSelect'
this.hierarchical = mode === 'hierarchical'
const { list, defaultValues, singleSelectedNode } = flattenTree({
tree: JSON.parse(JSON.stringify(data)),
simple: this.simpleSelect,
radio: this.radioSelect,
showPartialState: showPartiallySelected,
hierarchical,
hierarchical: this.hierarchical,
rootPrefixId,
})
this.tree = list
this.defaultValues = defaultValues
this.showPartialState = !hierarchical && showPartiallySelected
this.showPartialState = !this.hierarchical && showPartiallySelected
this.searchMaps = new Map()
this.hierarchical = hierarchical

if ((this.simpleSelect || this.radioSelect) && singleSelectedNode) {
// Remembers initial check on single select dropdowns
this.currentChecked = singleSelectedNode._id
Expand Down
2 changes: 1 addition & 1 deletion src/tree-node/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ class TreeNode extends PureComponent {
onNodeToggle: PropTypes.func,
onAction: PropTypes.func,
onCheckboxChange: PropTypes.func,
mode: PropTypes.oneOf(['multiSelect', 'simpleSelect', 'radioSelect']),
mode: PropTypes.oneOf(['multiSelect', 'simpleSelect', 'radioSelect', 'hierarchical']),
showPartiallySelected: PropTypes.bool,
readOnly: PropTypes.bool,
clientId: PropTypes.string,
Expand Down
2 changes: 1 addition & 1 deletion src/tree-node/node-label.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class NodeLabel extends PureComponent {
partial: PropTypes.bool,
disabled: PropTypes.bool,
dataset: PropTypes.object,
mode: PropTypes.oneOf(['multiSelect', 'simpleSelect', 'radioSelect']),
mode: PropTypes.oneOf(['multiSelect', 'simpleSelect', 'radioSelect', 'hierarchical']),
showPartiallySelected: PropTypes.bool,
onCheckboxChange: PropTypes.func,
readOnly: PropTypes.bool,
Expand Down
2 changes: 1 addition & 1 deletion src/tree/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class Tree extends Component {
onNodeToggle: PropTypes.func,
onAction: PropTypes.func,
onCheckboxChange: PropTypes.func,
mode: PropTypes.oneOf(['multiSelect', 'simpleSelect', 'radioSelect']),
mode: PropTypes.oneOf(['multiSelect', 'simpleSelect', 'radioSelect', 'hierarchical']),
showPartiallySelected: PropTypes.bool,
pageSize: PropTypes.number,
readOnly: PropTypes.bool,
Expand Down
2 changes: 1 addition & 1 deletion src/trigger/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class Trigger extends PureComponent {
disabled: PropTypes.bool,
readOnly: PropTypes.bool,
showDropdown: PropTypes.bool,
mode: PropTypes.oneOf(['multiSelect', 'simpleSelect', 'radioSelect']),
mode: PropTypes.oneOf(['multiSelect', 'simpleSelect', 'radioSelect', 'hierarchical']),
texts: PropTypes.object,
}

Expand Down
Loading