-
Notifications
You must be signed in to change notification settings - Fork 158
Default Account Flow - Continue #3384
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
base: main
Are you sure you want to change the base?
Changes from all commits
16d581b
26fd1d2
926851c
4803b34
c3b534a
fd103f9
83f92eb
c17a306
511abac
ab6218c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,35 @@ | ||||||
<script lang="ts"> | ||||||
type ToggleProps = { | ||||||
toggled: boolean; | ||||||
onClick: (value: boolean) => void; | ||||||
label?: string; | ||||||
disabled?: boolean; | ||||||
}; | ||||||
let { toggled, onClick, label, disabled = false }: ToggleProps = $props(); | ||||||
</script> | ||||||
|
||||||
<label class="flex flex-row items-center gap-2"> | ||||||
<button | ||||||
type="button" | ||||||
aria-labelledby={label ? "toggle" : undefined} | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The aria-labelledby references 'toggle' but the actual id is 'toggle-label' (line 22). This will break accessibility as the label association won't work correctly. Copilot uses AI. Check for mistakes. Positive FeedbackNegative Feedback |
||||||
class={`bg-bg-tertiary relative flex h-5 w-9 flex-row items-center rounded-full p-0.5 ${toggled ? "justify-end" : "justify-start"}`} | ||||||
onclick={() => onClick(!toggled)} | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In Svelte, the native DOM on:click={() => onClick(!toggled)} This change applies to both button elements in this component that currently use
Suggested change
Spotted by Diamond |
||||||
> | ||||||
<div class="size-4 rounded-full bg-white"></div> | ||||||
</button> | ||||||
{#if label} | ||||||
<span id="toggle-label" class="text-text-secondary text-sm font-medium" | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why is the id needed? |
||||||
>{label}</span | ||||||
> | ||||||
{/if} | ||||||
<input | ||||||
type="checkbox" | ||||||
role="switch" | ||||||
aria-labelledby={label ? "toggle" : undefined} | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The aria-labelledby references 'toggle' but the actual id is 'toggle-label' (line 22). This will break accessibility as the label association won't work correctly. Copilot uses AI. Check for mistakes. Positive FeedbackNegative Feedback |
||||||
checked={toggled} | ||||||
{disabled} | ||||||
onchange={() => onClick(!toggled)} | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The hidden checkbox's onchange handler calls onClick(!toggled), but the button's onclick already does the same. This could cause the toggle to be called twice when using keyboard navigation, resulting in no state change.
Suggested change
Copilot uses AI. Check for mistakes. Positive FeedbackNegative Feedback |
||||||
hidden | ||||||
/> | ||||||
</label> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
<script lang="ts"> | ||
import { onMount } from "svelte"; | ||
import FeaturedIcon from "$lib/components/ui/FeaturedIcon.svelte"; | ||
import { UserPlusIcon } from "@lucide/svelte"; | ||
import Button from "$lib/components/ui/Button.svelte"; | ||
import Input from "$lib/components/ui/Input.svelte"; | ||
import ProgressRing from "$lib/components/ui/ProgressRing.svelte"; | ||
import { AUTH_FLOW_UPDATES } from "$lib/state/featureFlags"; | ||
import Checkbox from "../ui/Checkbox.svelte"; | ||
import { type AccountInfo } from "$lib/generated/internet_identity_types"; | ||
|
||
interface Props { | ||
handleEdit: ( | ||
account: AccountInfo, | ||
name: string, | ||
defaultAccount?: boolean, | ||
) => void; | ||
account: AccountInfo; | ||
defaultAccount: AccountInfo; | ||
} | ||
|
||
const { handleEdit, account, defaultAccount }: Props = $props(); | ||
|
||
let inputRef = $state<HTMLInputElement>(); | ||
let name = $state<string>(account.name[0] ?? ""); | ||
let loading = $state(false); | ||
let isDefault = $state<boolean>( | ||
defaultAccount.account_number[0] === account.account_number[0], | ||
); | ||
let defaultIsDisabled = | ||
defaultAccount.account_number[0] === account.account_number[0]; | ||
|
||
const handleSubmit = () => { | ||
loading = true; | ||
handleEdit(account, name, defaultIsDisabled ? undefined : isDefault); | ||
}; | ||
|
||
onMount(() => { | ||
inputRef?.focus(); | ||
}); | ||
</script> | ||
|
||
<form class="flex flex-1 flex-col"> | ||
<div class="mb-8 flex flex-col"> | ||
<FeaturedIcon size="lg" class="mb-4 self-start"> | ||
<UserPlusIcon size="1.5rem" /> | ||
</FeaturedIcon> | ||
<h1 class="text-text-primary mb-3 text-2xl font-medium"> | ||
{#if $AUTH_FLOW_UPDATES} | ||
Name account | ||
{:else} | ||
Name additional account | ||
{/if} | ||
</h1> | ||
<p class="text-md text-text-tertiary mb-6 font-medium"> | ||
{#if $AUTH_FLOW_UPDATES} | ||
You can edit this account later. Label it by use (e.g. 'Work' or | ||
'Demo'). | ||
{:else} | ||
You can rename this account later if needed. | ||
{/if} | ||
</p> | ||
<Input | ||
bind:element={inputRef} | ||
bind:value={name} | ||
inputmode="text" | ||
placeholder="Account name" | ||
hint={$AUTH_FLOW_UPDATES | ||
? "" | ||
: 'Label it by how you\'ll use it — e.g., "Work", "Personal".'} | ||
type="text" | ||
size="md" | ||
autocomplete="off" | ||
autocorrect="off" | ||
spellcheck="false" | ||
disabled={loading} | ||
error={name.length > 32 ? "Maximum length is 32 characters." : undefined} | ||
aria-label="Account name" | ||
/> | ||
{#if $AUTH_FLOW_UPDATES} | ||
<div class="mt-4.5 flex flex-col gap-6"> | ||
<div class="border-border-tertiary border-t"></div> | ||
<div class="flex flex-row items-center gap-4"> | ||
<label | ||
class={`${defaultIsDisabled ? "cursor-not-allowed" : "cursor-pointer"} flex items-center gap-2`} | ||
> | ||
<Checkbox | ||
checked={isDefault} | ||
disabled={defaultIsDisabled} | ||
onchange={(e) => (isDefault = e.currentTarget.checked)} | ||
/> | ||
<span class="text-text-secondary text-sm font-medium"> | ||
Set as default sign-in | ||
</span> | ||
</label> | ||
</div> | ||
</div> | ||
{/if} | ||
</div> | ||
<div class="mt-auto flex flex-col items-stretch gap-3"> | ||
<Button | ||
onclick={handleSubmit} | ||
variant="primary" | ||
size="lg" | ||
type="submit" | ||
disabled={name.length === 0 || name.length > 32 || loading} | ||
> | ||
{#if loading} | ||
<ProgressRing /> | ||
{/if} | ||
<span>Save changes</span> | ||
</Button> | ||
</div> | ||
</form> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The checkbox still presented itself as clickable even though it was disabled...