-
-
Notifications
You must be signed in to change notification settings - Fork 145
feat: Merge searchValue,autoClearSearchValue and onSearch into the showSearch field #593
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
Changes from 4 commits
8962114
d5d0a28
69fde3b
c438b45
bbc7203
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -1,17 +1,21 @@ | ||||||||||||||||||||||||||
| import warning from '@rc-component/util/lib/warning'; | ||||||||||||||||||||||||||
| import * as React from 'react'; | ||||||||||||||||||||||||||
| import type { CascaderProps, ShowSearchType } from '../Cascader'; | ||||||||||||||||||||||||||
| import type { CascaderProps, SearchConfig } from '../Cascader'; | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| // Convert `showSearch` to unique config | ||||||||||||||||||||||||||
| export default function useSearchConfig(showSearch?: CascaderProps['showSearch']) { | ||||||||||||||||||||||||||
| return React.useMemo<[boolean, ShowSearchType]>(() => { | ||||||||||||||||||||||||||
| export default function useSearchConfig(showSearch?: CascaderProps['showSearch'], props?: any) { | ||||||||||||||||||||||||||
| const { autoClearSearchValue, searchValue, onSearch } = props; | ||||||||||||||||||||||||||
| return React.useMemo<[boolean, SearchConfig]>(() => { | ||||||||||||||||||||||||||
|
Comment on lines
+6
to
+8
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion props 解构存在潜在运行时异常 当 -export default function useSearchConfig(showSearch?: CascaderProps['showSearch'], props?: any) {
- const { autoClearSearchValue, searchValue, onSearch } = props;
+export default function useSearchConfig(
+ showSearch?: CascaderProps['showSearch'],
+ props: Partial<Pick<CascaderProps, 'autoClearSearchValue' | 'searchValue' | 'onSearch'>> = {},
+) {
+ const { autoClearSearchValue, searchValue, onSearch } = props;这样既提供了类型约束,也为缺省情况兜底。 📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||
| if (!showSearch) { | ||||||||||||||||||||||||||
| return [false, {}]; | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| let searchConfig: ShowSearchType = { | ||||||||||||||||||||||||||
| let searchConfig: SearchConfig = { | ||||||||||||||||||||||||||
| matchInputWidth: true, | ||||||||||||||||||||||||||
| limit: 50, | ||||||||||||||||||||||||||
| autoClearSearchValue, | ||||||||||||||||||||||||||
| searchValue, | ||||||||||||||||||||||||||
| onSearch, | ||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| if (showSearch && typeof showSearch === 'object') { | ||||||||||||||||||||||||||
|
|
@@ -30,5 +34,5 @@ export default function useSearchConfig(showSearch?: CascaderProps['showSearch'] | |||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| return [true, searchConfig]; | ||||||||||||||||||||||||||
| }, [showSearch]); | ||||||||||||||||||||||||||
| }, [showSearch, autoClearSearchValue, searchValue, onSearch]); | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
showSearch行描述与含义不符且默认值箭头错误>字符应去掉;表格默认值应直接写false。📝 Committable suggestion
🤖 Prompt for AI Agents