-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathDropdownMenu.js
More file actions
52 lines (46 loc) · 1.39 KB
/
DropdownMenu.js
File metadata and controls
52 lines (46 loc) · 1.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import React, { Component } from 'react';
import cx from 'classnames';
import { renderComponent } from './utils';
import Options from './Options';
export default class DropdownMenu extends Component {
componentWillMount() {
this.validateAndClose(this.props.options);
}
componentWillReceiveProps({ options }) {
this.validateAndClose(options);
}
validateAndClose(options) {
let { beforeOptionsComponent, afterOptionsComponent, select } = this.props;
if (!beforeOptionsComponent && !afterOptionsComponent && !options.length) {
select.actions.close();
}
}
render() {
let {
className,
select,
handleKeyDown,
highlightedOption,
minWidth,
onRef,
beforeOptionsComponent,
afterOptionsComponent,
...otherProps
} = this.props;
return (
<div
className={cx('PowerSelect__Menu', className && `${className}__Menu`)}
tabIndex="1"
onKeyDown={event => {
handleKeyDown(event, highlightedOption);
}}
style={{ minWidth }}
ref={dropdownMenu => this.props.onRef(dropdownMenu)}
>
{beforeOptionsComponent && renderComponent(beforeOptionsComponent, { select })}
<Options select={select} highlightedOption={highlightedOption} {...otherProps} />
{afterOptionsComponent && renderComponent(afterOptionsComponent, { select })}
</div>
);
}
}