Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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
9 changes: 7 additions & 2 deletions src/PickerInput/Selector/Input.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -334,16 +334,21 @@ const Input = React.forwardRef<InputRef, InputProps>((props, ref) => {
const rafRef = React.useRef<number>();

useLayoutEffect(() => {
if (!focused || !format || mouseDownRef.current) {
if (!focused || !format) {
Comment thread
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)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里和下面没有还原呀…………
你在 github 的 diff view 可以看的:

Image

另外,CI 还是失败的哈~

https://github.com/react-component/picker/actions/runs/22935988370/job/66567899243?pr=959

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just updated, please re-run CI

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The 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);

Expand Down
13 changes: 13 additions & 0 deletions tests/new-range.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1010,6 +1010,19 @@ describe('NewPicker.Range', () => {
expect(startInput.selectionEnd).toEqual(6);
});

it('focus by mousedown defers selection sync to mouseUp', () => {
const { container } = render(<Demo />);

const startInput = container.querySelectorAll<HTMLInputElement>('input')[0];

fireEvent.mouseDown(startInput);
fireEvent.focus(startInput);

fireEvent.mouseUp(startInput);
expect(startInput.selectionStart).toBeDefined();
expect(startInput.selectionEnd).toBeDefined();
});
Comment thread
claytonlin1110 marked this conversation as resolved.

it('blur to reset back text', async () => {
const { container } = render(<Demo />);

Expand Down