Skip to content

Commit 64d6641

Browse files
committed
fix(autocomplete): add function
1 parent d349e4c commit 64d6641

File tree

4 files changed

+51
-6
lines changed

4 files changed

+51
-6
lines changed

packages/autocomplete/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
"type": "module",
2222
"devDependencies": {
2323
"@svelement-ui/input": "workspace:^",
24+
"@svelement-ui/scrollbar": "workspace:^",
2425
"@svelement-ui/theme-chalk": "workspace:^",
2526
"@svelement-ui/tooltip": "workspace:^",
2627
"@svelement-ui/util-array-2-class-string": "workspace:^"

packages/autocomplete/src/lib/autocomplete.svelte

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,23 @@
22
import a2s from '@svelement-ui/util-array-2-class-string';
33
import SvelInput from '@svelement-ui/input';
44
import SvelTooltip from '@svelement-ui/tooltip';
5+
import SvelScrollbar from '@svelement-ui/scrollbar';
56
import { getContext } from 'svelte';
67
78
export let value;
9+
export let fetchSuggestions;
10+
export let triggerOnFocus = true;
11+
12+
let suggestions = [];
13+
let dropdownWidth = '';
14+
let ignoreFocusEvent = false;
15+
let suggestionDisabled = false;
16+
let loading = false;
17+
let activated = false;
818
let tooltipVisible = false;
919
$: dark = dark || getContext('svel-dark');
1020
11-
function handleInputClick() {
12-
console.log(tooltipVisible);
21+
function handleFocus() {
1322
tooltipVisible = true;
1423
}
1524
@@ -18,14 +27,20 @@
1827
}
1928
</script>
2029

21-
<SvelTooltip visible={tooltipVisible}>
30+
<SvelTooltip effect="light" visible={tooltipVisible}>
2231
<div
2332
aria-controls="svel-id-6711-108"
2433
aria-expanded="false"
2534
aria-haspopup="listbox"
2635
role="combobox"
2736
>
28-
<SvelInput bind:value on:blur={handleInputBlur} on:focus={handleInputClick} />
37+
<SvelInput bind:value on:blur={handleInputBlur} on:focus={handleFocus} />
38+
</div>
39+
<div slot="content">
40+
<div role="region">
41+
<SvelScrollbar>
42+
<li>1</li>
43+
</SvelScrollbar>
44+
</div>
2945
</div>
30-
<div slot="content">11111111111111111</div>
3146
</SvelTooltip>
Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,31 @@
11
<script>
22
import SvelAutoComplete from '$lib/index.js';
3+
4+
let value = '';
5+
const restaurants = [];
6+
const querySearch = (queryString, cb) => {
7+
const results = queryString
8+
? restaurants.value.filter(createFilter(queryString))
9+
: restaurants.value;
10+
// call callback function to return suggestions
11+
cb(results);
12+
};
13+
const createFilter = (queryString) => {
14+
return (restaurant) => {
15+
return restaurant.value.toLowerCase().indexOf(queryString.toLowerCase()) === 0;
16+
};
17+
};
18+
const loadAll = () => {
19+
return [
20+
{ value: 'vue', link: 'https://github.com/vuejs/vue' },
21+
{ value: 'element', link: 'https://github.com/ElemeFE/element' },
22+
{ value: 'cooking', link: 'https://github.com/ElemeFE/cooking' },
23+
{ value: 'mint-ui', link: 'https://github.com/ElemeFE/mint-ui' },
24+
{ value: 'vuex', link: 'https://github.com/vuejs/vuex' },
25+
{ value: 'vue-router', link: 'https://github.com/vuejs/vue-router' },
26+
{ value: 'babel', link: 'https://github.com/babel/babel' },
27+
];
28+
};
329
</script>
430

5-
<SvelAutoComplete>aaaa</SvelAutoComplete>
31+
<SvelAutoComplete fetchSuggestions={querySearch} />

pnpm-lock.yaml

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)