Files
immich/web/src/lib/components/shared-components/change-date.svelte
Ben Basten c6d2408517 feat(web): combobox accessibility improvements (#8007)
* bump skip link z index, to prevent overlap with the search box

* combobox refactor initial commit

* pull label into the combobox component

* feat(web): combobox accessibility improvements

* fix: replace crypto.randomUUID, fix border UI bug, simpler focus handling (#2)

* fix: handle changes in the selected option

* fix: better escape key handling in search bar

* fix: remove broken tailwind classes

Co-authored-by: Michel Heusschen <59014050+michelheusschen@users.noreply.github.com>

* fix: remove custom "outclick" handler logic

* fix: use focusout instead of custom key handlers to detect focus change

* fix: move escape key handling to the window

Also add escape key handling to the input box, to make sure that the "recent searches" dropdown gets closed too.

* fix: better input event handling

Co-authored-by: Michel Heusschen <59014050+michelheusschen@users.noreply.github.com>

* fix: highlighting selected dropdown element

---------

Co-authored-by: Michel Heusschen <59014050+michelheusschen@users.noreply.github.com>
2024-03-19 07:56:41 -05:00

97 lines
2.5 KiB
Svelte

<script lang="ts">
import { createEventDispatcher } from 'svelte';
import { DateTime } from 'luxon';
import ConfirmDialogue from './confirm-dialogue.svelte';
import Combobox from './combobox.svelte';
import DateInput from '../elements/date-input.svelte';
export let initialDate: DateTime = DateTime.now();
type ZoneOption = {
/**
* Timezone name
*
* e.g. Europe/Berlin
*/
label: string;
/**
* Timezone offset
*
* e.g. UTC+01:00
*/
value: string;
};
const timezones: ZoneOption[] = Intl.supportedValuesOf('timeZone').map((zone: string) => ({
label: zone + ` (${DateTime.local({ zone }).toFormat('ZZ')})`,
value: 'UTC' + DateTime.local({ zone }).toFormat('ZZ'),
}));
const initialOption = timezones.find((item) => item.value === 'UTC' + initialDate.toFormat('ZZ'));
let selectedOption = initialOption && {
label: initialOption?.label || '',
value: initialOption?.value || '',
};
let selectedDate = initialDate.toFormat("yyyy-MM-dd'T'HH:mm");
// Keep local time if not it's really confusing
$: date = DateTime.fromISO(selectedDate).setZone(selectedOption?.value, { keepLocalTime: true });
const dispatch = createEventDispatcher<{
cancel: void;
confirm: string;
}>();
const handleCancel = () => dispatch('cancel');
const handleConfirm = () => {
const value = date.toISO();
if (value) {
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
confirmColor="primary"
cancelColor="secondary"
title="Edit date & 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="mt-2" />
<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>
</div>
</ConfirmDialogue>
</div>