Skip to content

Commit

Permalink
Fixed #489
Browse files Browse the repository at this point in the history
  • Loading branch information
mertsincan committed Jul 3, 2018
1 parent 1b9b09e commit cdb2db1
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion src/components/dropdown/Dropdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,7 @@ export class Dropdown extends Component {
return <div className="ui-helper-hidden-accessible">
<input ref={(el) => this.focusInput = el} id={this.props.inputId} type="text" role="listbox"
onFocus={this.onInputFocus} onBlur={this.onInputBlur} onKeyDown={this.onInputKeyDown}
disabled={this.props.disabled} tabIndex={this.props.tabIndex} autoFocus={this.props.autoFocus} />
disabled={this.props.disabled} tabIndex={this.props.tabIndex} />
</div>;
}

Expand Down Expand Up @@ -467,6 +467,12 @@ export class Dropdown extends Component {
getOptionLabel(option) {
return this.props.optionLabel ? ObjectUtils.resolveFieldData(option, this.props.optionLabel) : option.label;
}

unbindWindowLoadListener() {
if (this.windowLoadListener) {
window.removeEventListener('load', this.windowLoadListener);
}
}

componentDidMount() {
if(this.props.autoWidth) {
Expand All @@ -477,10 +483,19 @@ export class Dropdown extends Component {
}
}, 0);
}

if (this.props.autoFocus && this.focusInput) {
this.windowLoadListener = () => {
this.focusInput.focus();
}

window.addEventListener('load', this.windowLoadListener);
}
}

componentWillUnmount() {
this.unbindDocumentClickListener();
this.unbindWindowLoadListener();
}

componentDidUpdate(prevProps, prevState) {
Expand Down

0 comments on commit cdb2db1

Please sign in to comment.