Clear search results when clicking a category anchor

release
Etienne Lemay 2016-07-08 16:28:43 -04:00
parent 47f2341f53
commit 1a3f2525b9
3 changed files with 28 additions and 9 deletions

View File

@ -56,7 +56,9 @@ export default class Category extends React.Component {
var { height: labelHeight } = this.label.getBoundingClientRect() var { height: labelHeight } = this.label.getBoundingClientRect()
this.top = top - parentTop + this.parent.scrollTop this.top = top - parentTop + this.parent.scrollTop
if (height > labelHeight) { if (height == 0) {
this.maxMargin = 0
} else if (height > labelHeight) {
this.maxMargin = height - labelHeight this.maxMargin = height - labelHeight
} else { } else {
this.maxMargin = 1 this.maxMargin = 1

View File

@ -137,18 +137,30 @@ export default class Picker extends React.Component {
handleAnchorClick(category, i) { handleAnchorClick(category, i) {
var component = this.refs[`category-${i}`], var component = this.refs[`category-${i}`],
{ scroll, anchors } = this.refs { scroll, anchors } = this.refs,
scrollToComponent = null
if (component) { scrollToComponent = () => {
let { top } = component if (component) {
let { top } = component
if (category.name == 'Recent') { if (category.name == 'Recent') {
top = 0 top = 0
} else { } else {
top += 1 top += 1
}
scroll.scrollTop = top
} }
}
scroll.scrollTop = top if (SEARCH_CATEGORY.emojis) {
this.handleSearch(null)
this.refs.search.clear()
window.requestAnimationFrame(scrollToComponent)
} else {
scrollToComponent()
} }
} }
@ -182,6 +194,7 @@ export default class Picker extends React.Component {
<div ref="scroll" className='emoji-picker-scroll' onScroll={this.handleScroll.bind(this)}> <div ref="scroll" className='emoji-picker-scroll' onScroll={this.handleScroll.bind(this)}>
<Search <Search
ref='search'
onSearch={this.handleSearch.bind(this)} onSearch={this.handleSearch.bind(this)}
/> />

View File

@ -59,6 +59,10 @@ export default class Search extends React.Component {
this.props.onSearch(results) this.props.onSearch(results)
} }
clear() {
this.refs.input.value = ''
}
render() { render() {
return <input return <input
ref='input' ref='input'