Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(web): Prevent DELETE key from clearing DateInput in modal #8846

Merged
merged 6 commits into from
Apr 29, 2024
Merged
Show file tree
Hide file tree
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
66 changes: 29 additions & 37 deletions web/src/lib/components/shared-components/change-date.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -53,43 +53,35 @@
dispatch('confirm', value);
}
};

const handleKeydown = (event: KeyboardEvent) => {
if (['ArrowUp', 'ArrowDown', 'ArrowLeft', 'ArrowRight'].includes(event.key)) {
event.stopPropagation();
}
};
</script>

<div role="presentation" on:keydown={handleKeydown}>
<ConfirmDialogue
id="edit-date-time-modal"
confirmColor="primary"
title="Edit date and time"
prompt="Please select a new date:"
disabled={!date.isValid}
onConfirm={handleConfirm}
onClose={handleCancel}
>
<div class="flex flex-col text-md px-4 text-center gap-2" slot="prompt">
<div class="flex flex-col">
<label for="datetime">Date and Time</label>
<DateInput
class="immich-form-input text-sm my-4 w-full"
id="datetime"
type="datetime-local"
bind:value={selectedDate}
/>
</div>
<div class="flex flex-col w-full mt-2">
<Combobox
bind:selectedOption
id="settings-timezone"
label="Timezone"
options={timezones}
placeholder="Search timezone..."
/>
</div>
<ConfirmDialogue
id="edit-date-time-modal"
confirmColor="primary"
title="Edit date and time"
prompt="Please select a new date:"
disabled={!date.isValid}
onConfirm={handleConfirm}
onClose={handleCancel}
>
<div class="flex flex-col text-md px-4 text-center gap-2" slot="prompt">
<div class="flex flex-col">
<label for="datetime">Date and Time</label>
<DateInput
class="immich-form-input text-sm my-4 w-full"
id="datetime"
type="datetime-local"
bind:value={selectedDate}
/>
</div>
<div class="flex flex-col w-full mt-2">
<Combobox
bind:selectedOption
id="settings-timezone"
label="Timezone"
options={timezones}
placeholder="Search timezone..."
/>
</div>
</ConfirmDialogue>
</div>
</div>
</ConfirmDialogue>
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@

<FocusTrap>
Copy link
Member

@ben-basten ben-basten Apr 22, 2024

Choose a reason for hiding this comment

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

Looks like the FocusTrap will have to be moved, to make sure that it's still receiving the keyboard events needed to manage focus within the modal. Making it a direct child of the section could be a fix for this!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@ben-basten Thank you, and I'll give it a try!

Copy link
Contributor

Choose a reason for hiding this comment

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

I just changed this to just ignore events that originate from an input type that includes date and that seemed to fix the issue without needing to make any other changes.

<section
role="presentation"
in:fade={{ duration: 100 }}
out:fade={{ duration: 100 }}
class="fixed left-0 top-0 z-[9990] flex h-screen w-screen place-content-center place-items-center bg-black/40"
Expand Down
2 changes: 1 addition & 1 deletion web/src/lib/utils/shortcut.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export const shouldIgnoreShortcut = (event: KeyboardEvent): boolean => {
return false;
}
const type = (event.target as HTMLInputElement).type;
return ['textarea', 'text'].includes(type);
return ['textarea', 'text', 'date', 'datetime-local'].includes(type);
};

export const matchesShortcut = (event: KeyboardEvent, shortcut: Shortcut) => {
Expand Down
Loading