mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-14 20:40:17 -05:00
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:
parent
428ef96c56
commit
1fb1c08348
2 changed files with 22 additions and 6 deletions
|
@ -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 (
|
||||
|
|
|
@ -43,11 +43,21 @@ describe('<ProjectNameEditableLabel />', function () {
|
|||
expect(props.onChange).to.be.calledWith('new project name')
|
||||
})
|
||||
|
||||
it('cancels renaming when the input loses focus', function () {
|
||||
render(<ProjectNameEditableLabel {...editableProps} />)
|
||||
it('calls "onChange" when the input loses focus', function () {
|
||||
const props = {
|
||||
...editableProps,
|
||||
onChange: sinon.stub(),
|
||||
}
|
||||
render(<ProjectNameEditableLabel {...props} />)
|
||||
|
||||
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')
|
||||
})
|
||||
})
|
||||
|
||||
|
|
Loading…
Reference in a new issue