aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/Select.jsx
diff options
context:
space:
mode:
authorcaojunchao <caojunchao@didichuxing.com>2017-03-09 13:38:54 +0800
committercaojunchao <caojunchao@didichuxing.com>2017-03-09 13:38:54 +0800
commitd093074a00881b60b3440a35503f0143612143a0 (patch)
tree6c930b2ce269632285377492e8659acc45b83a52 /src/Select.jsx
parent2bda6450fabe79840c0a83221416ab4864022612 (diff)
downloadtime-picker-d093074a00881b60b3440a35503f0143612143a0.tar.gz
time-picker-d093074a00881b60b3440a35503f0143612143a0.tar.zst
time-picker-d093074a00881b60b3440a35503f0143612143a0.zip
Fix the bug the Select's scrollbar flashes repeatedly in Chrome/macOS when always show scroll bars
Diffstat (limited to 'src/Select.jsx')
-rw-r--r--src/Select.jsx24
1 files changed, 22 insertions, 2 deletions
diff --git a/src/Select.jsx b/src/Select.jsx
index 5733b1a..deb155d 100644
--- a/src/Select.jsx
+++ b/src/Select.jsx
@@ -32,6 +32,12 @@ const Select = React.createClass({
32 onMouseEnter: PropTypes.func, 32 onMouseEnter: PropTypes.func,
33 }, 33 },
34 34
35 getInitialState() {
36 return {
37 active: false,
38 };
39 },
40
35 componentDidMount() { 41 componentDidMount() {
36 // jump to selected option 42 // jump to selected option
37 this.scrollToSelected(0); 43 this.scrollToSelected(0);
@@ -87,17 +93,31 @@ const Select = React.createClass({
87 scrollTo(select, to, duration); 93 scrollTo(select, to, duration);
88 }, 94 },
89 95
96 handleMouseEnter(e) {
97 this.setState({ active: true });
98 this.props.onMouseEnter(e);
99 },
100
101 handleMouseLeave() {
102 this.setState({ active: false });
103 },
104
90 render() { 105 render() {
91 if (this.props.options.length === 0) { 106 if (this.props.options.length === 0) {
92 return null; 107 return null;
93 } 108 }
94 109
95 const { prefixCls } = this.props; 110 const { prefixCls } = this.props;
111 const cls = classnames({
112 [`${prefixCls}-select`]: 1,
113 [`${prefixCls}-select-active`]: this.state.active,
114 });
96 115
97 return ( 116 return (
98 <div 117 <div
99 className={`${prefixCls}-select`} 118 className={cls}
100 onMouseEnter={this.props.onMouseEnter} 119 onMouseEnter={this.handleMouseEnter}
120 onMouseLeave={this.handleMouseLeave}
101 > 121 >
102 <ul ref="list">{this.getOptions()}</ul> 122 <ul ref="list">{this.getOptions()}</ul>
103 </div> 123 </div>