Skip to content

Commit 59fa185

Browse files
committed
fix: issue #4301
1 parent 0426134 commit 59fa185

File tree

3 files changed

+36
-1
lines changed

3 files changed

+36
-1
lines changed

src/components/Select/Select.jsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ const Select = (props) => {
2626
{...props}
2727
createOptionPosition="first"
2828
className={containerclass}
29+
ref={props.createSelectRef}
2930
classNamePrefix="react-select"
3031
/>
3132
)

src/components/TeamManagement/AutocompleteInput.jsx

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,18 @@ class AutocompleteInput extends React.Component {
1616
const {
1717
placeholder,
1818
selectedMembers,
19-
disabled
19+
createSelectRef,
20+
disabled,
21+
onBlur
2022
} = this.props
2123

2224
return (
2325
<div className="autocomplete-wrapper">
2426
<Select
2527
isMulti
28+
onBlur={onBlur}
2629
closeMenuOnSelect
30+
createSelectRef={createSelectRef}
2731
showDropdownIndicator={false}
2832
createOption
2933
placeholder={placeholder}
@@ -41,6 +45,7 @@ class AutocompleteInput extends React.Component {
4145
AutocompleteInput.defaultProps = {
4246
placeholder: 'Enter one or more user handles',
4347
selectedMembers: [],
48+
createSelectRef: () => {},
4449
disabled: false
4550
}
4651

@@ -50,6 +55,16 @@ AutocompleteInput.propTypes = {
5055
*/
5156
onUpdate: PropTypes.func,
5257

58+
/**
59+
* Callback fired when input blur
60+
*/
61+
onBlur: PropTypes.func,
62+
63+
/**
64+
* Callback for pass select Ref to parent component
65+
*/
66+
createSelectRef : PropTypes.func,
67+
5368
/**
5469
* The current logged in user in the app.
5570
* Used to determinate "You" label and access

src/components/TeamManagement/AutocompleteInputContainer.jsx

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,11 @@ class AutocompleteInputContainer extends React.Component {
1111
constructor(props) {
1212
super(props)
1313
this.debounceTimer = null
14+
this.selectInstance = null
1415

1516
this.clearUserSuggestions = this.clearUserSuggestions.bind(this)
17+
this.handleInputBlur = this.handleInputBlur.bind(this)
18+
this.createSelectRef = this.createSelectRef.bind(this)
1619
}
1720

1821
/**
@@ -66,13 +69,29 @@ class AutocompleteInputContainer extends React.Component {
6669
this.clearUserSuggestions()
6770
}
6871

72+
handleInputBlur() {
73+
const innerSelectInstance = this.selectInstance.select.select
74+
const focusedOption = innerSelectInstance.state.focusedOption
75+
// current input value
76+
const inputValue = this.selectInstance.state.inputValue
77+
if (inputValue && focusedOption) {
78+
innerSelectInstance.selectOption(focusedOption)
79+
}
80+
}
81+
82+
createSelectRef(ref) {
83+
this.selectInstance = ref
84+
}
85+
6986
render() {
7087

7188
const { placeholder, currentUser, selectedMembers, disabled } = this.props
7289

7390
return (
7491
<AutocompleteInput
92+
createSelectRef={this.createSelectRef}
7593
placeholder={placeholder ? placeholder:''}
94+
onBlur={this.handleInputBlur}
7695
onInputChange={this.onInputChange.bind(this)}
7796
onUpdate={this.onUpdate.bind(this)}
7897
suggestedMembers={this.props.suggestedMembers}

0 commit comments

Comments
 (0)