-
Notifications
You must be signed in to change notification settings - Fork 99
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
feat(select): 新增带搜索情况下,点击叉号按钮时下拉框同时清空(#2945) #2948
Merged
Merged
Changes from 5 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
e8190d4
feat(select): 新增带搜索情况下,点击叉号按钮时下拉框同时清空(#2945)
37d471c
chore(select): 生成变更记录文件
9a2f6ea
feat(select): 暴露onClear接口和searchValueProp传参
b4e364b
chore(select): 删除无用console
729614f
chore: refactor code
925f851
chore: refactor code
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@hi-ui/select": minor | ||
--- | ||
|
||
feat: 新增带搜索情况下,点击叉号按钮时下拉框同时清空 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@hi-ui/hiui": patch | ||
--- | ||
|
||
feat(select): 新增带搜索情况下,点击叉号按钮时下拉框同时清空 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -32,6 +32,7 @@ import { uniqBy } from '@hi-ui/array-utils' | |
import { HiBaseAppearanceEnum, HiBaseSizeEnum, useLocaleContext } from '@hi-ui/core' | ||
import { callAllFuncs } from '@hi-ui/func-utils' | ||
import { mockDefaultHandlers } from '@hi-ui/dom-utils' | ||
import { mergeRefs } from '@hi-ui/react-utils' | ||
|
||
const _role = 'select' | ||
const _prefix = getPrefixCls(_role) | ||
|
@@ -77,13 +78,14 @@ export const Select = forwardRef<HTMLDivElement | null, SelectProps>( | |
onSelect: onSelectProp, | ||
onSearch: onSearchProp, | ||
onKeyDown: onKeyDownProp, | ||
onClear: onClearProp, | ||
customRender, | ||
...rest | ||
}, | ||
ref | ||
) => { | ||
const i18n = useLocaleContext() | ||
|
||
const innerRef = useRef<HTMLDivElement>() | ||
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. HTMLDivElement 改为上面说的 PikcerHelper |
||
const placeholder = isUndef(placeholderProp) ? i18n.get('select.placeholder') : placeholderProp | ||
|
||
const [menuVisible, menuVisibleAction] = useUncontrolledToggle({ | ||
|
@@ -227,7 +229,7 @@ export const Select = forwardRef<HTMLDivElement | null, SelectProps>( | |
return ( | ||
<SelectProvider value={context}> | ||
<Picker | ||
ref={ref} | ||
ref={mergeRefs(ref, innerRef)} | ||
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. 建议将 innerRef 放在该行下面,另外有了 innerRef 后不需要在使用 mergeRefs |
||
className={cls} | ||
{...rootProps} | ||
visible={menuVisible} | ||
|
@@ -241,6 +243,7 @@ export const Select = forwardRef<HTMLDivElement | null, SelectProps>( | |
loading={rest.loading !== undefined ? rest.loading : loading} | ||
footer={renderExtraFooter ? renderExtraFooter() : null} | ||
scrollable={!inVirtual} | ||
innerRef={innerRef} | ||
trigger={ | ||
customRender ? ( | ||
typeof customRender === 'function' ? ( | ||
|
@@ -265,6 +268,11 @@ export const Select = forwardRef<HTMLDivElement | null, SelectProps>( | |
value={value} | ||
onChange={(value, item) => { | ||
tryChangeValue(value, item.raw) | ||
// 非受控模式下清空下拉框 | ||
if (value === '') { | ||
innerRef.current?.resetSearch() | ||
onClearProp?.() | ||
} | ||
}} | ||
size={size} | ||
data={mergedData} | ||
|
@@ -377,6 +385,10 @@ export interface SelectProps | |
* 搜索时触发 | ||
*/ | ||
onSearch?: (keyword: string) => void | ||
/** | ||
* 点击关闭按钮时触发 | ||
*/ | ||
onClear?: () => void | ||
/** | ||
* 设置大小 | ||
*/ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
HTMLDivElement 改为 useImperativeHandle 中声明的方法,例如:interface PikcerHelper {resetSearch: () => void}