|
1 | 1 | import * as React from 'react'; |
2 | 2 | import PropTypes from 'prop-types'; |
3 | 3 | import { expect } from 'chai'; |
4 | | -import { spy } from 'sinon'; |
| 4 | +import sinon, { spy } from 'sinon'; |
5 | 5 | import { act, createRenderer, fireEvent, screen, reactMajor } from '@mui/internal-test-utils'; |
6 | 6 | import { ThemeProvider } from '@emotion/react'; |
7 | 7 | import FormControl, { useFormControl } from '@mui/material/FormControl'; |
@@ -694,6 +694,32 @@ describe('<InputBase />', () => { |
694 | 694 | }); |
695 | 695 | }); |
696 | 696 |
|
| 697 | + describe('caret behavior', () => { |
| 698 | + it('should preserve caret position when clicking on the Root wrapper', () => { |
| 699 | + const clock = sinon.useFakeTimers(); |
| 700 | + |
| 701 | + const { container } = render(<InputBase defaultValue="hello" />); |
| 702 | + const input = container.querySelector('input'); |
| 703 | + |
| 704 | + act(() => { |
| 705 | + input.setSelectionRange(2, 2); |
| 706 | + }); |
| 707 | + |
| 708 | + const wrapper = input.parentElement; |
| 709 | + |
| 710 | + fireEvent.click(wrapper); |
| 711 | + |
| 712 | + act(() => { |
| 713 | + clock.runAll(); |
| 714 | + }); |
| 715 | + |
| 716 | + expect(input.selectionStart).to.equal(2); |
| 717 | + expect(input.selectionEnd).to.equal(2); |
| 718 | + |
| 719 | + clock.restore(); |
| 720 | + }); |
| 721 | + }); |
| 722 | + |
697 | 723 | describe('prop: focused', () => { |
698 | 724 | it('should render correct border color with `ThemeProvider` imported from `@emotion/react`', function test() { |
699 | 725 | if (window.navigator.userAgent.includes('jsdom')) { |
|
0 commit comments