diff --git a/services/web/frontend/js/features/editor-navigation-toolbar/components/project-name-editable-label.js b/services/web/frontend/js/features/editor-navigation-toolbar/components/project-name-editable-label.js
index 54b457830b..a06a83279d 100644
--- a/services/web/frontend/js/features/editor-navigation-toolbar/components/project-name-editable-label.js
+++ b/services/web/frontend/js/features/editor-navigation-toolbar/components/project-name-editable-label.js
@@ -34,11 +34,15 @@ function ProjectNameEditableLabel({
}
}
+ function finishRenaming() {
+ setIsRenaming(false)
+ onChange(inputContent)
+ }
+
function handleKeyDown(event) {
if (event.key === 'Enter') {
event.preventDefault()
- setIsRenaming(false)
- onChange(event.target.value)
+ finishRenaming()
}
}
@@ -47,7 +51,9 @@ function ProjectNameEditableLabel({
}
function handleBlur() {
- setIsRenaming(false)
+ if (isRenaming) {
+ finishRenaming()
+ }
}
return (
diff --git a/services/web/test/frontend/features/editor-navigation-toolbar/components/project-name-editable-label.test.js b/services/web/test/frontend/features/editor-navigation-toolbar/components/project-name-editable-label.test.js
index d172ac56e9..cb7de63733 100644
--- a/services/web/test/frontend/features/editor-navigation-toolbar/components/project-name-editable-label.test.js
+++ b/services/web/test/frontend/features/editor-navigation-toolbar/components/project-name-editable-label.test.js
@@ -43,11 +43,21 @@ describe('', function () {
expect(props.onChange).to.be.calledWith('new project name')
})
- it('cancels renaming when the input loses focus', function () {
- render()
+ it('calls "onChange" when the input loses focus', function () {
+ const props = {
+ ...editableProps,
+ onChange: sinon.stub(),
+ }
+ render()
+
fireEvent.doubleClick(screen.getByText('test-project'))
+ const input = screen.getByRole('textbox')
+
+ fireEvent.change(input, { target: { value: 'new project name' } })
+
fireEvent.blur(screen.getByRole('textbox'))
- expect(screen.queryByRole('textbox')).to.not.exist
+
+ expect(props.onChange).to.be.calledWith('new project name')
})
})