Skip to content

Commit

Permalink
Merge pull request #239 from kbase/UFI-60
Browse files Browse the repository at this point in the history
a bit more refinement [UFI-60]
  • Loading branch information
eapearson authored Jul 21, 2023
2 parents e9e2d0b + ecc0ac7 commit 4ba096a
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 37 deletions.
14 changes: 14 additions & 0 deletions src/plugin/iframe_root/modules/reactComponents/TypeaheadInput.css
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,20 @@
overflow: auto
}

.TypeaheadInput .-dropdown-wrapper > .-dropdown-items .-dropdown-item {
padding: 4px;
cursor: pointer;
}

.TypeaheadInput .-dropdown-wrapper > .-dropdown-items .-dropdown-item:hover {
background-color: rgba(200, 200, 200, 0.2);
}

.TypeaheadInput .-dropdown-wrapper > .-dropdown-items .-dropdown-item:active {
background-color: rgba(200, 200, 200, 0.5);
}


.TypeaheadInput .-search-button {
cursor: pointer;
}
48 changes: 11 additions & 37 deletions src/plugin/iframe_root/modules/reactComponents/TypeaheadInput.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,26 +115,21 @@ define([

onInput(e) {
const value = e.target.value;
const result = this.inputUpdated(value);
// if (result.status === 'ERROR') {
// return;
// }
this.inputUpdated(value);
this.props.onSelect(value);
}

onKeyDown(event) {
if (event.key === 'Tab') {
this.tabbing = true;
} else {
this.tabbing = false;
if (event.key === 'Tab' || event.key === 'Escape' || event.key === 'Enter') {
this.closeDropdown();
}
}

doToggleSearch(e) {
e.stopPropagation();
this.inputRef.current.focus();
if (this.state.status !== 'SUCCESS') {
const totalCount = this.data.length;
const totalCount = this.props.data.length;
this.setState({
status: 'SUCCESS',
value: {
Expand Down Expand Up @@ -173,19 +168,6 @@ define([
this.props.onSelect(this.state.inputValue);
}

onKeyPress(e) {
if (e.key === 'Enter' || e.key === 'Escape') {
e.preventDefault();
this.closeDropdown();
}
}

onBlur() {
if (this.tabbing) {
this.closeDropdown();
}
}

renderCancelSearchButton() {
if (!this.state.userOpenedSearch) {
return;
Expand All @@ -200,18 +182,18 @@ define([
doSelectValue(value) {
this.setState({
...this.state,
value: {
value
},
// value,
inputValue: value,
userOpenedSearch: false
});
this.props.onSelect(value);
this.inputRef.current.focus();
}

leaveAsIs(ev) {
ev.preventDefault();
ev.stopPropagation();
this.inputRef.current.focus();
this.closeDropdown();
}

Expand Down Expand Up @@ -249,16 +231,10 @@ define([

return this.state.value.searchedValues.map(({label}) => {
return html`
<div className="-row"
style=${{
padding: '4px',
cursor: 'pointer'
}}
onClick=${() => {this.doSelectValue(label);}}
>
${label}
</div>
<div className="-row -dropdown-item"
onClick=${() => {this.doSelectValue(label);}}>
${label}
</div>
`;
});
}
Expand Down Expand Up @@ -325,9 +301,7 @@ define([
value=${this.state.inputValue}
placeholder=${this.props.placeholder}
onInput=${this.onInput.bind(this)}
onKeyPress=${this.onKeyPress.bind(this)}
onKeyDown=${this.onKeyDown.bind(this)}
onBlur=${this.onBlur.bind(this)}
/>
${this.renderCancelSearchButton()}
${this.renderSearchButton()}
Expand Down

0 comments on commit 4ba096a

Please sign in to comment.