Skip to content

Commit

Permalink
Handle enter key in Rename modal
Browse files Browse the repository at this point in the history
Not handling the enter key reloads the page and doesn't rename the
potentially changed input.

Closes: #622
  • Loading branch information
jelly authored and martinpitt committed Jul 12, 2024
1 parent 3199cb9 commit f4e0475
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/dialogs/rename.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,17 @@ const RenameItemModal = ({ dialogResult, path, selected } : {
text={errorMessage}
isInline
/>}
<Form isHorizontal>
<Form
isHorizontal onSubmit={e => {
e.preventDefault();
if (name !== selected.name)
renameItem();
else {
setNameError(checkName(name, cwdInfo?.entries || {}, selected));
}
return false;
}}
>
<FormGroup fieldId="rename-item-input" label={label}>
<TextInput
autoFocus // eslint-disable-line jsx-a11y/no-autofocus
Expand Down
10 changes: 10 additions & 0 deletions test/check-application
Original file line number Diff line number Diff line change
Expand Up @@ -930,6 +930,16 @@ class TestFiles(testlib.MachineCase):
b.set_input_text("#rename-item-input", "foo.txt")
b.wait_in_text("#rename-item-input-helper", "Filename is the same as original name")
b.click("div.pf-v5-c-modal-box__close > button")
b.wait_not_present(".pf-v5-c-modal-box")

# Enter allows renaming.
self.file_action_modal('foo.txt', 'Rename')
b.key('Enter')
b.wait_in_text("#rename-item-input-helper", "Filename is the same as original name")
b.set_input_text("#rename-item-input", "renamed-foo.txt", blur=False)
b.key('Enter')
b.wait_not_present(".pf-v5-c-modal-box")
b.wait_visible("[data-item='renamed-foo.txt']")

def testHiddenItems(self) -> None:
b = self.browser
Expand Down

0 comments on commit f4e0475

Please sign in to comment.