Skip to content
Merged
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
14 changes: 10 additions & 4 deletions client/modules/IDE/components/CollectionList/CollectionListRow.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -129,9 +129,6 @@ const CollectionListRowBase = (props) => {
closeAll();
setRenameOpen(true);
setRenameValue(props.collection.name);
if (renameInput.current) {
renameInput.current.focus();
}
};

const handleRenameChange = (e) => {
Expand All @@ -146,6 +143,12 @@ const CollectionListRowBase = (props) => {
}
};

const handleRenameFocus = () => {
if (renameInput.current) {
renameInput.current.focus();
}
};

const handleRenameBlur = () => {
updateName();
closeAll();
Expand Down Expand Up @@ -191,7 +194,10 @@ const CollectionListRowBase = (props) => {
onKeyDown={handleRenameEnter}
onBlur={handleRenameBlur}
onClick={(e) => e.stopPropagation()}
ref={renameInput}
ref={(node) => {
renameInput.current = node;
handleRenameFocus();
}}
Comment on lines +197 to +200
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does the ref function get executed every time that the element is mounted? Like if you open it and close it and open it again, will it get focused the second time? I think so but I'm not certain off the top of my head.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will it get focused the second time?

Yes, it will. The way it works is when the component gets mounted the ref callback is called with the input field as an parameter. And when the component gets unmounted the callback is called again with null as an parameter.

/>
)}
</>
Expand Down