Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -320,3 +320,12 @@ export const ShouldSetFocusOnPlaceholderClick: Story = () => {
return <DateInput />;
};
ShouldSetFocusOnPlaceholderClick.storyName = 'should set focus on placeholder click';

export const TEST: Story = () => {
return (
<React.StrictMode>
<DateInput value="27.04.1992" />
</React.StrictMode>
);
};
TEST.parameters = { creevey: { skip: true } };
5 changes: 3 additions & 2 deletions packages/react-ui/internal/InputLikeText/InputLikeText.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import debounce from 'lodash.debounce';
import { globalObject, SafeTimer } from '@skbkontur/global-object';

import { isNonNullable } from '../../lib/utils';
import { mergeRefs } from '../../lib/mergeRefs';
import { isKeyTab, isShortcutPaste } from '../../lib/events/keyboard/identifiers';
import { MouseDrag, MouseDragEventHandler } from '../../lib/events/MouseDrag';
import { isEdge, isIE11, isMobile } from '../../lib/client';
Expand Down Expand Up @@ -170,7 +171,7 @@ export class InputLikeText extends React.Component<InputLikeTextProps, InputLike
{(theme) => {
this.theme = theme;
return (
<CommonWrapper rootNodeRef={this.setRootNode} {...this.getProps()}>
<CommonWrapper {...this.getProps()}>
{this.renderMain}
</CommonWrapper>
);
Expand Down Expand Up @@ -257,7 +258,7 @@ export class InputLikeText extends React.Component<InputLikeTextProps, InputLike
onMouseEnter={this.handleHover}
onMouseLeave={this.handleUnhover}
onBlur={this.handleBlur}
ref={this.innerRef}
ref={mergeRefs(this.setRootNode, this.innerRef)}
onKeyDown={this.handleKeyDown}
onMouseDown={this.handleMouseDown}
role="textbox"
Expand Down
5 changes: 2 additions & 3 deletions packages/react-ui/lib/mergeRefs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,10 @@ import { Nullable } from '../typings/utility-types';
import { isNonNullable, isNullable } from './utils';

type RefVariants<T> = Nullable<React.RefObject<T> | React.RefCallback<T>>;
type RefCallback<T> = ReturnType<typeof createRefCallback<T>>;
const CALLBACK_AS_KEY = { callbackAsKey: true };

type CacheKey<T> = NonNullable<RefVariants<T> | typeof CALLBACK_AS_KEY>;
type CacheValue<T> = RefCallback<T> | WeakMap<CacheKey<T>, CacheValue<T>>;
type CacheValue<T> = React.RefCallback<T> | WeakMap<CacheKey<T>, CacheValue<T>>;

const cache = new WeakMap<CacheKey<any>, CacheValue<any>>();

Expand All @@ -29,7 +28,7 @@ const cache = new WeakMap<CacheKey<any>, CacheValue<any>>();
* return <div ref={mergeRefs(localRef, ref)} />;
* });
*/
export function mergeRefs<T>(...refs: Array<RefVariants<T>>): RefCallback<T> {
export function mergeRefs<T>(...refs: Array<RefVariants<T>>): React.RefCallback<T> {
const cacheLevel = getLeafRefInCache(...refs);

const cachedCallback = cacheLevel.get(CALLBACK_AS_KEY);
Expand Down