Skip to content

Commit

Permalink
fix: Inconsistent use of accents in Safari react-component#16
Browse files Browse the repository at this point in the history
  • Loading branch information
blacktail committed Jul 18, 2022
1 parent 12dc37f commit b63ed56
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 36 deletions.
24 changes: 4 additions & 20 deletions src/ResizableTextArea.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import * as React from 'react';
import classNames from 'classnames';
import ResizeObserver from 'rc-resize-observer';
import omit from 'rc-util/lib/omit';
import classNames from 'classnames';
import calculateNodeHeight from './calculateNodeHeight';
import type { TextAreaProps } from '.';
import * as React from 'react';
import shallowEqual from 'shallowequal';
import type { TextAreaProps } from '.';
import calculateNodeHeight from './calculateNodeHeight';

// eslint-disable-next-line @typescript-eslint/naming-convention
enum RESIZE_STATUS {
Expand Down Expand Up @@ -93,7 +93,6 @@ class ResizableTextArea extends React.Component<TextAreaProps, TextAreaState> {
this.setState({ resizeStatus: RESIZE_STATUS.RESIZED }, () => {
this.resizeFrameId = requestAnimationFrame(() => {
this.setState({ resizeStatus: RESIZE_STATUS.NONE });
this.fixFirefoxAutoScroll();
});
});
});
Expand All @@ -106,21 +105,6 @@ class ResizableTextArea extends React.Component<TextAreaProps, TextAreaState> {
cancelAnimationFrame(this.resizeFrameId);
}

// https://github.com/ant-design/ant-design/issues/21870
fixFirefoxAutoScroll() {
try {
if (document.activeElement === this.textArea) {
const currentStart = this.textArea.selectionStart;
const currentEnd = this.textArea.selectionEnd;
this.textArea.setSelectionRange(currentStart, currentEnd);
}
} catch (e) {
// Fix error in Chrome:
// Failed to read the 'selectionStart' property from 'HTMLInputElement'
// http://stackoverflow.com/q/21177489/3040605
}
}

renderTextArea = () => {
const {
prefixCls = 'rc-textarea',
Expand Down
17 changes: 1 addition & 16 deletions tests/index.spec.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import React from 'react';
import { mount } from 'enzyme';
import TextArea from '../src';
import { focusTest, sleep } from './utils';
import calculateNodeHeight, {
calculateNodeStyling,
} from '../src/calculateNodeHeight';
import { focusTest, sleep } from './utils';

focusTest(TextArea);

Expand Down Expand Up @@ -239,18 +238,4 @@ describe('TextArea', () => {
}),
);
});

it('scroll to bottom when autoSize', async () => {
const wrapper = mount(<TextArea autoSize />, { attachTo: document.body });
wrapper.find('textarea').simulate('focus');
wrapper.find('textarea').getDOMNode().focus();
const setSelectionRangeFn = jest.spyOn(
wrapper.find('textarea').getDOMNode(),
'setSelectionRange',
);
wrapper.find('textarea').simulate('change', { target: { value: '\n1' } });
await sleep(100);
expect(setSelectionRangeFn).toHaveBeenCalled();
wrapper.unmount();
});
});

0 comments on commit b63ed56

Please sign in to comment.