Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support React versions 17 and 16 at the same time #2360

Merged
merged 8 commits into from
May 11, 2021
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ export const selectNodeContents = (node: HTMLElement | null, start?: number, end
if (!node) {
return;
}
if (document.createRange) {
if ('createRange' in document) {
try {
const selection = window.getSelection();
const range = window.document.createRange();
Expand Down
2 changes: 1 addition & 1 deletion packages/react-ui/components/Input/Input.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -466,7 +466,7 @@ export class Input extends React.Component<InputProps, InputState> {

if (this.props.selectAllOnFocus) {
// https://github.com/facebook/react/issues/7769
this.input ? this.selectAll() : this.delaySelectAll();
this.input && !isIE11 ? this.selectAll() : this.delaySelectAll();
}

if (this.props.onFocus) {
Expand Down
17 changes: 15 additions & 2 deletions packages/react-ui/components/Textarea/Textarea.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import React, { ReactNode } from 'react';
import PropTypes from 'prop-types';
import throttle from 'lodash.throttle';
import cn from 'classnames';
import raf from 'raf';

import { isKeyEnter } from '../../lib/events/keyboard/identifiers';
import { polyfillPlaceholder } from '../../lib/polyfillPlaceholder';
Expand All @@ -11,7 +12,7 @@ import { ThemeContext } from '../../lib/theming/ThemeContext';
import { Theme } from '../../lib/theming/Theme';
import { RenderLayer } from '../../internal/RenderLayer';
import { ResizeDetector } from '../../internal/ResizeDetector';
import { isBrowser } from '../../lib/client';
import { isBrowser, isIE11 } from '../../lib/client';
import { CommonProps, CommonWrapper, CommonWrapperRestProps } from '../../internal/CommonWrapper';
import { isTestEnv } from '../../lib/currentEnvironment';

Expand Down Expand Up @@ -189,6 +190,7 @@ export class Textarea extends React.Component<TextareaProps, TextareaState> {
};

private theme!: Theme;
private selectAllId: number | null = null;
private node: Nullable<HTMLTextAreaElement>;
private fakeNode: Nullable<HTMLTextAreaElement>;
private counter: Nullable<TextareaCounterRef>;
Expand Down Expand Up @@ -221,6 +223,7 @@ export class Textarea extends React.Component<TextareaProps, TextareaState> {
if (this.props.showLengthCounter && this.textareaObserver) {
this.textareaObserver.disconnect();
}
this.cancelDelayedSelectAll();
}

public componentDidUpdate(prevProps: TextareaProps) {
Expand Down Expand Up @@ -286,6 +289,15 @@ export class Textarea extends React.Component<TextareaProps, TextareaState> {
}
};

private delaySelectAll = (): number => (this.selectAllId = raf(this.selectAll));

private cancelDelayedSelectAll = (): void => {
if (this.selectAllId) {
raf.cancel(this.selectAllId);
this.selectAllId = null;
}
};

private renderMain = (props: CommonWrapperRestProps<TextareaProps>) => {
const {
width = DEFAULT_WIDTH,
Expand Down Expand Up @@ -497,7 +509,8 @@ export class Textarea extends React.Component<TextareaProps, TextareaState> {
this.setState({ isCounterVisible: true });

if (this.props.selectAllOnFocus) {
this.selectAll();
// https://github.com/facebook/react/issues/7769
this.node && !isIE11 ? this.selectAll() : this.delaySelectAll();
}

if (this.props.onFocus) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ class VariousAlignsPortalsItemsAndScrolls extends React.Component {
dropdownProps={{ align, disablePortal }}
>
<Menu>
<MenuItem>
<MenuItem style={{ pointerEvents: 'none' }}>
{`${row}/${col}/align-${align}/portal-${!disablePortal}; `.repeat(long ? 3 : 1)}
</MenuItem>
</Menu>
Expand Down
8 changes: 4 additions & 4 deletions packages/react-ui/lib/LayoutEvents.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ function getEmitter() {
}

function listenBrowserEvents() {
window.addEventListener('scroll', emit);
window.addEventListener('resize', emit);
window.addEventListener('scroll', emit, { capture: true });
window.addEventListener('resize', emit, { capture: true });
}

function unlistenBrowserEvents() {
window.removeEventListener('scroll', emit);
window.removeEventListener('resize', emit);
window.removeEventListener('scroll', emit, { capture: true });
window.removeEventListener('resize', emit, { capture: true });
}

export function addListener(callback: () => void) {
Expand Down
2 changes: 1 addition & 1 deletion packages/react-ui/lib/listenFocusOutside.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ function addHandleEvent() {
document.body.addEventListener(
isFirefox ? 'focus' : ('focusin' as 'focus'),
isFirefox ? debounce(handleNativeFocus, 0, { leading: true, trailing: false }) : handleNativeFocus,
isFirefox,
{ capture: true },
);
}

Expand Down
4 changes: 2 additions & 2 deletions packages/react-ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -154,8 +154,8 @@
"webpack": "^4.41.2"
},
"peerDependencies": {
"react": ">=16.9 <17",
"react-dom": ">=16.9 <17"
"react": ">=16.9",
"react-dom": ">=16.9"
},
"jest": {
"testResultsProcessor": "jest-teamcity-reporter",
Expand Down