Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add costum debounce delay #335

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
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
5 changes: 5 additions & 0 deletions docs/components/DocProps.vue
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,11 @@
type: 'Number | String',
defaultValue: code('999'),
description: `${(code('z-index'))} of the menu.`,
}, {
name: 'inputDebounceDelay',
type: 'Number',
defaultValue: code('200'),
description: `Sync search throttling delay. The represents the “waiting time” between input entries before processing the search.`,
} ],
}),
}
Expand Down
4 changes: 2 additions & 2 deletions src/components/Input.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<script>
import { debounce, deepExtend, includes } from '../utils'
import { MIN_INPUT_WIDTH, KEY_CODES, INPUT_DEBOUNCE_DELAY } from '../constants'
import { MIN_INPUT_WIDTH, KEY_CODES } from '../constants'

const keysThatRequireMenuBeingOpen = [
KEY_CODES.ENTER,
Expand Down Expand Up @@ -53,7 +53,7 @@
created() {
this.debouncedCallback = debounce(
this.updateSearchQuery,
INPUT_DEBOUNCE_DELAY,
this.instance.inputDebounceDelay,
{ leading: true, trailing: true },
)
},
Expand Down
10 changes: 9 additions & 1 deletion src/mixins/treeselectMixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {
LOAD_ROOT_OPTIONS, LOAD_CHILDREN_OPTIONS, ASYNC_SEARCH,
ALL, BRANCH_PRIORITY, LEAF_PRIORITY, ALL_WITH_INDETERMINATE,
ALL_CHILDREN, ALL_DESCENDANTS, LEAF_CHILDREN, LEAF_DESCENDANTS,
ORDER_SELECTED, LEVEL, INDEX,
ORDER_SELECTED, LEVEL, INDEX, INPUT_DEBOUNCE_DELAY,
} from '../constants'

function sortValueByIndex(a, b) {
Expand Down Expand Up @@ -636,6 +636,14 @@ export default {
type: [ Number, String ],
default: 999,
},

/**
* Sync search throttling delay.
*/
inputDebounceDelay: {
type: Number,
default: INPUT_DEBOUNCE_DELAY,
},
},

data() {
Expand Down
21 changes: 21 additions & 0 deletions test/unit/specs/Searching.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -468,6 +468,27 @@ describe('Searching', () => {
await typeAndAssert('b', [ 'ab', 'b' ])
})

it('sync search throttling delay', async () => {
const wrapper = mount(Treeselect, {
propsData: {
inputDebounceDelay: 500,
options: [ {
id: 'a',
label: 'a',
children: [ {
id: 'aa',
label: 'x',
}, {
id: 'ab',
label: 'a x',
} ],
} ],
},
})

await typeSearchText(wrapper, 'a x')
})

describe('async search', () => {
it('basic', async () => {
let id = 0
Expand Down
3 changes: 1 addition & 2 deletions test/unit/specs/shared.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import sleep from 'yaku/lib/sleep'
import Option from '@src/components/Option'
import { INPUT_DEBOUNCE_DELAY } from '@src/constants'

export function $(selector, context = document) {
return context.querySelector(selector)
Expand Down Expand Up @@ -106,7 +105,7 @@ export async function typeSearchText(wrapper, text) {
$input.element.value = text
$input.trigger('input')
expect(wrapper.vm.$refs.control.$refs['value-container'].$refs.input.value).toBe(text)
await sleep(INPUT_DEBOUNCE_DELAY + 1)
await sleep(wrapper.vm.inputDebounceDelay + 1)
expect(wrapper.vm.trigger.searchQuery).toBe(text)
}

Expand Down