Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions spec/picker-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,37 @@ describe('Picker', () => {
})
})
})

it('clears search when switching categories', (done) => {
let search = picker.findComponent(Search)
let input = search.find('input')
input.element.value = '+1'
input.trigger('input')

picker.vm.$nextTick(() => {
let categories = picker.findAllComponents(Category)
let searchCategory = categories.at(0)
expect(searchCategory.vm.id).toBe('search')

let anchors = picker.findComponent(Anchors)
let anchorsCategories = anchors.findAll('.emoji-mart-anchor')
let symbols = anchorsCategories.at(8)
expect(symbols.element.attributes['data-title'].value).toBe('Symbols')
symbols.trigger('click')

picker.vm.$nextTick(() => {
let events = anchors.emitted().click
let category = events[0][0]
expect(category.id).toBe('symbols')
expect(anchors.vm.activeCategory.id).toBe('symbols')

// Verify that the search input is cleared
expect(search.vm.value).toBe('')

done()
})
})
})
})

describe('categories', () => {
Expand Down
4 changes: 4 additions & 0 deletions src/components/Picker.vue
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,10 @@ export default {
},
onAnchorClick(category) {
this.view.onAnchorClick(category)
// Clear the search when switching categories
// otherwise categories switch does not work.
// See #136.
Comment on lines +215 to +217

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The comment explains the purpose of this code, but it could be more descriptive. Consider adding more context about why the category switch doesn't work without clearing the search. For example, does the search filter interfere with the category display logic?

      // Clear the search when switching categories.
      // The search filter interferes with the category display logic,
      // preventing the correct emojis from being displayed after switching.
      // See #136.

this.$refs.search.clear()
},
onSearch(value) {
this.view.onSearch(value)
Expand Down