Skip to content

Commit

Permalink
fix(Navigation): fix create directory modal's error "maximum call sta…
Browse files Browse the repository at this point in the history
…ck size exceeded" [YTFRONT-4245]
  • Loading branch information
pabolkovdn committed Nov 1, 2024
1 parent 22879ac commit a549db4
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
14 changes: 12 additions & 2 deletions packages/ui/src/ui/containers/PathEditor/PathEditor.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,9 @@ export class PathEditor extends Component {
autoFocus: PropTypes.bool,
hasClear: PropTypes.bool,
showErrors: PropTypes.bool,
inputRef: PropTypes.shape({
current: PropTypes.instanceOf(HTMLInputElement),
}),
};

static defaultProps = {
Expand All @@ -78,7 +81,7 @@ export class PathEditor extends Component {
super(props);

this.suggestionsList = React.createRef();
this.input = React.createRef();
this.input = this.props.inputRef ?? React.createRef();

this.debounceLoading = debounce_(this.debounceLoading, debounceTime);
this.prevScope = null;
Expand Down Expand Up @@ -183,9 +186,16 @@ export class PathEditor extends Component {
const {onFocus} = this.props;
const {path} = this.state;

// Action {onFocus} from TextInput with {autoFocus=true} property invoke before controllRef will set,
// for this reason DOM Input element is assings hrere into ref, those <inputRef> (from own props)
// will accessing in parrent component
if (!this.input.current) {
this.input.current = e.target;
}

key.setScope('path-editor');
this.setState({inputFocus: true});
onFocus?.(e, {path});
this.callCallback(onFocus, path);
};

handleInputBlur = () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,8 @@ function NavigationPathEditor({hideEditor}: {hideEditor: () => void}) {
const dispatch = useDispatch();
const actualPath = useSelector(getActualPath);

const inputRef = React.createRef<HTMLInputElement | null>();

const handleApply = React.useCallback(
(path: string) => {
if (path !== actualPath) {
Expand All @@ -143,15 +145,20 @@ function NavigationPathEditor({hideEditor}: {hideEditor: () => void}) {
[hideEditor],
);

const handleFocus = React.useCallback(() => {
inputRef.current?.select();
}, [inputRef]);

return (
<PathEditor
inputRef={inputRef}
className={block('path-editor')}
autoFocus
defaultPath={actualPath}
onApply={handleApply}
onCancel={hideEditor}
onBlur={hideEditor}
onFocus={(e) => e.target.select()}
onFocus={handleFocus}
/>
);
}
Expand Down

0 comments on commit a549db4

Please sign in to comment.