Skip to content

Commit 637fe66

Browse files
committed
refactor: Update mode to include hierarchical (#251)
BREAKING CHANGE: `hierarchical` prop `hierarchical` prop is now moved under `mode` prop. ``` // before <DropdownTreeSelect data={data} hierarchical={true} /> // after <DropdownTreeSelect data={data} mode="hierarchical" /> ```
1 parent 007602b commit 637fe66

File tree

10 files changed

+183
-170
lines changed

10 files changed

+183
-170
lines changed

README.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ A lightweight and fast control to render a select component that can display hie
5151
- [keepOpenOnSelect](#keepopenonselect)
5252
- [mode](#mode)
5353
- [multiSelect](#multiSelect)
54+
- [hierarchical](#hierarchical)
5455
- [simpleSelect](#simpleSelect)
5556
- [radioSelect](#radioSelect)
5657
- [showPartiallySelected](#showpartiallyselected)
@@ -327,7 +328,13 @@ Defines how the dropdown is rendered / behaves
327328

328329
#### multiSelect
329330

330-
This is the default mode. A multi selectable dropdown which supports hierarchical data.
331+
A multi selectable dropdown which supports tree data with parent-child relationships. This is the default mode.
332+
333+
#### hierarchical
334+
335+
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.
336+
337+
⚠️ Note that `hierarchical=true` negates/overrides `showPartiallySelected`.
331338

332339
#### simpleSelect
333340

docs/src/stories/Options/index.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ class WithOptions extends PureComponent {
4545
showPartiallySelected,
4646
disabled,
4747
readOnly,
48-
hierarchical,
4948
} = this.state
5049

5150
return (
@@ -66,6 +65,7 @@ class WithOptions extends PureComponent {
6665
<option value="multiSelect">Multi select</option>
6766
<option value="simpleSelect">Simple select</option>
6867
<option value="radioSelect">Radio select</option>
68+
<option value="hierarchical">Hierarchical</option>
6969
</select>
7070
</div>
7171
<Checkbox
@@ -94,7 +94,6 @@ class WithOptions extends PureComponent {
9494
/>
9595
<Checkbox label="Disabled" value="disabled" checked={disabled} onChange={this.onOptionsChange} />
9696
<Checkbox label="Read Only" value="readOnly" checked={readOnly} onChange={this.onOptionsChange} />
97-
<Checkbox label="Hierarchical" value="hierarchical" checked={hierarchical} onChange={this.onOptionsChange} />
9897
</div>
9998
<div>
10099
<DropdownTreeSelect
@@ -110,7 +109,6 @@ class WithOptions extends PureComponent {
110109
showPartiallySelected={showPartiallySelected}
111110
disabled={disabled}
112111
readOnly={readOnly}
113-
hierarchical={hierarchical}
114112
/>
115113
</div>
116114
</div>

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@
184184
}
185185
},
186186
"lint-staged": {
187-
"*.{js,json,css,md}": [
187+
"*.{js,json,css,md,ts}": [
188188
"prettier --write",
189189
"git add -f"
190190
]

src/index.js

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,10 @@ class DropdownTreeSelect extends Component {
4242
onNodeToggle: PropTypes.func,
4343
onFocus: PropTypes.func,
4444
onBlur: PropTypes.func,
45-
mode: PropTypes.oneOf(['multiSelect', 'simpleSelect', 'radioSelect']),
45+
mode: PropTypes.oneOf(['multiSelect', 'simpleSelect', 'radioSelect', 'hierarchical']),
4646
showPartiallySelected: PropTypes.bool,
4747
disabled: PropTypes.bool,
4848
readOnly: PropTypes.bool,
49-
hierarchical: PropTypes.bool,
5049
id: PropTypes.string,
5150
}
5251

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

70-
initNewProps = ({ data, mode, showPartiallySelected, hierarchical }) => {
69+
initNewProps = ({ data, mode, showPartiallySelected }) => {
7170
this.treeManager = new TreeManager({
7271
data,
7372
mode,
7473
showPartiallySelected,
75-
hierarchical,
7674
rootPrefixId: this.clientId,
7775
})
7876
// Restore focus-state
@@ -94,8 +92,8 @@ class DropdownTreeSelect extends Component {
9492
}
9593

9694
componentWillMount() {
97-
const { data, hierarchical } = this.props
98-
this.initNewProps({ data, hierarchical, ...this.props })
95+
const { data, mode, showPartiallySelected } = this.props
96+
this.initNewProps({ data, mode, showPartiallySelected })
9997
}
10098

10199
componentWillUnmount() {

src/tree-manager/index.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,23 +5,24 @@ import nodeVisitor from './nodeVisitor'
55
import keyboardNavigation, { FocusActionNames } from './keyboardNavigation'
66

77
class TreeManager {
8-
constructor({ data, mode, showPartiallySelected, hierarchical, rootPrefixId }) {
8+
constructor({ data, mode, showPartiallySelected, rootPrefixId }) {
99
this._src = data
1010
this.simpleSelect = mode === 'simpleSelect'
1111
this.radioSelect = mode === 'radioSelect'
12+
this.hierarchical = mode === 'hierarchical'
1213
const { list, defaultValues, singleSelectedNode } = flattenTree({
1314
tree: JSON.parse(JSON.stringify(data)),
1415
simple: this.simpleSelect,
1516
radio: this.radioSelect,
1617
showPartialState: showPartiallySelected,
17-
hierarchical,
18+
hierarchical: this.hierarchical,
1819
rootPrefixId,
1920
})
2021
this.tree = list
2122
this.defaultValues = defaultValues
22-
this.showPartialState = !hierarchical && showPartiallySelected
23+
this.showPartialState = !this.hierarchical && showPartiallySelected
2324
this.searchMaps = new Map()
24-
this.hierarchical = hierarchical
25+
2526
if ((this.simpleSelect || this.radioSelect) && singleSelectedNode) {
2627
// Remembers initial check on single select dropdowns
2728
this.currentChecked = singleSelectedNode._id

src/tree-node/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ class TreeNode extends PureComponent {
6969
onNodeToggle: PropTypes.func,
7070
onAction: PropTypes.func,
7171
onCheckboxChange: PropTypes.func,
72-
mode: PropTypes.oneOf(['multiSelect', 'simpleSelect', 'radioSelect']),
72+
mode: PropTypes.oneOf(['multiSelect', 'simpleSelect', 'radioSelect', 'hierarchical']),
7373
showPartiallySelected: PropTypes.bool,
7474
readOnly: PropTypes.bool,
7575
clientId: PropTypes.string,

src/tree-node/node-label.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ class NodeLabel extends PureComponent {
1919
partial: PropTypes.bool,
2020
disabled: PropTypes.bool,
2121
dataset: PropTypes.object,
22-
mode: PropTypes.oneOf(['multiSelect', 'simpleSelect', 'radioSelect']),
22+
mode: PropTypes.oneOf(['multiSelect', 'simpleSelect', 'radioSelect', 'hierarchical']),
2323
showPartiallySelected: PropTypes.bool,
2424
onCheckboxChange: PropTypes.func,
2525
readOnly: PropTypes.bool,

src/tree/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ class Tree extends Component {
2323
onNodeToggle: PropTypes.func,
2424
onAction: PropTypes.func,
2525
onCheckboxChange: PropTypes.func,
26-
mode: PropTypes.oneOf(['multiSelect', 'simpleSelect', 'radioSelect']),
26+
mode: PropTypes.oneOf(['multiSelect', 'simpleSelect', 'radioSelect', 'hierarchical']),
2727
showPartiallySelected: PropTypes.bool,
2828
pageSize: PropTypes.number,
2929
readOnly: PropTypes.bool,

src/trigger/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ class Trigger extends PureComponent {
1414
disabled: PropTypes.bool,
1515
readOnly: PropTypes.bool,
1616
showDropdown: PropTypes.bool,
17-
mode: PropTypes.oneOf(['multiSelect', 'simpleSelect', 'radioSelect']),
17+
mode: PropTypes.oneOf(['multiSelect', 'simpleSelect', 'radioSelect', 'hierarchical']),
1818
texts: PropTypes.object,
1919
}
2020

0 commit comments

Comments
 (0)