Skip to content

Commit 39ba39c

Browse files
committed
Re-name 'selected' state 'index'
1 parent 4bb0022 commit 39ba39c

File tree

4 files changed

+17
-19
lines changed

4 files changed

+17
-19
lines changed

lib/Input.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ class Input extends React.Component {
6363
}
6464

6565
render () {
66-
const { query, placeholder, expanded, listboxId, selected } = this.props
66+
const { query, placeholder, expanded, listboxId, index } = this.props
6767

6868
return (
6969
<div className={this.props.classNames.searchInput}>
@@ -75,7 +75,7 @@ class Input extends React.Component {
7575
aria-autocomplete='list'
7676
aria-label={placeholder}
7777
aria-owns={listboxId}
78-
aria-activedescendant={selected > -1 ? `${listboxId}-${selected}` : null}
78+
aria-activedescendant={index > -1 ? `${listboxId}-${index}` : null}
7979
aria-expanded={expanded}
8080
style={{ width: this.state.inputWidth }} />
8181
<div ref={(c) => { this.sizer = c }} style={SIZER_STYLES}>{query || placeholder}</div>

lib/ReactTags.js

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ const CLASS_NAMES = {
2727
}
2828

2929
function pressDelimiterKey (e) {
30-
if (this.state.query || this.state.selected > -1) {
30+
if (this.state.query || this.state.index > -1) {
3131
e.preventDefault()
3232
}
3333

@@ -37,7 +37,7 @@ function pressDelimiterKey (e) {
3737
return matchExact(this.state.query).test(option.name)
3838
})
3939

40-
const index = this.state.selected === -1 ? match : this.state.selected
40+
const index = this.state.index === -1 ? match : this.state.index
4141

4242
if (index > -1) {
4343
this.addTag(this.state.options[index])
@@ -51,21 +51,21 @@ function pressUpKey (e) {
5151
e.preventDefault()
5252

5353
// if first item, cycle to the bottom
54-
if (this.state.selected <= 0) {
55-
this.setState({ selected: this.state.options.length - 1 })
54+
if (this.state.index <= 0) {
55+
this.setState({ index: this.state.options.length - 1 })
5656
} else {
57-
this.setState({ selected: this.state.selected - 1 })
57+
this.setState({ index: this.state.index - 1 })
5858
}
5959
}
6060

6161
function pressDownKey (e) {
6262
e.preventDefault()
6363

6464
// if last item, cycle to top
65-
if (this.state.selected >= this.state.options.length - 1) {
66-
this.setState({ selected: 0 })
65+
if (this.state.index >= this.state.options.length - 1) {
66+
this.setState({ index: 0 })
6767
} else {
68-
this.setState({ selected: this.state.selected + 1 })
68+
this.setState({ index: this.state.index + 1 })
6969
}
7070
}
7171

@@ -89,7 +89,7 @@ class ReactTags extends React.Component {
8989
query: '',
9090
focused: false,
9191
options: [],
92-
selected: -1,
92+
index: -1,
9393
classNames: Object.assign({}, CLASS_NAMES, this.props.classNames)
9494
}
9595
}
@@ -142,7 +142,7 @@ class ReactTags extends React.Component {
142142
}
143143

144144
onBlur () {
145-
this.setState({ focused: false, selected: -1 })
145+
this.setState({ focused: false, index: -1 })
146146

147147
if (this.props.onBlur) {
148148
this.props.onBlur()
@@ -167,7 +167,7 @@ class ReactTags extends React.Component {
167167
// reset the state
168168
this.setState({
169169
query: '',
170-
selected: -1
170+
index: -1
171171
})
172172
}
173173

lib/Suggestions.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ class Suggestions extends React.Component {
2222
const key = `${this.props.listboxId}-${i}`
2323
const classNames = []
2424

25-
if (this.props.selected === i) {
25+
if (this.props.index === i) {
2626
classNames.push(this.props.classNames.suggestionActive)
2727
}
2828

lib/concerns/matchers.js

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,14 @@ function escapeForRegExp (string) {
22
return string.replace(/[-\\^$*+?.()|[\]{}]/g, '\\$&')
33
}
44

5-
function matchAny (string) {
5+
export function matchAny (string) {
66
return new RegExp(escapeForRegExp(string), 'gi')
77
}
88

9-
function matchPartial (string) {
9+
export function matchPartial (string) {
1010
return new RegExp(`(?:^|\\s)${escapeForRegExp(string)}`, 'i')
1111
}
1212

13-
function matchExact (string) {
13+
export function matchExact (string) {
1414
return new RegExp(`^${escapeForRegExp(string)}$`, 'i')
1515
}
16-
17-
module.exports = { escapeForRegExp, matchAny, matchPartial, matchExact }

0 commit comments

Comments
 (0)