@skbkontur/react-ui 6.5.3 → 6.5.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,17 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
## [6.5.4](https://github.com/skbkontur/retail-ui/compare/@skbkontur/react-ui@6.5.3...@skbkontur/react-ui@6.5.4) (2026-11-19)
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
### Bug Fixes
|
|
10
|
+
|
|
11
|
+
* **PasswordInput:** validate when focus leaves the component ([029514e](https://github.com/skbkontur/retail-ui/commit/029514e63d7650d99918e9c9b26c2fcddc19f1fe))
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
|
|
6
17
|
## [6.5.3](https://github.com/skbkontur/retail-ui/compare/@skbkontur/react-ui@6.5.2...@skbkontur/react-ui@6.5.3) (2026-11-18)
|
|
7
18
|
|
|
8
19
|
|
|
@@ -30,6 +30,7 @@ export declare class PasswordInput extends React.PureComponent<PasswordInputProp
|
|
|
30
30
|
private styles;
|
|
31
31
|
private theme;
|
|
32
32
|
private input;
|
|
33
|
+
private pendingInputBlur;
|
|
33
34
|
getRootNode: TGetRootNode;
|
|
34
35
|
private setRootNode;
|
|
35
36
|
private readonly locale;
|
|
@@ -54,6 +55,8 @@ export declare class PasswordInput extends React.PureComponent<PasswordInputProp
|
|
|
54
55
|
private focusOnInput;
|
|
55
56
|
private handleFocus;
|
|
56
57
|
private handleFocusOutside;
|
|
58
|
+
private handleInputBlur;
|
|
59
|
+
private handleBlur;
|
|
57
60
|
private getEyeWrapperClassname;
|
|
58
61
|
private renderEye;
|
|
59
62
|
private refInput;
|
|
@@ -74,6 +74,7 @@ var PasswordInput = /** @class */ (function (_super) {
|
|
|
74
74
|
focused: false,
|
|
75
75
|
capsLockEnabled: false,
|
|
76
76
|
};
|
|
77
|
+
_this.pendingInputBlur = null;
|
|
77
78
|
_this.getProps = createPropsGetter({});
|
|
78
79
|
/** Программно устанавливает фокус на поле.
|
|
79
80
|
* Появляется фокусная рамка, элемент получает клавиатурные события и воспринимается как текущий элемент для чтения скринридерами.
|
|
@@ -124,6 +125,7 @@ var PasswordInput = /** @class */ (function (_super) {
|
|
|
124
125
|
}
|
|
125
126
|
};
|
|
126
127
|
_this.handleFocus = function (event) {
|
|
128
|
+
_this.pendingInputBlur = null;
|
|
127
129
|
if (_this.state.focused) {
|
|
128
130
|
return;
|
|
129
131
|
}
|
|
@@ -138,6 +140,27 @@ var PasswordInput = /** @class */ (function (_super) {
|
|
|
138
140
|
_this.setState({ focused: false });
|
|
139
141
|
}
|
|
140
142
|
};
|
|
143
|
+
_this.handleInputBlur = function (event) {
|
|
144
|
+
event.persist();
|
|
145
|
+
_this.pendingInputBlur = event;
|
|
146
|
+
};
|
|
147
|
+
_this.handleBlur = function (event) {
|
|
148
|
+
var _a, _b, _c;
|
|
149
|
+
if (event.currentTarget.contains(event.relatedTarget)) {
|
|
150
|
+
return;
|
|
151
|
+
}
|
|
152
|
+
var inputBlur = _this.pendingInputBlur;
|
|
153
|
+
_this.pendingInputBlur = null;
|
|
154
|
+
var input = (_a = _this.input) === null || _a === void 0 ? void 0 : _a.getNode();
|
|
155
|
+
if (input) {
|
|
156
|
+
// Preserve the input event contract even when focus leaves via the visibility button.
|
|
157
|
+
(_c = (_b = _this.props).onBlur) === null || _c === void 0 ? void 0 : _c.call(_b, Object.assign(Object.create(inputBlur !== null && inputBlur !== void 0 ? inputBlur : event), {
|
|
158
|
+
currentTarget: input,
|
|
159
|
+
target: input,
|
|
160
|
+
relatedTarget: event.relatedTarget,
|
|
161
|
+
}));
|
|
162
|
+
}
|
|
163
|
+
};
|
|
141
164
|
_this.renderEye = function () {
|
|
142
165
|
var capsLockEnabled = _this.state.capsLockEnabled;
|
|
143
166
|
return (React.createElement("span", { className: _this.styles.iconWrapper() },
|
|
@@ -152,10 +175,10 @@ var PasswordInput = /** @class */ (function (_super) {
|
|
|
152
175
|
_this.setState({ visible: false });
|
|
153
176
|
};
|
|
154
177
|
_this.renderMain = function (props) {
|
|
155
|
-
var detectCapsLock = props.detectCapsLock, rest = __rest(props, ["detectCapsLock"]);
|
|
178
|
+
var detectCapsLock = props.detectCapsLock, onBlur = props.onBlur, rest = __rest(props, ["detectCapsLock", "onBlur"]);
|
|
156
179
|
return (React.createElement(RenderLayer, { active: _this.state.focused, onFocusOutside: _this.handleFocusOutside, onClickOutside: _this.handleFocusOutside },
|
|
157
|
-
React.createElement("div", { "data-tid": PasswordInputDataTids.root, className: _this.styles.root() },
|
|
158
|
-
React.createElement(Input, __assign({ ref: _this.refInput, type: _this.state.visible ? 'text' : 'password' }, rest, { onKeyDown: _this.handleKeydown, onKeyPress: _this.handleKeyPress, rightIcon: _this.renderEye(), onFocus: _this.handleFocus })))));
|
|
180
|
+
React.createElement("div", { "data-tid": PasswordInputDataTids.root, className: _this.styles.root(), onBlur: _this.handleBlur },
|
|
181
|
+
React.createElement(Input, __assign({ ref: _this.refInput, type: _this.state.visible ? 'text' : 'password' }, rest, { onKeyDown: _this.handleKeydown, onKeyPress: _this.handleKeyPress, rightIcon: _this.renderEye(), onFocus: _this.handleFocus, onBlurCapture: _this.handleInputBlur })))));
|
|
159
182
|
};
|
|
160
183
|
return _this;
|
|
161
184
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PasswordInput.js","sourceRoot":"","sources":["PasswordInput.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEA,OAAO,KAAK,MAAM,OAAO,CAAC;AAG1B,OAAO,EAAE,aAAa,EAAE,MAAM,uCAAuC,CAAC;AACtE,OAAO,EAAE,WAAW,EAAE,MAAM,qCAAqC,CAAC;AAClE,OAAO,EAAE,iBAAiB,EAA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jC,aAAa;QAJzB,qBAAqB;QACrB,QAAQ;QACR,MAAM,CAAC,eAAe,EAAE,yBAAyB,CAAC;QAClD,QAAQ;OACI,aAAa,CA6MzB;IAAD,oBAAC;CAAA,AA7MD,CAAmC,KAAK,CAAC,aAAa,GA6MrD;SA7MY,aAAa","sourcesContent":["import type { Emotion } from '@emotion/css/create-instance';\nimport type { AriaAttributes, JSX } from 'react';\nimport React from 'react';\n\nimport type { CommonProps, CommonWrapperRestProps } from '../../internal/CommonWrapper/index.js';\nimport { CommonWrapper } from '../../internal/CommonWrapper/index.js';\nimport { RenderLayer } from '../../internal/RenderLayer/index.js';\nimport { createPropsGetter } from '../../lib/createPropsGetter.js';\nimport { isKeyCapsLock } from '../../lib/events/keyboard/identifiers.js';\nimport { KeyboardEventCodes as Codes } from '../../lib/events/keyboard/KeyboardEventCodes.js';\nimport { locale } from '../../lib/locale/decorators.js';\nimport { withRenderEnvironment } from '../../lib/renderEnvironment/RenderEnvironmentDecorator.js';\nimport type { TGetRootNode, TSetRootNode } from '../../lib/rootNode/index.js';\nimport { rootNode } from '../../lib/rootNode/index.js';\nimport { withSize } from '../../lib/size/SizeDecorator.js';\nimport type { Theme } from '../../lib/theming/Theme.js';\nimport { ThemeContext } from '../../lib/theming/ThemeContext.js';\nimport type { SizeProp } from '../../lib/types/props.js';\nimport { isNonNullable } from '../../lib/utils.js';\nimport type { Nullable } from '../../typings/utility-types.js';\nimport { Input } from '../Input/index.js';\nimport type { InputProps } from '../Input/index.js';\nimport type { PasswordInputLocale } from './locale/index.js';\nimport { PasswordInputLocaleHelper } from './locale/index.js';\nimport { getStyles } from './PasswordInput.styles.js';\nimport { PasswordInputIcon } from './PasswordInputIcon.js';\n\nexport interface PasswordInputProps\n extends Pick<AriaAttributes, 'aria-label'>, CommonProps, Omit<InputProps, 'showClearIcon'> {\n /** Визуально показывает, что активен CapsLock. */\n detectCapsLock?: boolean;\n}\n\nexport interface PasswordInputState {\n visible: boolean;\n focused: boolean;\n capsLockEnabled?: boolean | null;\n}\n\nexport const PasswordInputDataTids = {\n root: 'PasswordInput',\n capsLockDetector: 'PasswordInputCapsLockDetector',\n eyeIcon: 'PasswordInputEyeIcon',\n} as const;\n\n/**\n * Однострочное поле для ввода пароля, в котором символы заменяются на точки.\n */\n@withRenderEnvironment\n@rootNode\n@locale('PasswordInput', PasswordInputLocaleHelper)\n@withSize\nexport class PasswordInput extends React.PureComponent<PasswordInputProps, PasswordInputState> {\n public static __KONTUR_REACT_UI__ = 'PasswordInput';\n public static displayName = 'PasswordInput';\n\n public state: PasswordInputState = {\n visible: false,\n focused: false,\n capsLockEnabled: false,\n };\n private size!: SizeProp;\n\n private emotion!: Emotion;\n private cx!: Emotion['cx'];\n private styles!: ReturnType<typeof getStyles>;\n private theme!: Theme;\n\n private input: Nullable<Input>;\n public getRootNode!: TGetRootNode;\n private setRootNode!: TSetRootNode;\n private readonly locale!: PasswordInputLocale;\n\n private getProps = createPropsGetter({});\n\n public componentDidMount() {\n if (this.props.detectCapsLock) {\n this.setState({ capsLockEnabled: null });\n }\n }\n\n public static getDerivedStateFromProps(props: PasswordInputProps, state: PasswordInputState) {\n if (props.disabled) {\n return { visible: false };\n }\n\n return state;\n }\n\n public render(): JSX.Element {\n this.styles = getStyles(this.emotion);\n\n return (\n <ThemeContext.Consumer>\n {(theme) => {\n this.theme = theme;\n return (\n <CommonWrapper rootNodeRef={this.setRootNode} {...this.getProps()}>\n {this.renderMain}\n </CommonWrapper>\n );\n }}\n </ThemeContext.Consumer>\n );\n }\n\n /** Программно устанавливает фокус на поле.\n * Появляется фокусная рамка, элемент получает клавиатурные события и воспринимается как текущий элемент для чтения скринридерами.\n * @public\n */\n public focus = (): void => {\n if (this.input) {\n this.input.focus();\n }\n };\n\n /** Программно снимает фокус с кнопки.\n * @public\n */\n public blur = (): void => {\n if (this.input) {\n this.input.blur();\n }\n };\n\n private handleKeyPress = (e: React.KeyboardEvent<HTMLInputElement>) => {\n const { onKeyPress, detectCapsLock } = this.props;\n\n if (onKeyPress) {\n onKeyPress(e);\n }\n\n if (!detectCapsLock) {\n return;\n }\n\n const capsLockEnabled = e.getModifierState(Codes.CapsLock);\n\n this.setState({ capsLockEnabled });\n };\n\n private handleKeydown = (e: React.KeyboardEvent<HTMLInputElement>) => {\n const {\n props: { detectCapsLock, onKeyDown },\n state: { capsLockEnabled },\n } = this;\n\n if (onKeyDown) {\n onKeyDown(e);\n }\n\n if (!detectCapsLock) {\n return;\n }\n\n if (isKeyCapsLock(e) && isNonNullable(capsLockEnabled)) {\n this.setState({ capsLockEnabled: !capsLockEnabled });\n }\n };\n\n private handleToggleVisibility = () => {\n this.setState((prevState) => ({ visible: !prevState.visible }), this.focusOnInput);\n };\n\n private focusOnInput = () => {\n if (this.input) {\n this.input.focus();\n }\n };\n\n private handleFocus = (event: React.FocusEvent<HTMLInputElement>) => {\n if (this.state.focused) {\n return;\n }\n\n this.setState({ focused: true });\n\n if (this.props.onFocus) {\n this.props.onFocus(event);\n }\n };\n\n private handleFocusOutside = () => {\n this.hideSymbols();\n\n if (this.state.focused) {\n this.setState({ focused: false });\n }\n };\n\n private getEyeWrapperClassname() {\n switch (this.size) {\n case 'large':\n return this.styles.eyeWrapperLarge(this.theme);\n case 'medium':\n return this.styles.eyeWrapperMedium(this.theme);\n case 'small':\n default:\n return this.styles.eyeWrapperSmall(this.theme);\n }\n }\n\n private renderEye = () => {\n const { capsLockEnabled } = this.state;\n\n return (\n <span className={this.styles.iconWrapper()}>\n {capsLockEnabled && (\n <span className={this.styles.capsLockDetector()} data-tid={PasswordInputDataTids.capsLockDetector} />\n )}\n <span className={this.cx(this.styles.toggleVisibility(this.theme), this.getEyeWrapperClassname())}>\n {!this.props.disabled && (\n <button\n type=\"button\"\n aria-label={this.state.visible ? this.locale.eyeClosedAriaLabel : this.locale.eyeOpenedAriaLabel}\n onClick={this.handleToggleVisibility}\n className={this.styles.icon()}\n data-tid={PasswordInputDataTids.eyeIcon}\n >\n <PasswordInputIcon size={this.size} visible={this.state.visible} />\n </button>\n )}\n </span>\n </span>\n );\n };\n\n private refInput = (element: Input) => {\n this.input = element;\n };\n\n private hideSymbols = () => {\n this.setState({ visible: false });\n };\n\n private renderMain = (props: CommonWrapperRestProps<PasswordInputProps>) => {\n const { detectCapsLock, ...rest } = props;\n return (\n <RenderLayer\n active={this.state.focused}\n onFocusOutside={this.handleFocusOutside}\n onClickOutside={this.handleFocusOutside}\n >\n <div data-tid={PasswordInputDataTids.root} className={this.styles.root()}>\n <Input\n ref={this.refInput}\n type={this.state.visible ? 'text' : 'password'}\n {...rest}\n onKeyDown={this.handleKeydown}\n onKeyPress={this.handleKeyPress}\n rightIcon={this.renderEye()}\n onFocus={this.handleFocus}\n />\n </div>\n </RenderLayer>\n );\n };\n}\n"]}
|
|
1
|
+
{"version":3,"file":"PasswordInput.js","sourceRoot":"","sources":["PasswordInput.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEA,OAAO,KAAK,MAAM,OAAO,CAAC;AAG1B,OAAO,EAAE,aAAa,EAAE,MAAM,uCAAuC,CAAC;AACtE,OAAO,EAAE,WAAW,EAAE,MAAM,qCAAqC,CAAC;AAClE,OAAO,EAAE,iBAAiB,EAAE,MAAM,gCAAgC,CAAC;AACnE,OAAO,EAAE,aAAa,EAAE,MAAM,0CAA0C,CAAC;AACzE,OAAO,EAAE,kBAAkB,IAAI,KAAK,EAAE,MAAM,iDAAiD,CAAC;AAC9F,OAAO,EAAE,MAAM,EAAE,MAAM,gCAAgC,CAAC;AACxD,OAAO,EAAE,qBAAqB,EAAE,MAAM,2DAA2D,CAAC;AAElG,OAAO,EAAE,QAAQ,EAAE,MAAM,6BAA6B,CAAC;AACvD,OAAO,EAAE,QAAQ,EAAE,MAAM,iCAAiC,CAAC;AAE3D,OAAO,EAAE,YAAY,EAAE,MAAM,mCAAmC,CAAC;AAEjE,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAEnD,OA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AAC,CACqB,CACzB,CAAC;IACJ,CAAC;IAgHO,8CAAsB,GAA9B;QACE,QAAQ,IAAI,CAAC,IAAI,EAAE,CAAC;YAClB,KAAK,OAAO;gBACV,OAAO,IAAI,CAAC,MAAM,CAAC,eAAe,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;YACjD,KAAK,QAAQ;gBACX,OAAO,IAAI,CAAC,MAAM,CAAC,gBAAgB,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;YAClD,KAAK,OAAO,CAAC;YACb;gBACE,OAAO,IAAI,CAAC,MAAM,CAAC,eAAe,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QACnD,CAAC;IACH,CAAC;IA9Ka,iCAAmB,GAAG,eAAe,AAAlB,CAAmB;IACtC,yBAAW,GAAG,eAAe,AAAlB,CAAmB;IAFjC,aAAa;QAJzB,qBAAqB;QACrB,QAAQ;QACR,MAAM,CAAC,eAAe,EAAE,yBAAyB,CAAC;QAClD,QAAQ;OACI,aAAa,CAyOzB;IAAD,oBAAC;CAAA,AAzOD,CAAmC,KAAK,CAAC,aAAa,GAyOrD;SAzOY,aAAa","sourcesContent":["import type { Emotion } from '@emotion/css/create-instance';\nimport type { AriaAttributes, JSX } from 'react';\nimport React from 'react';\n\nimport type { CommonProps, CommonWrapperRestProps } from '../../internal/CommonWrapper/index.js';\nimport { CommonWrapper } from '../../internal/CommonWrapper/index.js';\nimport { RenderLayer } from '../../internal/RenderLayer/index.js';\nimport { createPropsGetter } from '../../lib/createPropsGetter.js';\nimport { isKeyCapsLock } from '../../lib/events/keyboard/identifiers.js';\nimport { KeyboardEventCodes as Codes } from '../../lib/events/keyboard/KeyboardEventCodes.js';\nimport { locale } from '../../lib/locale/decorators.js';\nimport { withRenderEnvironment } from '../../lib/renderEnvironment/RenderEnvironmentDecorator.js';\nimport type { TGetRootNode, TSetRootNode } from '../../lib/rootNode/index.js';\nimport { rootNode } from '../../lib/rootNode/index.js';\nimport { withSize } from '../../lib/size/SizeDecorator.js';\nimport type { Theme } from '../../lib/theming/Theme.js';\nimport { ThemeContext } from '../../lib/theming/ThemeContext.js';\nimport type { SizeProp } from '../../lib/types/props.js';\nimport { isNonNullable } from '../../lib/utils.js';\nimport type { Nullable } from '../../typings/utility-types.js';\nimport { Input } from '../Input/index.js';\nimport type { InputProps } from '../Input/index.js';\nimport type { PasswordInputLocale } from './locale/index.js';\nimport { PasswordInputLocaleHelper } from './locale/index.js';\nimport { getStyles } from './PasswordInput.styles.js';\nimport { PasswordInputIcon } from './PasswordInputIcon.js';\n\nexport interface PasswordInputProps\n extends Pick<AriaAttributes, 'aria-label'>, CommonProps, Omit<InputProps, 'showClearIcon'> {\n /** Визуально показывает, что активен CapsLock. */\n detectCapsLock?: boolean;\n}\n\nexport interface PasswordInputState {\n visible: boolean;\n focused: boolean;\n capsLockEnabled?: boolean | null;\n}\n\nexport const PasswordInputDataTids = {\n root: 'PasswordInput',\n capsLockDetector: 'PasswordInputCapsLockDetector',\n eyeIcon: 'PasswordInputEyeIcon',\n} as const;\n\n/**\n * Однострочное поле для ввода пароля, в котором символы заменяются на точки.\n */\n@withRenderEnvironment\n@rootNode\n@locale('PasswordInput', PasswordInputLocaleHelper)\n@withSize\nexport class PasswordInput extends React.PureComponent<PasswordInputProps, PasswordInputState> {\n public static __KONTUR_REACT_UI__ = 'PasswordInput';\n public static displayName = 'PasswordInput';\n\n public state: PasswordInputState = {\n visible: false,\n focused: false,\n capsLockEnabled: false,\n };\n private size!: SizeProp;\n\n private emotion!: Emotion;\n private cx!: Emotion['cx'];\n private styles!: ReturnType<typeof getStyles>;\n private theme!: Theme;\n\n private input: Nullable<Input>;\n private pendingInputBlur: React.FocusEvent<HTMLInputElement> | null = null;\n public getRootNode!: TGetRootNode;\n private setRootNode!: TSetRootNode;\n private readonly locale!: PasswordInputLocale;\n\n private getProps = createPropsGetter({});\n\n public componentDidMount() {\n if (this.props.detectCapsLock) {\n this.setState({ capsLockEnabled: null });\n }\n }\n\n public static getDerivedStateFromProps(props: PasswordInputProps, state: PasswordInputState) {\n if (props.disabled) {\n return { visible: false };\n }\n\n return state;\n }\n\n public render(): JSX.Element {\n this.styles = getStyles(this.emotion);\n\n return (\n <ThemeContext.Consumer>\n {(theme) => {\n this.theme = theme;\n return (\n <CommonWrapper rootNodeRef={this.setRootNode} {...this.getProps()}>\n {this.renderMain}\n </CommonWrapper>\n );\n }}\n </ThemeContext.Consumer>\n );\n }\n\n /** Программно устанавливает фокус на поле.\n * Появляется фокусная рамка, элемент получает клавиатурные события и воспринимается как текущий элемент для чтения скринридерами.\n * @public\n */\n public focus = (): void => {\n if (this.input) {\n this.input.focus();\n }\n };\n\n /** Программно снимает фокус с кнопки.\n * @public\n */\n public blur = (): void => {\n if (this.input) {\n this.input.blur();\n }\n };\n\n private handleKeyPress = (e: React.KeyboardEvent<HTMLInputElement>) => {\n const { onKeyPress, detectCapsLock } = this.props;\n\n if (onKeyPress) {\n onKeyPress(e);\n }\n\n if (!detectCapsLock) {\n return;\n }\n\n const capsLockEnabled = e.getModifierState(Codes.CapsLock);\n\n this.setState({ capsLockEnabled });\n };\n\n private handleKeydown = (e: React.KeyboardEvent<HTMLInputElement>) => {\n const {\n props: { detectCapsLock, onKeyDown },\n state: { capsLockEnabled },\n } = this;\n\n if (onKeyDown) {\n onKeyDown(e);\n }\n\n if (!detectCapsLock) {\n return;\n }\n\n if (isKeyCapsLock(e) && isNonNullable(capsLockEnabled)) {\n this.setState({ capsLockEnabled: !capsLockEnabled });\n }\n };\n\n private handleToggleVisibility = () => {\n this.setState((prevState) => ({ visible: !prevState.visible }), this.focusOnInput);\n };\n\n private focusOnInput = () => {\n if (this.input) {\n this.input.focus();\n }\n };\n\n private handleFocus = (event: React.FocusEvent<HTMLInputElement>) => {\n this.pendingInputBlur = null;\n if (this.state.focused) {\n return;\n }\n\n this.setState({ focused: true });\n\n if (this.props.onFocus) {\n this.props.onFocus(event);\n }\n };\n\n private handleFocusOutside = () => {\n this.hideSymbols();\n\n if (this.state.focused) {\n this.setState({ focused: false });\n }\n };\n\n private handleInputBlur = (event: React.FocusEvent<HTMLInputElement>) => {\n event.persist();\n this.pendingInputBlur = event;\n };\n\n private handleBlur = (event: React.FocusEvent<HTMLDivElement>) => {\n if (event.currentTarget.contains(event.relatedTarget)) {\n return;\n }\n\n const inputBlur = this.pendingInputBlur;\n this.pendingInputBlur = null;\n const input = this.input?.getNode();\n if (input) {\n // Preserve the input event contract even when focus leaves via the visibility button.\n this.props.onBlur?.(\n Object.assign(Object.create(inputBlur ?? event) as React.FocusEvent<HTMLInputElement>, {\n currentTarget: input,\n target: input,\n relatedTarget: event.relatedTarget,\n }),\n );\n }\n };\n\n private getEyeWrapperClassname() {\n switch (this.size) {\n case 'large':\n return this.styles.eyeWrapperLarge(this.theme);\n case 'medium':\n return this.styles.eyeWrapperMedium(this.theme);\n case 'small':\n default:\n return this.styles.eyeWrapperSmall(this.theme);\n }\n }\n\n private renderEye = () => {\n const { capsLockEnabled } = this.state;\n\n return (\n <span className={this.styles.iconWrapper()}>\n {capsLockEnabled && (\n <span className={this.styles.capsLockDetector()} data-tid={PasswordInputDataTids.capsLockDetector} />\n )}\n <span className={this.cx(this.styles.toggleVisibility(this.theme), this.getEyeWrapperClassname())}>\n {!this.props.disabled && (\n <button\n type=\"button\"\n aria-label={this.state.visible ? this.locale.eyeClosedAriaLabel : this.locale.eyeOpenedAriaLabel}\n onClick={this.handleToggleVisibility}\n className={this.styles.icon()}\n data-tid={PasswordInputDataTids.eyeIcon}\n >\n <PasswordInputIcon size={this.size} visible={this.state.visible} />\n </button>\n )}\n </span>\n </span>\n );\n };\n\n private refInput = (element: Input) => {\n this.input = element;\n };\n\n private hideSymbols = () => {\n this.setState({ visible: false });\n };\n\n private renderMain = (props: CommonWrapperRestProps<PasswordInputProps>) => {\n const { detectCapsLock, onBlur, ...rest } = props;\n return (\n <RenderLayer\n active={this.state.focused}\n onFocusOutside={this.handleFocusOutside}\n onClickOutside={this.handleFocusOutside}\n >\n <div data-tid={PasswordInputDataTids.root} className={this.styles.root()} onBlur={this.handleBlur}>\n <Input\n ref={this.refInput}\n type={this.state.visible ? 'text' : 'password'}\n {...rest}\n onKeyDown={this.handleKeydown}\n onKeyPress={this.handleKeyPress}\n rightIcon={this.renderEye()}\n onFocus={this.handleFocus}\n onBlurCapture={this.handleInputBlur}\n />\n </div>\n </RenderLayer>\n );\n };\n}\n"]}
|