Skip to content

Commit

Permalink
fix(pop-confirm): 修复搜索时在中文输入法下按回车键弹窗会关闭的问题(XiaoMi#2809)
Browse files Browse the repository at this point in the history
  • Loading branch information
xiamiao committed Apr 23, 2024
1 parent 4218b57 commit d29df7e
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion packages/ui/select/src/Select.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -186,11 +186,12 @@ export const Select = forwardRef<HTMLDivElement | null, SelectProps>(
const defaultIndex = showData.findIndex((item: SelectDataItem) => !item.disabled)

const [focusedIndex, setFocusedIndex] = useState<number>(defaultIndex)
const [isComposing, setIsComposing] = useState<boolean>(false)

const handleKeyDown = useLatestCallback((evt: React.KeyboardEvent) => {
const { key } = evt

if (key === 'Enter') {
if (key === 'Enter' && !isComposing) {
const item = showData[focusedIndex]

if (item) {
Expand Down Expand Up @@ -235,6 +236,12 @@ export const Select = forwardRef<HTMLDivElement | null, SelectProps>(
onKeyDown={mockDefaultHandlers(handleKeyDown, onKeyDownProp)}
onOpen={menuVisibleAction.on}
onClose={menuVisibleAction.off}
onCompositionStart={() => {
setIsComposing(true)
}}
onCompositionEnd={() => {
setIsComposing(false)
}}
searchable={searchable}
keyword={keywordProp}
onSearch={callAllFuncs(onSearchProp, onSearch)}
Expand Down

0 comments on commit d29df7e

Please sign in to comment.