-
-
Notifications
You must be signed in to change notification settings - Fork 338
fix: holding left click breaks mask #959
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 6 commits
663937f
fde8fad
5b1a920
d7a17cd
caa9ce8
d87b9d1
b8bb7e1
8079b67
3db54d4
ccd4c43
d3c0f5f
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 |
|---|---|---|
|
|
@@ -97,6 +97,8 @@ const Input = React.forwardRef<InputRef, InputProps>((props, ref) => { | |
| // ========================= Refs ========================= | ||
| const holderRef = React.useRef<HTMLDivElement>(null); | ||
| const inputRef = React.useRef<HTMLInputElement>(null); | ||
| // When mousedown get focus, defer selection to mouseUp so click position is used | ||
| const mouseDownRef = React.useRef(false); | ||
|
|
||
| React.useImperativeHandle(ref, () => ({ | ||
| nativeElement: holderRef.current, | ||
|
|
@@ -153,6 +155,12 @@ const Input = React.forwardRef<InputRef, InputProps>((props, ref) => { | |
| }; | ||
|
|
||
| const onFormatPaste: React.ClipboardEventHandler<HTMLInputElement> = (event) => { | ||
| // Block paste until selection is set (after mouseUp when focus was by mousedown) | ||
| if (mouseDownRef.current) { | ||
| event.preventDefault(); | ||
| return; | ||
| } | ||
|
|
||
| // Get paste text | ||
| const pasteText = event.clipboardData.getData('text'); | ||
|
|
||
|
|
@@ -164,8 +172,6 @@ const Input = React.forwardRef<InputRef, InputProps>((props, ref) => { | |
| // ======================== Mouse ========================= | ||
| // When `mouseDown` get focus, it's better to not to change the selection | ||
| // Since the up position maybe not is the first cell | ||
| const mouseDownRef = React.useRef(false); | ||
|
|
||
| const onFormatMouseDown: React.MouseEventHandler<HTMLInputElement> = () => { | ||
| mouseDownRef.current = true; | ||
| }; | ||
|
|
@@ -225,6 +231,25 @@ const Input = React.forwardRef<InputRef, InputProps>((props, ref) => { | |
|
|
||
| const { key } = event; | ||
|
|
||
| // Block mask editing until selection is set (after mouseUp when focus was by mousedown). | ||
| // Still allow shared handlers (onKeyDown, Enter submit) above to run. | ||
| if (mouseDownRef.current) { | ||
|
claytonlin1110 marked this conversation as resolved.
|
||
| const shouldBlock = | ||
| key.length === 1 || | ||
| key === 'Backspace' || | ||
| key === 'Delete' || | ||
| key === 'ArrowLeft' || | ||
| key === 'ArrowRight' || | ||
| key === 'ArrowUp' || | ||
| key === 'ArrowDown'; | ||
|
|
||
| if (shouldBlock) { | ||
| event.preventDefault(); | ||
| } | ||
|
|
||
| return; | ||
| } | ||
|
|
||
| // Save the cache with cell text | ||
| let nextCellText: string = null; | ||
|
|
||
|
|
@@ -334,16 +359,21 @@ const Input = React.forwardRef<InputRef, InputProps>((props, ref) => { | |
| const rafRef = React.useRef<number>(); | ||
|
|
||
| useLayoutEffect(() => { | ||
| if (!focused || !format || mouseDownRef.current) { | ||
| if (!focused || !format) { | ||
|
claytonlin1110 marked this conversation as resolved.
Outdated
|
||
| return; | ||
| } | ||
|
|
||
| // Reset with format if not match | ||
| // Reset with format if not match (always apply when focused so mask works when focusing by mousedown) | ||
|
Member
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. 这里和下面没有还原呀…………
另外,CI 还是失败的哈~ https://github.com/react-component/picker/actions/runs/22935988370/job/66567899243?pr=959
Contributor
Author
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. Just updated, please re-run CI
Contributor
Author
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. |
||
| if (!maskFormat.match(inputValue)) { | ||
| triggerInputChange(format); | ||
| return; | ||
| } | ||
|
|
||
| // When mousedown get focus, defer selection to mouseUp so click position is used | ||
| if (mouseDownRef.current) { | ||
| return; | ||
| } | ||
|
|
||
| // Match the selection range | ||
| inputRef.current.setSelectionRange(selectionStart, selectionEnd); | ||
|
|
||
|
|
||

Uh oh!
There was an error while loading. Please reload this page.