Skip to content

Commit

Permalink
update react refs to use callback instead of strings
Browse files Browse the repository at this point in the history
  • Loading branch information
coderpawz committed Jul 26, 2017
1 parent c3780a0 commit 74da6c4
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 7 deletions.
5 changes: 4 additions & 1 deletion src/Calendar.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,9 @@ const Calendar = createReactClass({
showTimePicker: false,
});
},
saveDateInput(dateInput) {
this.dateInputInstance = dateInput;
},
render() {
const props = this.props;
const {
Expand All @@ -227,7 +230,7 @@ const Calendar = createReactClass({
}) : null;
const dateInputElement = props.showDateInput ? (
<DateInput
ref="dateInput"
ref={this.saveDateInput}
format={this.getFormat()}
key="date-input"
value={value}
Expand Down
6 changes: 5 additions & 1 deletion src/RangeCalendar.js
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,10 @@ const RangeCalendar = createReactClass({
return month.isSameOrBefore(value[0], 'month');
},

saveRoot(root) {
this.rootInstance = root;
},

render() {
const props = this.props;
const state = this.state;
Expand Down Expand Up @@ -473,7 +477,7 @@ const RangeCalendar = createReactClass({
nextMonthOfStart.month() === endValue.month();
return (
<div
ref="root"
ref={this.saveRoot}
className={classes}
style={props.style}
tabIndex="0"
Expand Down
10 changes: 8 additions & 2 deletions src/date/DateInput.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,13 @@ const DateInput = createReactClass({
},

focus() {
this.refs.dateInput.focus();
if (this.dateInputInstance) {
this.dateInputInstance.focus();
}
},

saveDateInput(dateInput) {
this.dateInputInstance = dateInput;
},

render() {
Expand All @@ -107,7 +113,7 @@ const DateInput = createReactClass({
return (<div className={`${prefixCls}-input-wrap`}>
<div className={`${prefixCls}-date-input-wrap`}>
<input
ref="dateInput"
ref={this.saveDateInput}
className={`${prefixCls}-input ${invalidClass}`}
value={str}
disabled={props.disabled}
Expand Down
6 changes: 5 additions & 1 deletion src/mixin/CalendarMixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,10 @@ const CalendarMixin = {
this.setSelectedValue(value, cause);
},

saveRoot(root) {
this.rootInstance = root;
},

renderRoot(newProps) {
const props = this.props;
const prefixCls = props.prefixCls;
Expand All @@ -79,7 +83,7 @@ const CalendarMixin = {

return (
<div
ref="root"
ref={this.saveRoot}
className={`${classnames(className)}`}
style={this.props.style}
tabIndex="0"
Expand Down
4 changes: 2 additions & 2 deletions src/mixin/CommonMixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ export default {
},

focus() {
if (this.refs.root) {
this.refs.root.focus();
if (this.rootInstance) {
this.rootInstance.focus();
}
},
};

0 comments on commit 74da6c4

Please sign in to comment.