Skip to content

Commit

Permalink
fix: Refs Must Have Owner Warning in React 16.1.1
Browse files Browse the repository at this point in the history
  • Loading branch information
jaywcjlove committed Nov 21, 2017
1 parent 91695e7 commit bd3d8d8
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 23 deletions.
12 changes: 1 addition & 11 deletions src/date-picker/BasePicker.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,6 @@ export default class BasePicker extends Component {
{ ...this.propsToState(props) }
)
}
componentDidMount() {
this.input = ReactDOM.findDOMNode(this.refs.input);
this.setState({
inputWidth: this.input.getBoundingClientRect().width
})
}
componentWillReceiveProps(nextProps) {
this.setState({ ...this.propsToState(nextProps) })
}
Expand All @@ -71,9 +65,6 @@ export default class BasePicker extends Component {
}
onMouseDown(e) {
const { visible } = this.state;
if (this.refs.input) {
this.refs.input.focus();
}
if (!visible) {
// 单选展开菜单
this.toggleMenu(e);
Expand Down Expand Up @@ -150,7 +141,6 @@ export default class BasePicker extends Component {
<span style={style} className={this.classNames(states.className, className, 'w-date-base')}>
<Input
type="text"
ref="input"
{...props}
value={text}
onMouseDown={this.onMouseDown.bind(this)}
Expand Down Expand Up @@ -178,4 +168,4 @@ BasePicker.defaultProps = {
placeholder: '选择时间',
readOnly: false,
disabled: false,
}
}
2 changes: 1 addition & 1 deletion src/date-picker/TimePicker.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,4 @@ export default class TimePicker extends BasePicker {
/>
)
}
}
}
19 changes: 11 additions & 8 deletions src/date-picker/TimePickerSpinner.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,6 @@ export default class TimeSpinner extends Component {
this.renderItem = this.renderItem.bind(this)
this.handleClick = this.handleClick.bind(this)
}
componentDidMount() {
const { several } = this.state;
let { spinner } = this.refs;
if (spinner.children && spinner.children[0]) {
spinner.style.width = spinner.children[0].offsetWidth * several.length + 'px'
}
}
// 生成时间
rangeTime(end, ty) {
return TimeSpinner.items(end, ty, this.props);
Expand Down Expand Up @@ -82,7 +75,17 @@ export default class TimeSpinner extends Component {
const { several } = this.state;

return (
<div ref="spinner" className={this.classNames(`${prefixCls}`)}>
<div
ref={(elm) => {
if (elm) {
const { several } = this.state;
if (elm.children && elm.children[0]) {
elm.style.width = elm.children[0].offsetWidth * several.length + 'px'
}
}
}}
className={this.classNames(`${prefixCls}`)}
>
{several.indexOf('HH') > -1 && this.renderItem(this.rangeTime(24, 'hours'))}
{several.indexOf('mm') > -1 && this.renderItem(this.rangeTime(60, 'minutes'))}
{several.indexOf('ss') > -1 && this.renderItem(this.rangeTime(60, 'seconds'))}
Expand Down
2 changes: 2 additions & 0 deletions src/date-picker/style/time-select.less
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
.w-timeselect,.w-timepicker {
.w-popper-warpper {
position: absolute;
width: 100%;
text-align: left;
}
}
.w-timepicker-panel-popper, .w-timeselect-panel-popper {
Expand Down
1 change: 0 additions & 1 deletion src/input/Input.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,6 @@ export default class Input extends Component {
{icon && this.renderIcon.bind(this)('icon')}
<input
{...other}
ref="input"
type={type}
className={this.classNames(`${prefixCls}-inner`, {
[`${prefixCls}-p-left`]: preIcon,
Expand Down
26 changes: 26 additions & 0 deletions src/time-picker/__test__/TimePicker.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import React from 'react';
import { mount } from 'enzyme';
import { TimePicker } from '../../../src';

describe('<TimePicker>', () => {
var wrapper = mount(
<TimePicker
onChange={() => {

}}
disabledHours={['00', '01']}
disabledMinutes={['01', '02']}
disabled={true}
format="HH:mm:ss"
placeholder="选择时间de拉!"
value={new Date(2017, 6, 28, 15, 51)}
></TimePicker>
);

it('Test the default props and node.', () => {
expect(wrapper.name()).toBe('TimePicker');
// 默认值测试
expect(wrapper.type()).toEqual(TimePicker);
})

})
3 changes: 1 addition & 2 deletions src/transition/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ export default class Animate extends Component {
<Transition
{...other}
style={other.style}
ref="transition"
className={prefixCls}
in={transitionIn}
timeout={timeout}
Expand Down Expand Up @@ -104,4 +103,4 @@ Animate.defaultProps = {
animateOnMount: true, // 安装动画
duration: 200, // 持续时间
wait: 200 // 等待出现和退出时间
};
};

0 comments on commit bd3d8d8

Please sign in to comment.