diff --git a/src/components/views/elements/DirectorySearchBox.js b/src/components/views/elements/DirectorySearchBox.js index 56f0bfd134..adca77ff9f 100644 --- a/src/components/views/elements/DirectorySearchBox.js +++ b/src/components/views/elements/DirectorySearchBox.js @@ -27,6 +27,10 @@ export default class DirectorySearchBox extends React.Component { this.onJoinButtonClick = this.onJoinButtonClick.bind(this); this.input = null; + + this.state = { + value: '', + }; } collectInput(e) { @@ -34,8 +38,9 @@ export default class DirectorySearchBox extends React.Component { } onClearClick() { + this.setState({value: ''}); + if (this.input) { - this.input.value = ''; this.input.focus(); if (this.props.onClear) { @@ -44,27 +49,34 @@ export default class DirectorySearchBox extends React.Component { } } - onChange() { + onChange(ev) { if (!this.input) return; + this.setState({value: ev.target.value}); if (this.props.onChange) { - this.props.onChange(this.input.value); + this.props.onChange(this.state.value); } } onKeyUp(ev) { if (ev.key == 'Enter') { if (this.props.onJoinClick) { - this.props.onJoinClick(this.input.value); + this.props.onJoinClick(this.state.value); } } } onJoinButtonClick() { + if (this.props.onJoinClick) { + this.props.onJoinClick(this.state.value); + } } _contentLooksLikeAlias() { - return true; + if (!this.input) return false; + + // liberal test for things that look like room aliases + return /#.+:.+/.test(this.state.value); } render() { @@ -84,7 +96,7 @@ export default class DirectorySearchBox extends React.Component { return
-