]> git.immae.eu Git - github/fretlink/time-picker.git/commitdiff
Fix the bug the Select's scrollbar flashes repeatedly in Chrome/macOS when always...
authorcaojunchao <caojunchao@didichuxing.com>
Thu, 9 Mar 2017 05:38:54 +0000 (13:38 +0800)
committercaojunchao <caojunchao@didichuxing.com>
Thu, 9 Mar 2017 05:38:54 +0000 (13:38 +0800)
assets/index/Select.less
src/Select.jsx

index 13b5b187418cb53ebf11e9bfd186c8ebd1389ad4..8bec4a079b13142fcb7ca313dbddea999e97de0c 100644 (file)
@@ -9,7 +9,7 @@
   overflow: hidden;
   position: relative; // Fix chrome weird render bug
 
-  &:hover {
+  &-active {
     overflow-y: auto;
   }
 
index 5733b1a235b9348f94c5f7fac1b3f9c4109fba71..deb155ddbae5c7884c4efe6cd63c5076c415b5cd 100644 (file)
@@ -32,6 +32,12 @@ const Select = React.createClass({
     onMouseEnter: PropTypes.func,
   },
 
+  getInitialState() {
+    return {
+      active: false,
+    };
+  },
+
   componentDidMount() {
     // jump to selected option
     this.scrollToSelected(0);
@@ -87,17 +93,31 @@ const Select = React.createClass({
     scrollTo(select, to, duration);
   },
 
+  handleMouseEnter(e) {
+    this.setState({ active: true });
+    this.props.onMouseEnter(e);
+  },
+
+  handleMouseLeave() {
+    this.setState({ active: false });
+  },
+
   render() {
     if (this.props.options.length === 0) {
       return null;
     }
 
     const { prefixCls } = this.props;
+    const cls = classnames({
+      [`${prefixCls}-select`]: 1,
+      [`${prefixCls}-select-active`]: this.state.active,
+    });
 
     return (
       <div
-        className={`${prefixCls}-select`}
-        onMouseEnter={this.props.onMouseEnter}
+        className={cls}
+        onMouseEnter={this.handleMouseEnter}
+        onMouseLeave={this.handleMouseLeave}
       >
         <ul ref="list">{this.getOptions()}</ul>
       </div>