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

Feature/select(#2627) #2633

Merged
merged 4 commits into from
Oct 26, 2023
Merged
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 .changeset/light-moons-juggle.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@hi-ui/check-select": patch
---

CheckSelect dataSource 下搜索框增加防抖操作
5 changes: 5 additions & 0 deletions .changeset/rude-garlics-tickle.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@hi-ui/hiui": patch
---

CheckSelect Select dataSource 下搜索框增加防抖操作
5 changes: 5 additions & 0 deletions .changeset/three-dryers-collect.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@hi-ui/select": patch
---

Select dataSource 下搜索框增加防抖操作
5 changes: 5 additions & 0 deletions .changeset/unlucky-lizards-sleep.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@hi-ui/use-search-mode": patch
---

异步 search 增加防抖功能
1 change: 1 addition & 0 deletions packages/hooks/use-search-mode/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
"dependencies": {
"@hi-ui/dom-utils": "^4.0.4",
"@hi-ui/env": "^4.0.1",
"@hi-ui/func-utils": "^4.0.1",
"@hi-ui/loading": "^4.0.4",
"@hi-ui/tree-utils": "^4.0.2",
"@hi-ui/type-assertion": "^4.0.1",
Expand Down
7 changes: 5 additions & 2 deletions packages/hooks/use-search-mode/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { invariant } from '@hi-ui/env'
import { filterTree, getNodeAncestors, cloneTree } from '@hi-ui/tree-utils'
import { useLatestRef } from '@hi-ui/use-latest'
import { useUncontrolledState } from '@hi-ui/use-uncontrolled-state'
import { debounce } from '@hi-ui/func-utils'

const initialStateInSearch = () => ({
matched: false,
Expand Down Expand Up @@ -58,7 +59,9 @@ export const useSearchMode = ({
},
[searchable, setKeyword, runSearch]
)

const isAsyncMode = searchMode === 'dataSource'
// 只有异步搜索需要防抖,正常不需要
const debounceOnSearch = isAsyncMode ? debounce(onSearch) : onSearch
const keywordLatestRef = useLatestRef(keyword)

// 外部数据或策略改变时,重新触发搜索
Expand All @@ -73,7 +76,7 @@ export const useSearchMode = ({
searchable,
searchMode,
keyword,
onSearch,
onSearch: debounceOnSearch,
inSearch,
isEmpty,
state: stateInSearch,
Expand Down