Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/develop' into feat/dowjones#216
Browse files Browse the repository at this point in the history
# Conflicts:
#	__snapshots__/src/index.test.js.snap
  • Loading branch information
mrchief committed Apr 24, 2019
2 parents 3d300f4 + 4ce383a commit 23e50f8
Show file tree
Hide file tree
Showing 6 changed files with 178 additions and 3 deletions.
7 changes: 7 additions & 0 deletions README.md
Expand Up @@ -54,6 +54,7 @@ A lightweight and fast control to render a select component that can display hie
- [radioSelect](#radioSelect)
- [showPartiallySelected](#showpartiallyselected)
- [showDropdown](#showDropdown)
- [showDropdownAlways](#showDropdownAlways)
- [form states (disabled|readOnly)](#formstates)
- [id](#id)
- [label](#label)
Expand Down Expand Up @@ -344,6 +345,12 @@ Type: `bool` (default: `false`)

If set to true, shows the dropdown when rendered. This can be used to render the component with the dropdown open as its initial state.

### showDropdownAlways

Type: `bool`

If set to true, always shows the dropdown when rendered, and toggling dropdown will be disabled.

### form states (disabled|readOnly)

Type: `bool` (default: `false`)
Expand Down
151 changes: 151 additions & 0 deletions __snapshots__/src/index.test.js.md
Expand Up @@ -4,6 +4,157 @@ The actual snapshot is saved in `index.test.js.snap`.

Generated by [AVA](https://ava.li).

## always shows dropdown

> Snapshot 1
<div
className="react-dropdown-tree-select"
id="rdts"
>
<div
className="dropdown"
>
<a
className="dropdown-trigger arrow top"
onClick={Function {}}
>
<Input
inputRef={Function inputRef {}}
onBlur={Function {}}
onFocus={Function {}}
onInputChange={Function {}}
onKeyDown={Function {}}
onTagRemove={Function {}}
tags={[]}
/>
</a>
<div
className="dropdown-content"
>
<Tree
clientId="rdts"
data={
Map {
'rdts-0' => {
_children: [
'rdts-0-0',
'rdts-0-1',
],
_depth: 0,
_id: 'rdts-0',
children: undefined,
label: 'item1',
value: 'value1',
},
'rdts-0-0' => {
_children: [
'rdts-0-0-0',
'rdts-0-0-1',
],
_depth: 1,
_id: 'rdts-0-0',
_parent: 'rdts-0',
children: undefined,
label: 'item1-1',
value: 'value1-1',
},
'rdts-0-0-0' => {
_depth: 2,
_id: 'rdts-0-0-0',
_parent: 'rdts-0-0',
label: 'item1-1-1',
value: 'value1-1-1',
},
'rdts-0-0-1' => {
_depth: 2,
_id: 'rdts-0-0-1',
_parent: 'rdts-0-0',
label: 'item1-1-2',
value: 'value1-1-2',
},
'rdts-0-1' => {
_depth: 1,
_id: 'rdts-0-1',
_parent: 'rdts-0',
label: 'item1-2',
value: 'value1-2',
},
'rdts-1' => {
_children: [
'rdts-1-0',
'rdts-1-1',
],
_depth: 0,
_id: 'rdts-1',
children: undefined,
label: 'item2',
value: 'value2',
},
'rdts-1-0' => {
_children: [
'rdts-1-0-0',
'rdts-1-0-1',
'rdts-1-0-2',
],
_depth: 1,
_id: 'rdts-1-0',
_parent: 'rdts-1',
children: undefined,
label: 'item2-1',
value: 'value2-1',
},
'rdts-1-0-0' => {
_depth: 2,
_id: 'rdts-1-0-0',
_parent: 'rdts-1-0',
label: 'item2-1-1',
value: 'value2-1-1',
},
'rdts-1-0-1' => {
_depth: 2,
_id: 'rdts-1-0-1',
_parent: 'rdts-1-0',
label: 'item2-1-2',
value: 'value2-1-2',
},
'rdts-1-0-2' => {
_children: [
'rdts-1-0-2-0',
],
_depth: 2,
_id: 'rdts-1-0-2',
_parent: 'rdts-1-0',
children: undefined,
label: 'item2-1-3',
value: 'value2-1-3',
},
'rdts-1-0-2-0' => {
_depth: 3,
_id: 'rdts-1-0-2-0',
_parent: 'rdts-1-0-2',
label: 'item2-1-3-1',
value: 'value2-1-3-1',
},
'rdts-1-1' => {
_depth: 1,
_id: 'rdts-1-1',
_parent: 'rdts-1',
label: 'item2-2',
value: 'value2-2',
},
}
}
onAction={Function {}}
onCheckboxChange={Function {}}
onNodeToggle={Function {}}
pageSize={100}
searchModeOn={false}
/>
</div>
</div>
</div>

## doesn't toggle dropdown if it's disabled

> Snapshot 1
Expand Down
Binary file modified __snapshots__/src/index.test.js.snap
Binary file not shown.
7 changes: 4 additions & 3 deletions src/index.js
Expand Up @@ -30,6 +30,7 @@ class DropdownTreeSelect extends Component {
keepOpenOnSelect: PropTypes.bool,
placeholderText: PropTypes.string,
showDropdown: PropTypes.bool,
showDropdownAlways: PropTypes.bool,
className: PropTypes.string,
onChange: PropTypes.func,
onAction: PropTypes.func,
Expand Down Expand Up @@ -57,7 +58,7 @@ class DropdownTreeSelect extends Component {
constructor(props) {
super(props)
this.state = {
showDropdown: this.props.showDropdown || false,
showDropdown: this.props.showDropdown || this.props.showDropdownAlways || false,
searchModeOn: false,
currentFocus: undefined,
}
Expand Down Expand Up @@ -107,7 +108,7 @@ class DropdownTreeSelect extends Component {
handleClick = (e, callback) => {
this.setState(prevState => {
// keep dropdown active when typing in search box
const showDropdown = this.keepDropdownActive || !prevState.showDropdown
const showDropdown = this.props.showDropdownAlways || this.keepDropdownActive || !prevState.showDropdown

// register event listeners only if there is a state change
if (showDropdown !== prevState.showDropdown) {
Expand All @@ -126,7 +127,7 @@ class DropdownTreeSelect extends Component {
}

handleOutsideClick = e => {
if (!isOutsideClick(e, this.node)) {
if (this.props.showDropdownAlways || !isOutsideClick(e, this.node)) {
return
}

Expand Down
13 changes: 13 additions & 0 deletions src/index.test.js
Expand Up @@ -72,6 +72,19 @@ test('shows dropdown', t => {
t.snapshot(toJson(wrapper))
})

test('always shows dropdown', t => {
const { tree } = t.context
const wrapper = shallow(<DropdownTreeSelect id={dropdownId} data={tree} showDropdownAlways />)
t.snapshot(toJson(wrapper))
})

test('keeps dropdown open for showDropdownAlways', t => {
const { tree } = t.context
const wrapper = mount(<DropdownTreeSelect id={dropdownId} data={tree} showDropdownAlways />)
wrapper.instance().handleClick()
t.true(wrapper.state().showDropdown)
})

test('notifies on action', t => {
const handler = spy()
const { tree } = t.context
Expand Down
3 changes: 3 additions & 0 deletions types/react-dropdown-tree-select.d.ts
Expand Up @@ -25,6 +25,9 @@ declare module "react-dropdown-tree-select" {
* This can be used to render the component with the dropdown open as its initial state
*/
showDropdown?: boolean;
/** If set to true, always shows the dropdown when rendered, and toggling dropdown will be disabled.
*/
showDropdownAlways?: boolean;
/** Additional classname for container.
* The container renders with a default classname of react-dropdown-tree-select
*/
Expand Down

0 comments on commit 23e50f8

Please sign in to comment.