Skip to content

Commit 4a842b8

Browse files
authored
Merge pull request #91 from appirio-tech/community-fixes
Fix search bar typeahead and styling
2 parents 8299afd + 9bc2d9b commit 4a842b8

File tree

8 files changed

+42
-19
lines changed

8 files changed

+42
-19
lines changed

components/Panel/Panel.jsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ class Panel extends Component {
4242

4343
return (
4444
<div className="Panel">
45-
{header}
45+
{this.props.showHeader ? header : null}
4646
{body}
4747
</div>
4848
)
@@ -54,4 +54,8 @@ Panel.propTypes = {
5454
expandTrigger: PropTypes.string
5555
}
5656

57+
Panel.defaultProps = {
58+
showHeader : true
59+
}
60+
5761
export default Panel

components/Panel/Panel.scss

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,8 @@ $panel-header-bg-color: #DFDFE1;
1919
border-right : 1px solid $tc-gray-40;
2020
border-bottom : 1px solid $tc-gray-40;
2121
padding: 10px;
22+
overflow-x: visible;
23+
overflow-y: scroll;
24+
max-height: 252px;
2225
}
23-
}
26+
}

components/SearchBar/SearchBar.jsx

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ class SearchBar extends Component {
6767

6868
handleSuggestionsUpdate(requestNo, data) {
6969
if (requestNo === this.state.maxRequestNo) {
70+
console.log('SUGGESTIONS', data)
7071
this.setState({loading: false, suggestions: data, selectedSuggestionIdx: null})
7172
}
7273
}
@@ -102,6 +103,7 @@ class SearchBar extends Component {
102103
this.refs.searchValue.value = null
103104
this.setState({ searchValue: this.refs.searchValue.value })
104105
this.setState({ searchState: 'empty' })
106+
this.setState({ suggestions: false })
105107
this.props.onClearSearch()
106108
}
107109

@@ -191,11 +193,11 @@ class SearchBar extends Component {
191193

192194
const results = this.state.loading === true
193195
? <div className="loading-suggestions"><Loader /></div>
194-
: <SearchSuggestions recentSearch={ recentList } searchTerm={ this.state.searchValue } popularSearch={ popularList } onSuggestionSelect={ this.handleSuggestionSelect } />
196+
: <SearchSuggestions hideSuggestionsWhenEmpty={ this.props.hideSuggestionsWhenEmpty } recentSearch={ recentList } searchTerm={ this.state.searchValue } popularSearch={ popularList } showPopularSearchHeader={ this.props.showPopularSearchHeader } onSuggestionSelect={ this.handleSuggestionSelect } />
195197
return (
196198
<div className={ sbClasses }>
197-
<input className="search-bar__text" onFocus={ this.onFocus } onChange={ this.onChange } onKeyUp={ this.onKeyUp } ref="searchValue" value={this.state.searchValue} />
198199
<span className="search-typeahead-text">{ typeaheadText }</span>
200+
<input className="search-bar__text" onFocus={ this.onFocus } onChange={ this.onChange } onKeyUp={ this.onKeyUp } ref="searchValue" value={this.state.searchValue} />
199201
<img className="search-bar__clear" src={ require('./x-mark.svg') } onClick={ this.clearSearch }/>
200202
<div className="search-icon-wrap" onClick={ this.search }>
201203
<img className="search-bar__icon" src={ require('./icon-search.png') } />
@@ -209,19 +211,22 @@ class SearchBar extends Component {
209211
}
210212
}
211213

212-
213214
SearchBar.propTypes = {
215+
hideSuggestionsWhenEmpty: PropTypes.func.bool,
214216
onSearch : PropTypes.func.isRequired,
215217
onClearSearch : PropTypes.func,
216218
onTermChange : PropTypes.func.isRequired,
217219
recentTerms : PropTypes.array,
218-
searchTermKey: PropTypes.string
220+
searchTermKey: PropTypes.string,
221+
showPopularSearchHeader: PropTypes.bool
219222
}
220223

221224
SearchBar.defaultProps = {
225+
hideSuggestionsWhenEmpty: false,
222226
recentTerms : [],
223227
searchTermKey : 'q',
224-
onClearSearch : () => {}
228+
onClearSearch : () => {},
229+
showPopularSearchHeader: true
225230
}
226231

227232
export default SearchBar

components/SearchBar/SearchBar.scss

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,9 @@
7979
font-size: 17px;
8080
color: $tc-gray-90;
8181
line-height: 20px;
82-
width: calc(100% - 15px - 46px);
82+
// NOTE: If uncommented, it causes problems with the proper alignment of
83+
// the typeahead text.
84+
// width: calc(100% - 15px - 46px);
8385
position: absolute;
8486
left: 15px;
8587
top: 50%;
@@ -100,10 +102,11 @@
100102
}
101103

102104
.search-typeahead-text {
105+
position: absolute;
103106
color: $tc-gray-40;
104107
display: none;
105108
z-index: 10;
106-
left: 16.5px;
109+
top: 19px;
107110
}
108111

109112
.search-bar__clear {

components/SearchSuggestions/SearchSuggestions.jsx

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ class SearchSuggestions extends Component {
8383

8484
const popularSearch = !popularList ? '' :(
8585
<div className="popular-search-suggestions">
86-
<Panel>
86+
<Panel showHeader={this.props.showPopularSearchHeader}>
8787
<div className="panel-header">
8888
<div className="label">Popular</div>
8989
</div>
@@ -100,7 +100,11 @@ class SearchSuggestions extends Component {
100100
{ 'empty-state' : recentList && !popularList }
101101
)
102102

103-
return (
103+
const hide = this.props.hideSuggestionsWhenEmpty &&
104+
(!recentList || !recentList.length) &&
105+
(!popularList || !popularList.length)
106+
107+
return hide ? (<div></div>) : (
104108
<div className={ ssClasses }>
105109
{ popularSearch }
106110
{ recentSearches }
@@ -110,16 +114,20 @@ class SearchSuggestions extends Component {
110114
}
111115

112116
SearchSuggestions.propTypes = {
117+
hideWhenEmpty : PropTypes.bool,
113118
onSuggestionSelect : PropTypes.func.isRequired,
114119
recentSearch : PropTypes.array,
115120
popularSearch : PropTypes.array,
116-
searchTerm : PropTypes.string
121+
searchTerm : PropTypes.string,
122+
showPopularSearchHeader: PropTypes.bool
117123
}
118124

119125
SearchSuggestions.defaultProps = {
126+
hideWhenEmpty : true,
120127
recentSearch : [],
121128
popularSearch : [],
122-
searchTerm : ''
129+
searchTerm : '',
130+
showPopularSearchHeader: true
123131
}
124132

125-
export default SearchSuggestions
133+
export default SearchSuggestions

components/SearchSuggestions/SearchSuggestions.scss

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
border: 1px solid $tc-gray-30;
77
box-shadow: 0px 2px 6px 0px rgba(0, 0, 0, 0.3);
88
border-radius: 2px;
9-
min-height: 303px;
9+
// min-height: 303px;
1010
position: relative;
1111

1212
.panel-header {
@@ -66,7 +66,7 @@
6666
.panel-body {
6767
border: none;
6868
padding: 0;
69-
padding-bottom: 5px;
69+
// padding-bottom: 5px;
7070

7171
li.selected {
7272
background-color: $tc-gray-neutral-dark;
@@ -127,4 +127,4 @@
127127
.panel-body {
128128
padding-bottom: 45px;
129129
}
130-
}
130+
}

components/SwitchButton/SwitchButton.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ require('./SwitchButton.scss')
33
const SwitchButton = ({label, ...props}) => {
44
return (
55
<div className="SwitchButton clearfix">
6-
<span className="label">{label}</span>
76
<label>
7+
<span className="label">{label}</span>
88
<input type="checkbox" {...props} />
99
<i/>
1010
</label>

components/SwitchButton/SwitchButton.scss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
display: flex;
66
.label{
77
width: 92px;
8-
line-height: 30px;
8+
line-height: 20px;
99
font-size: 12px;
1010
@include roboto;
1111
color: $tc-gray-60;

0 commit comments

Comments
 (0)