Skip to content

Commit

Permalink
fix reactivity
Browse files Browse the repository at this point in the history
  • Loading branch information
luca-peruzzo committed Nov 24, 2024
1 parent bd9c819 commit 800c795
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 13 deletions.
4 changes: 2 additions & 2 deletions dist/login/components/FieldErrors.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
type FieldErrorProps = {
attribute: Attribute;
displayableErrors: FormFieldError[];
fieldIndex: number | undefined;
fieldIndex?: number;
kcClsx: KcClsx;
};
const { attribute, fieldIndex, kcClsx, displayableErrors: _displayableErrors }: FieldErrorProps = $props();
const displayableErrors = _displayableErrors.filter((error) => error.fieldIndex === fieldIndex);
const displayableErrors = _displayableErrors.filter((error) => !fieldIndex || error.fieldIndex === fieldIndex);
</script>

{#if displayableErrors.length !== 0}
Expand Down
2 changes: 1 addition & 1 deletion dist/login/components/FieldErrors.svelte.d.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
type FieldErrorProps = {
attribute: Attribute;
displayableErrors: FormFieldError[];
fieldIndex: number | undefined;
fieldIndex?: number;
kcClsx: KcClsx;
};
import type { FormFieldError } from '../lib/useUserProfileForm';
Expand Down
4 changes: 2 additions & 2 deletions dist/login/components/UserProfileFormFields.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@
{@render advancedMsg(attribute.displayName ?? '')()}
</label>
{#if attribute.required}
*{/if}
*
{/if}
</div>
<div class={kcClsx('kcInputWrapperClass')}>
{#if attribute.annotations.inputHelperTextBefore !== undefined}
Expand All @@ -83,7 +84,6 @@
{attribute}
{displayableErrors}
{kcClsx}
fieldIndex={undefined}
/>
{#if attribute.annotations.inputHelperTextAfter !== undefined}
<div
Expand Down
4 changes: 2 additions & 2 deletions src/lib/login/components/FieldErrors.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
type FieldErrorProps = {
attribute: Attribute;
displayableErrors: FormFieldError[];
fieldIndex: number | undefined;
fieldIndex?: number;
kcClsx: KcClsx;
};
const { attribute, fieldIndex, kcClsx, displayableErrors: _displayableErrors }: FieldErrorProps = $props();
const displayableErrors = _displayableErrors.filter((error) => error.fieldIndex === fieldIndex);
const displayableErrors = _displayableErrors.filter((error) => !fieldIndex || error.fieldIndex === fieldIndex);
</script>

{#if displayableErrors.length !== 0}
Expand Down
10 changes: 6 additions & 4 deletions src/lib/login/components/PasswordWrapper.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import { useReducer } from '@keycloakify/svelte/tools/useReducer';
import type { KcClsx } from 'keycloakify/login/lib/kcClsx';
import { assert } from 'keycloakify/tools/assert';
import type { Snippet } from 'svelte';
import { onMount, type Snippet } from 'svelte';
import type { I18n } from '../i18n';
const props: { kcClsx: KcClsx; i18n: I18n; passwordInputId: string; children: Snippet } = $props();
Expand All @@ -14,12 +14,14 @@
(isPasswordRevealed: boolean) => !isPasswordRevealed,
false,
);
$effect(() => {
onMount(() => {
const passwordInputElement: HTMLInputElement = document.getElementById(passwordInputId) as HTMLInputElement;
assert(passwordInputElement instanceof HTMLInputElement);
passwordInputElement.type = isPasswordRevealed ? 'text' : 'password';
const unsubscribe = isPasswordRevealed.subscribe(($isPasswordRevealed) => {
passwordInputElement.type = $isPasswordRevealed ? 'text' : 'password';
});
return () => unsubscribe();
});
</script>

Expand Down
4 changes: 2 additions & 2 deletions src/lib/login/components/UserProfileFormFields.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@
{@render advancedMsg(attribute.displayName ?? '')()}
</label>
{#if attribute.required}
*{/if}
*
{/if}
</div>
<div class={kcClsx('kcInputWrapperClass')}>
{#if attribute.annotations.inputHelperTextBefore !== undefined}
Expand All @@ -83,7 +84,6 @@
{attribute}
{displayableErrors}
{kcClsx}
fieldIndex={undefined}
/>
{#if attribute.annotations.inputHelperTextAfter !== undefined}
<div
Expand Down

0 comments on commit 800c795

Please sign in to comment.