Skip to content

Commit 61a4ee9

Browse files
committed
fix: Inconsistent use of accents in Safari #16
1 parent 12dc37f commit 61a4ee9

File tree

2 files changed

+20
-8
lines changed

2 files changed

+20
-8
lines changed

src/ResizableTextArea.tsx

+8-5
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
import * as React from 'react';
1+
import classNames from 'classnames';
22
import ResizeObserver from 'rc-resize-observer';
33
import omit from 'rc-util/lib/omit';
4-
import classNames from 'classnames';
5-
import calculateNodeHeight from './calculateNodeHeight';
6-
import type { TextAreaProps } from '.';
4+
import * as React from 'react';
75
import shallowEqual from 'shallowequal';
6+
import type { TextAreaProps } from '.';
7+
import calculateNodeHeight from './calculateNodeHeight';
88

99
// eslint-disable-next-line @typescript-eslint/naming-convention
1010
enum RESIZE_STATUS {
@@ -109,7 +109,10 @@ class ResizableTextArea extends React.Component<TextAreaProps, TextAreaState> {
109109
// https://github.com/ant-design/ant-design/issues/21870
110110
fixFirefoxAutoScroll() {
111111
try {
112-
if (document.activeElement === this.textArea) {
112+
if (
113+
navigator.userAgent.includes('Firefox') &&
114+
document.activeElement === this.textArea
115+
) {
113116
const currentStart = this.textArea.selectionStart;
114117
const currentEnd = this.textArea.selectionEnd;
115118
this.textArea.setSelectionRange(currentStart, currentEnd);

tests/index.spec.js

+12-3
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,18 @@
1-
import React from 'react';
21
import { mount } from 'enzyme';
32
import TextArea from '../src';
4-
import { focusTest, sleep } from './utils';
53
import calculateNodeHeight, {
64
calculateNodeStyling,
75
} from '../src/calculateNodeHeight';
6+
import { focusTest, sleep } from './utils';
87

98
focusTest(TextArea);
109

10+
let userAgentGetter;
11+
12+
beforeEach(() => {
13+
userAgentGetter = jest.spyOn(window.navigator, 'userAgent', 'get');
14+
});
15+
1116
describe('TextArea', () => {
1217
const originalGetComputedStyle = window.getComputedStyle;
1318
beforeAll(() => {
@@ -241,6 +246,9 @@ describe('TextArea', () => {
241246
});
242247

243248
it('scroll to bottom when autoSize', async () => {
249+
userAgentGetter.mockReturnValue(
250+
'Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:102.0) Gecko/20100101 Firefox/102.0',
251+
);
244252
const wrapper = mount(<TextArea autoSize />, { attachTo: document.body });
245253
wrapper.find('textarea').simulate('focus');
246254
wrapper.find('textarea').getDOMNode().focus();
@@ -250,7 +258,8 @@ describe('TextArea', () => {
250258
);
251259
wrapper.find('textarea').simulate('change', { target: { value: '\n1' } });
252260
await sleep(100);
253-
expect(setSelectionRangeFn).toHaveBeenCalled();
261+
if (navigator.userAgent.includes('Firefox'))
262+
expect(setSelectionRangeFn).toHaveBeenCalled();
254263
wrapper.unmount();
255264
});
256265
});

0 commit comments

Comments
 (0)