From d093074a00881b60b3440a35503f0143612143a0 Mon Sep 17 00:00:00 2001 From: caojunchao Date: Thu, 9 Mar 2017 13:38:54 +0800 Subject: Fix the bug the Select's scrollbar flashes repeatedly in Chrome/macOS when always show scroll bars --- assets/index/Select.less | 2 +- src/Select.jsx | 24 ++++++++++++++++++++++-- 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/assets/index/Select.less b/assets/index/Select.less index 13b5b18..8bec4a0 100644 --- a/assets/index/Select.less +++ b/assets/index/Select.less @@ -9,7 +9,7 @@ overflow: hidden; position: relative; // Fix chrome weird render bug - &:hover { + &-active { overflow-y: auto; } 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({ 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 (
-- cgit v1.2.3 From 17444974eff819b0a5c29ae7d5f37242bf407f89 Mon Sep 17 00:00:00 2001 From: caojunchao Date: Thu, 9 Mar 2017 14:22:01 +0800 Subject: Add test --- tests/Select.spec.jsx | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/tests/Select.spec.jsx b/tests/Select.spec.jsx index fd2ec32..2d30098 100644 --- a/tests/Select.spec.jsx +++ b/tests/Select.spec.jsx @@ -33,6 +33,34 @@ describe('Select', () => { document.body.removeChild(container); }); + describe('select panel', () => { + it('select panel reacts to mouseenter and mouseleave correctly', (done) => { + const picker = renderPicker(); + const input = TestUtils.scryRenderedDOMComponentsWithClass(picker, + 'rc-time-picker-input')[0]; + async.series([(next) => { + Simulate.click(input); + setTimeout(next, 100); + }, (next) => { + const re = /(^|\s+)rc-time-picker-panel-select-active(\s+|$)/; + const selector = TestUtils.scryRenderedDOMComponentsWithClass(picker.panelInstance, + 'rc-time-picker-panel-select')[0]; + + expect(re.test(selector.className)).to.be(false); + + Simulate.mouseEnter(selector); + expect(re.test(selector.className)).to.be(true); + + Simulate.mouseLeave(selector); + expect(re.test(selector.className)).to.be(false); + + next(); + }], () => { + done(); + }); + }); + }); + describe('select number', () => { it('select number correctly', (done) => { const picker = renderPicker(); -- cgit v1.2.3