From 957e78b4374d630e44b2a3ce94b16dfaad28e9ec Mon Sep 17 00:00:00 2001 From: Mikhail Shatikhin Date: Wed, 13 Nov 2024 17:19:41 +0500 Subject: [PATCH] fix: add fixes --- .../Simple Components/chrome2022.png | 4 +- .../Simple Components/chrome2022Dark.png | 4 +- .../Simple Components/firefox2022.png | 4 +- .../Simple Components/firefox2022Dark.png | 4 +- .../PasswordInput/PasswordInput.tsx | 27 +++- .../components/TokenInput/TokenInput.tsx | 6 +- .../react-ui/components/Tooltip/Tooltip.tsx | 14 +-- .../__stories__/shadowDom.stories.tsx | 118 +++++++++++++++--- .../FocusControlWrapper.tsx | 6 +- .../internal/InputLikeText/InputLikeText.tsx | 2 +- .../internal/RenderLayer/RenderLayer.tsx | 21 +--- packages/react-ui/lib/listenFocusOutside.ts | 24 +++- packages/react-ui/lib/theming/Emotion.ts | 13 +- 13 files changed, 183 insertions(+), 64 deletions(-) diff --git a/packages/react-ui/.creevey/images/ShadowDom/Simple Components/chrome2022.png b/packages/react-ui/.creevey/images/ShadowDom/Simple Components/chrome2022.png index 240b16e3695..3c2cd242a4e 100644 --- a/packages/react-ui/.creevey/images/ShadowDom/Simple Components/chrome2022.png +++ b/packages/react-ui/.creevey/images/ShadowDom/Simple Components/chrome2022.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:6cc3c658f2ae82b2ae08fef7e191635f8e7a3545ef42f4b4e56c3ab319a827a6 -size 167283 +oid sha256:9ff642e3117c121baed3eb2789efd0458028d8e255bbce995551243273075914 +size 184170 diff --git a/packages/react-ui/.creevey/images/ShadowDom/Simple Components/chrome2022Dark.png b/packages/react-ui/.creevey/images/ShadowDom/Simple Components/chrome2022Dark.png index b3e1077b6b3..852d5c560db 100644 --- a/packages/react-ui/.creevey/images/ShadowDom/Simple Components/chrome2022Dark.png +++ b/packages/react-ui/.creevey/images/ShadowDom/Simple Components/chrome2022Dark.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:a2ce0b69353558ad982f1199a2ff2f4278f86e8ea3e399417b170725fd5f1ea6 -size 178935 +oid sha256:1e37bfd545ea53c12d2ed98cd00de20002b499cc8c5a21534b2dc87dc8d9dad9 +size 195436 diff --git a/packages/react-ui/.creevey/images/ShadowDom/Simple Components/firefox2022.png b/packages/react-ui/.creevey/images/ShadowDom/Simple Components/firefox2022.png index bb2f669db6c..030df1ee665 100644 --- a/packages/react-ui/.creevey/images/ShadowDom/Simple Components/firefox2022.png +++ b/packages/react-ui/.creevey/images/ShadowDom/Simple Components/firefox2022.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:4f96d6174428983cac8fa928f5613ab1acab886dc9187cb108d9e8142ec8e8ec -size 173259 +oid sha256:0ca790782268d9981ec119681742446cb7557bf7f3be62f063bb7d74f28454cc +size 190015 diff --git a/packages/react-ui/.creevey/images/ShadowDom/Simple Components/firefox2022Dark.png b/packages/react-ui/.creevey/images/ShadowDom/Simple Components/firefox2022Dark.png index d11e5c3475c..7a1bb530d64 100644 --- a/packages/react-ui/.creevey/images/ShadowDom/Simple Components/firefox2022Dark.png +++ b/packages/react-ui/.creevey/images/ShadowDom/Simple Components/firefox2022Dark.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:6f8e8a1e89d0238123450719dba6ecf191b19dc10119760dde147304b604c4f6 -size 182232 +oid sha256:5f30fed6c6867cfb9ea50c3d2ab4754ea515feb2c069538b2f4f1459213ef626 +size 198772 diff --git a/packages/react-ui/components/PasswordInput/PasswordInput.tsx b/packages/react-ui/components/PasswordInput/PasswordInput.tsx index 9ad91598c1b..be4fcdddc44 100644 --- a/packages/react-ui/components/PasswordInput/PasswordInput.tsx +++ b/packages/react-ui/components/PasswordInput/PasswordInput.tsx @@ -28,6 +28,7 @@ export interface PasswordInputProps extends Pick, export interface PasswordInputState { visible: boolean; + focused: boolean; capsLockEnabled?: boolean | null; } @@ -63,6 +64,7 @@ export class PasswordInput extends React.PureComponent { - this.setState((prevState) => ({ visible: !prevState.visible }), this.handleFocus); + this.setState((prevState) => ({ visible: !prevState.visible }), this.handleFocusOnInput); }; - private handleFocus = () => { + private handleFocusOnInput = () => { if (this.input) { this.input.focus(); } }; + private handleFocus = (event: React.FocusEvent) => { + if (this.state.focused) { + return; + } + + this.setState({ focused: true }); + + if (this.props.onFocus) { + this.props.onFocus(event); + } + }; + private handleBlur = () => { if (this.input) { this.input.blur(); @@ -229,6 +243,12 @@ export class PasswordInput extends React.PureComponent { this.setState({ visible: false }); + + if (!this.state.focused) { + return; + } + + this.setState({ focused: false }); }; private renderMain = (props: CommonWrapperRestProps) => { @@ -238,10 +258,11 @@ export class PasswordInput extends React.PureComponent +
diff --git a/packages/react-ui/components/TokenInput/TokenInput.tsx b/packages/react-ui/components/TokenInput/TokenInput.tsx index 25bd72542ba..df878153134 100644 --- a/packages/react-ui/components/TokenInput/TokenInput.tsx +++ b/packages/react-ui/components/TokenInput/TokenInput.tsx @@ -40,6 +40,7 @@ import { createPropsGetter } from '../../lib/createPropsGetter'; import { getUid } from '../../lib/uidUtils'; import { TokenView } from '../Token/TokenView'; import { ThemeContext } from '../../lib/theming/ThemeContext'; +import { isShadowRoot } from '../../lib/shadowDom/isShadowRoot'; import { TokenInputLocale, TokenInputLocaleHelper } from './locale'; import { getStyles } from './TokenInput.styles'; @@ -725,7 +726,10 @@ export class TokenInput extends React.PureComponent) => { if (this.menuRef && globalObject.document) { const menu = getRootNode(this.tokensInputMenu?.getMenuRef()); - const relatedTarget = event.relatedTarget || globalObject.document.activeElement; + + const isShadowRootElement = isShadowRoot(this.emotion.sheet.container.getRootNode()); + const relatedTarget = + (isShadowRootElement ? event.target : event.relatedTarget) ?? globalObject.document.activeElement; if (menu && menu.contains(relatedTarget)) { return true; diff --git a/packages/react-ui/components/Tooltip/Tooltip.tsx b/packages/react-ui/components/Tooltip/Tooltip.tsx index 953551535cf..3cc7e6f3ba7 100644 --- a/packages/react-ui/components/Tooltip/Tooltip.tsx +++ b/packages/react-ui/components/Tooltip/Tooltip.tsx @@ -9,7 +9,7 @@ import { Popup, PopupPositionsType, PopupProps, ShortPopupPositionsType } from ' import { RenderLayer, RenderLayerProps } from '../../internal/RenderLayer'; import { Nullable } from '../../typings/utility-types'; import { MouseEventType } from '../../typings/event-types'; -import { containsTargetOrRenderContainer } from '../../lib/listenFocusOutside'; +import { clickOutsideContent } from '../../lib/listenFocusOutside'; import { Theme } from '../../lib/theming/Theme'; import { isTestEnv } from '../../lib/currentEnvironment'; import { CommonProps, CommonWrapper } from '../../internal/CommonWrapper'; @@ -17,7 +17,6 @@ import { rootNode, TSetRootNode } from '../../lib/rootNode'; import { InstanceWithAnchorElement } from '../../lib/InstanceWithAnchorElement'; import { createPropsGetter } from '../../lib/createPropsGetter'; import { CloseButtonIcon } from '../../internal/CloseButtonIcon/CloseButtonIcon'; -import { isInstanceOf } from '../../lib/isInstanceOf'; import { EmotionConsumer } from '../../lib/theming/Emotion'; import { ThemeContext } from '../../lib/theming/ThemeContext'; import { @@ -25,6 +24,7 @@ import { ReactUIFeatureFlags, ReactUIFeatureFlagsContext, } from '../../lib/featureFlagsContext'; +import { isShadowRoot } from '../../lib/shadowDom/isShadowRoot'; import { getStyles } from './Tooltip.styles'; @@ -548,12 +548,10 @@ export class Tooltip extends React.PureComponent imp } }; - private isClickOutsideContent(event: Event) { - if (this.contentElement && isInstanceOf(event.target, globalObject.Element)) { - return !containsTargetOrRenderContainer(event.target)(this.contentElement); - } - - return true; + private isClickOutsideContent(event: Event): boolean { + const node = this.contentElement; + const isShadowRootElement = isShadowRoot(this.emotion.sheet.container.getRootNode()); + return clickOutsideContent(event, node, isShadowRootElement); } private handleFocus = () => { diff --git a/packages/react-ui/components/__stories__/shadowDom.stories.tsx b/packages/react-ui/components/__stories__/shadowDom.stories.tsx index 3462498311c..2d9fba50090 100644 --- a/packages/react-ui/components/__stories__/shadowDom.stories.tsx +++ b/packages/react-ui/components/__stories__/shadowDom.stories.tsx @@ -56,24 +56,32 @@ const Components: React.JSX.Element[] = [ , ,
, - , - Promise.resolve([1, 2, 3])} />, + , + getItems={() => Promise.resolve([1, 2, 3])} renderItem={(x) => x} onValueChange={console.log} />, , , - , + , , - , - , - , + + MenuItem + MenuItem + MenuItem + , + DropdownMenu}> + MenuItem + MenuItem + MenuItem + , + , , gap, , - + , hint, - , + , , link, // , @@ -83,11 +91,13 @@ const Components: React.JSX.Element[] = [ // , // , , - , - , - , +
+ + , + , + , } />, - , // , // , , @@ -96,17 +106,86 @@ const Components: React.JSX.Element[] = [ { label: '1', value: '1' }, { label: '2', value: '2' }, ]} + onValueChange={console.log} />, , -