From 7d014966e62b0fdd2f744055244ca6d1b8fe0b6c Mon Sep 17 00:00:00 2001 From: Etienne Lemay Date: Sat, 27 May 2017 13:36:41 -0400 Subject: [PATCH] Unselect categories when searching --- src/components/picker.js | 57 ++++++++++++++++++++++------------------ 1 file changed, 31 insertions(+), 26 deletions(-) diff --git a/src/components/picker.js b/src/components/picker.js index d389077..a49add6 100644 --- a/src/components/picker.js +++ b/src/components/picker.js @@ -198,43 +198,48 @@ export default class Picker extends React.Component { return } - var target = this.refs.scroll, - scrollTop = target.scrollTop, - scrollingDown = scrollTop > (this.scrollTop || 0), - activeCategory = null, - minTop = 0 + let activeCategory = null - for (let i = 0, l = this.categories.length; i < l; i++) { - let ii = scrollingDown ? (this.categories.length - 1 - i) : i, - category = this.categories[ii], - component = this.refs[`category-${ii}`] + if (SEARCH_CATEGORY.emojis) { + activeCategory = SEARCH_CATEGORY + } else { + var target = this.refs.scroll, + scrollTop = target.scrollTop, + scrollingDown = scrollTop > (this.scrollTop || 0), + minTop = 0 - if (component) { - let active = component.handleScroll(scrollTop) + for (let i = 0, l = this.categories.length; i < l; i++) { + let ii = scrollingDown ? (this.categories.length - 1 - i) : i, + category = this.categories[ii], + component = this.refs[`category-${ii}`] - if (!minTop || component.top < minTop) { - if (component.top > 0) { - minTop = component.top + if (component) { + let active = component.handleScroll(scrollTop) + + if (!minTop || component.top < minTop) { + if (component.top > 0) { + minTop = component.top + } + } + + if (active && !activeCategory) { + activeCategory = category } } + } + + if (scrollTop < minTop) { + for (let category of this.categories) { + if (category.anchor === false) { continue } - if (active && !activeCategory) { activeCategory = category + break } + } else if (scrollTop + this.clientHeight >= this.scrollHeight) { + activeCategory = this.categories[this.categories.length - 1] } } - if (scrollTop < minTop) { - for (let category of this.categories) { - if (category.anchor === false) { continue } - - activeCategory = category - break - } - } else if (scrollTop + this.clientHeight >= this.scrollHeight) { - activeCategory = this.categories[this.categories.length - 1] - } - if (activeCategory) { let { anchors } = this.refs, { name: categoryName } = activeCategory