Merge pull request #4673 from overleaf/msm-rename-project-onblur

Rename project on blur instead of canceling renaming

GitOrigin-RevId: fe58b48d5ab37357df33e970338e8b96c3ec1986
This commit is contained in:
June Kelly 2021-08-11 09:50:01 +01:00 committed by Copybot
parent 428ef96c56
commit 1fb1c08348
2 changed files with 22 additions and 6 deletions

View file

@ -34,11 +34,15 @@ function ProjectNameEditableLabel({
} }
} }
function finishRenaming() {
setIsRenaming(false)
onChange(inputContent)
}
function handleKeyDown(event) { function handleKeyDown(event) {
if (event.key === 'Enter') { if (event.key === 'Enter') {
event.preventDefault() event.preventDefault()
setIsRenaming(false) finishRenaming()
onChange(event.target.value)
} }
} }
@ -47,7 +51,9 @@ function ProjectNameEditableLabel({
} }
function handleBlur() { function handleBlur() {
setIsRenaming(false) if (isRenaming) {
finishRenaming()
}
} }
return ( return (

View file

@ -43,11 +43,21 @@ describe('<ProjectNameEditableLabel />', function () {
expect(props.onChange).to.be.calledWith('new project name') expect(props.onChange).to.be.calledWith('new project name')
}) })
it('cancels renaming when the input loses focus', function () { it('calls "onChange" when the input loses focus', function () {
render(<ProjectNameEditableLabel {...editableProps} />) const props = {
...editableProps,
onChange: sinon.stub(),
}
render(<ProjectNameEditableLabel {...props} />)
fireEvent.doubleClick(screen.getByText('test-project')) fireEvent.doubleClick(screen.getByText('test-project'))
const input = screen.getByRole('textbox')
fireEvent.change(input, { target: { value: 'new project name' } })
fireEvent.blur(screen.getByRole('textbox')) fireEvent.blur(screen.getByRole('textbox'))
expect(screen.queryByRole('textbox')).to.not.exist
expect(props.onChange).to.be.calledWith('new project name')
}) })
}) })