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 61a4ee9
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 8 deletions.
13 changes: 8 additions & 5 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 @@ -109,7 +109,10 @@ class ResizableTextArea extends React.Component<TextAreaProps, TextAreaState> {
// https://github.com/ant-design/ant-design/issues/21870
fixFirefoxAutoScroll() {
try {
if (document.activeElement === this.textArea) {
if (
navigator.userAgent.includes('Firefox') &&
document.activeElement === this.textArea
) {
const currentStart = this.textArea.selectionStart;
const currentEnd = this.textArea.selectionEnd;
this.textArea.setSelectionRange(currentStart, currentEnd);
Expand Down
15 changes: 12 additions & 3 deletions tests/index.spec.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
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);

let userAgentGetter;

beforeEach(() => {
userAgentGetter = jest.spyOn(window.navigator, 'userAgent', 'get');
});

describe('TextArea', () => {
const originalGetComputedStyle = window.getComputedStyle;
beforeAll(() => {
Expand Down Expand Up @@ -241,6 +246,9 @@ describe('TextArea', () => {
});

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

0 comments on commit 61a4ee9

Please sign in to comment.