Skip to content

Commit 0d68fa4

Browse files
ryankshawmichaelbrewerdavis
authored andcommitted
Replace string refs with callback refs
1 parent 5b87ec3 commit 0d68fa4

File tree

2 files changed

+16
-16
lines changed

2 files changed

+16
-16
lines changed

src/combobox.js

+12-12
Original file line numberDiff line numberDiff line change
@@ -54,14 +54,14 @@ class Combobox extends React.Component {
5454

5555
componentWillReceiveProps(newProps) {
5656
this.setState({menu: this.makeMenu(newProps.children)}, function() {
57-
if(newProps.children.length && (this.isOpen || document.activeElement === this.refs.input)) {
57+
if(newProps.children.length && (this.isOpen || document.activeElement === this.input)) {
5858
if(!this.state.menu.children.length) {
5959
return
6060
}
6161
this.setState({
6262
isOpen: true
6363
}, function() {
64-
this.refs.list.scrollTop = 0;
64+
this.list.scrollTop = 0;
6565
}.bind(this))
6666
} else {
6767
this.hideList();
@@ -134,7 +134,7 @@ class Combobox extends React.Component {
134134
};
135135

136136
handleInputChange = () => {
137-
var value = this.refs.input.value;
137+
var value = this.input.value;
138138
this.clearSelectedState(function() {
139139
this.props.onInput(value);
140140
}.bind(this));
@@ -208,11 +208,11 @@ class Combobox extends React.Component {
208208
};
209209

210210
focusInput = () => {
211-
this.refs.input.focus();
211+
this.input.focus();
212212
};
213213

214214
selectInput = () => {
215-
this.refs.input.select();
215+
this.input.select();
216216
}
217217

218218
inputKeydownMap = {
@@ -285,15 +285,15 @@ class Combobox extends React.Component {
285285
if (options.focus !== false)
286286
this.selectInput();
287287
}.bind(this));
288-
this.refs.input.value = '' // added
288+
this.input.value = '' // added
289289
};
290290

291291
selectText = () => {
292-
var value = this.refs.input.value;
292+
var value = this.input.value;
293293
if(!value) return;
294294
this.props.onSelect(value);
295295
this.clearSelectedState();
296-
this.refs.input.value = '' // added
296+
this.input.value = '' // added
297297
};
298298

299299
focusNext = (event) => {
@@ -304,7 +304,7 @@ class Combobox extends React.Component {
304304
};
305305

306306
removeLastToken = () => {
307-
if(this.props.onRemoveLast && !this.refs.input.value) {
307+
if(this.props.onRemoveLast && !this.input.value) {
308308
this.props.onRemoveLast()
309309
}
310310
return true
@@ -387,7 +387,7 @@ class Combobox extends React.Component {
387387

388388
focusOption = () => {
389389
var index = this.state.focusedIndex;
390-
this.refs.list.childNodes[index].focus();
390+
this.list.childNodes[index].focus();
391391
};
392392

393393
state = {
@@ -419,7 +419,7 @@ class Combobox extends React.Component {
419419
{this.props.value}
420420
{this.state.inputValue}
421421
<input
422-
ref="input"
422+
ref={e => this.input = e}
423423
autoComplete="off"
424424
spellCheck="false"
425425
aria-label={ariaLabel}
@@ -447,7 +447,7 @@ class Combobox extends React.Component {
447447
</span>
448448
<div
449449
id={this.state.listId}
450-
ref="list"
450+
ref={e => this.list =e}
451451
className="ic-tokeninput-list"
452452
role="listbox">
453453
{this.state.menu.children}

src/main.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ class TokenInput extends React.Component {
2525

2626
handleClick = () => {
2727
// TODO: Expand combobox API for focus
28-
this.refs['combo-li'].querySelector('input').focus();
28+
this.comboLi.querySelector('input').focus();
2929
};
3030

3131
handleFocus = () => {
@@ -39,7 +39,7 @@ class TokenInput extends React.Component {
3939
};
4040

4141
handleSelect = (event, option) => {
42-
var input = this.refs['combo-li'].querySelector('input');
42+
var input = this.comboLi.querySelector('input');
4343
this.props.onSelect(event, option)
4444
this.setState({
4545
selectedToken: null
@@ -48,7 +48,7 @@ class TokenInput extends React.Component {
4848
};
4949

5050
handleRemove = (value) => {
51-
var input = this.refs['combo-li'].querySelector('input');
51+
var input = this.comboLi.querySelector('input');
5252
this.props.onRemove(value);
5353
input.focus();
5454
};
@@ -78,7 +78,7 @@ class TokenInput extends React.Component {
7878
return (
7979
<ul className={classes} onClick={this.handleClick}>
8080
{tokens}
81-
<li className="inline-flex" ref="combo-li">
81+
<li className="inline-flex" ref={e => this.comboLi = e}>
8282
<Combobox
8383
id={this.props.id}
8484
aria-label={this.props['combobox-aria-label']}

0 commit comments

Comments
 (0)