Skip to content

Commit 04e7ecc

Browse files
authored
Merge pull request #263 from gdi-be/29039-delete-date-fix
Fix date deletion and improve keyword display
2 parents 3b1e06a + 0a24e30 commit 04e7ecc

3 files changed

Lines changed: 41 additions & 11 deletions

File tree

src/lib/components/Form/Field/10_PublishedField.svelte

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,13 @@
1212
const { getValue } = getFormContext();
1313
const valueFromData = $derived(getValue<string>(KEY));
1414
let value = $state('');
15+
let initialized = false;
1516
17+
// TODO: this should be replaced by deriving "value". This
18+
// should be possible after svelte is updated to the latest version
19+
// https://github.com/gdi-be/mde-client/pull/261
1620
$effect(() => {
17-
if (valueFromData && !value) {
21+
if (valueFromData && !initialized) {
1822
value = new Date(valueFromData).toISOString().split('T')[0];
1923
}
2024
});

src/lib/components/Form/Inputs/DateInput.svelte

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@
22
import type { HTMLInputAttributes } from 'svelte/elements';
33
import { type FullFieldConfig, type ValidationResult } from '$lib/components/Form/FieldsConfig';
44
import FieldHint from '../FieldHint.svelte';
5-
import { getAccessToken } from '../../../context/TokenContext.svelte';
6-
import { getHighestRole } from '../../../util';
5+
import { getAccessToken } from '$lib/context/TokenContext.svelte';
6+
import { getHighestRole } from '$lib/util';
7+
import { onMount } from 'svelte';
78
89
type InputProps = {
910
value?: string;
@@ -26,9 +27,27 @@
2627
...restProps
2728
}: InputProps = $props();
2829
30+
let inputElement: HTMLInputElement;
31+
let isActive = $state(false);
32+
2933
const token = $derived(getAccessToken());
3034
const highestRole = $derived(getHighestRole(token));
3135
36+
// This special handling is needed as the input[type="date"] is not automatically
37+
// focused when the datepicker is opened.
38+
onMount(() => {
39+
const handleFocus = () => (isActive = true);
40+
const handleBlur = () => (isActive = false);
41+
42+
inputElement.addEventListener('focus', handleFocus);
43+
inputElement.addEventListener('blur', handleBlur);
44+
45+
return () => {
46+
inputElement.removeEventListener('focus', handleFocus);
47+
inputElement.removeEventListener('blur', handleBlur);
48+
};
49+
});
50+
3251
let invalid = $derived.by(() => {
3352
if (!fieldConfig) return false;
3453
const { editingRoles } = fieldConfig;
@@ -42,6 +61,8 @@
4261
<fieldset class={['date-input', wrapperClass, invalid && 'invalid']}>
4362
<legend>{label}</legend>
4463
<input
64+
class={[isActive && 'active']}
65+
bind:this={inputElement}
4566
type="date"
4667
id={key}
4768
name={key}
@@ -78,6 +99,13 @@
7899
margin-top: 0.5em;
79100
outline-width: 0;
80101
align-self: flex-start;
102+
103+
&.active,
104+
&:focus,
105+
&:focus-visible {
106+
border-color: var(--mdc-theme-primary);
107+
outline: 1px solid var(--mdc-theme-primary);
108+
}
81109
}
82110
83111
.field-footer {

src/lib/components/ReadOnly/DisplayFieldSnippets.svelte

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -182,15 +182,13 @@
182182
{/snippet}
183183

184184
{#snippet isoMetadataKeywords(value: Keywords)}
185-
{#if !value?.default?.length}
186-
{DEFAULT_NULL_STRING}
187-
{:else}
185+
{#await getAutoKeywords()}
186+
{t('general.loading')}
187+
{:then autoKeywords}
188+
{autoKeywords.join(', ')}
189+
{/await}
190+
{#if value?.default?.length}
188191
{value?.default?.map(({ keyword }) => keyword)?.join(', ') + ','}
189-
{#await getAutoKeywords()}
190-
{t('general.loading')}
191-
{:then autoKeywords}
192-
{autoKeywords.join(', ')}
193-
{/await}
194192
{/if}
195193
{/snippet}
196194

0 commit comments

Comments
 (0)