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

feat(frontend): sets autofocus on select field on desktop #4456

Merged
merged 23 commits into from
Feb 3, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
100b7a9
adds autofocus to InputTextWithAction component
BonomoAlessandro Jan 27, 2025
7b7bd36
fix lint issues
BonomoAlessandro Jan 27, 2025
2c4b9fc
🤖 Apply formatting changes
github-actions[bot] Jan 27, 2025
b673abe
fix lint issues
BonomoAlessandro Jan 27, 2025
dc3fd9b
adds device utils
BonomoAlessandro Jan 27, 2025
8f5b407
🤖 Apply formatting changes
github-actions[bot] Jan 27, 2025
57abaf1
adds custom type
BonomoAlessandro Jan 27, 2025
64d6132
fixes lint issues
BonomoAlessandro Jan 27, 2025
0d9a3db
fixes lint issues
BonomoAlessandro Jan 27, 2025
2dd2731
fixes lint issues
BonomoAlessandro Jan 27, 2025
26c5272
Merge branch 'main' into feature(frontend)/autofocus-search-fields
BonomoAlessandro Jan 27, 2025
3f3f438
updates device.utils.ts
BonomoAlessandro Jan 29, 2025
a4e11d0
adds return value
BonomoAlessandro Jan 29, 2025
a0d9c87
implements test cases for the device utils
BonomoAlessandro Jan 29, 2025
329f42a
removes unused code
BonomoAlessandro Jan 29, 2025
80c2049
🤖 Apply formatting changes
github-actions[bot] Jan 29, 2025
8628f84
Merge remote-tracking branch 'origin/main' into feature(frontend)/aut…
BonomoAlessandro Jan 29, 2025
7e359ff
adds auto select code
BonomoAlessandro Jan 29, 2025
1d645dd
updates gix components dependency
BonomoAlessandro Feb 3, 2025
38837be
🤖 Apply formatting changes
github-actions[bot] Feb 3, 2025
4c1771d
resolves lint issue
BonomoAlessandro Feb 3, 2025
1a3d7b2
Merge branch 'main' into feature(frontend)/autofocus-search-fields
BonomoAlessandro Feb 3, 2025
adf85c8
Merge branch 'main' into feature(frontend)/autofocus-search-fields
BonomoAlessandro Feb 3, 2025
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
2 changes: 2 additions & 0 deletions src/frontend/src/lib/components/manage/ManageTokens.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import type { ExchangesData } from '$lib/types/exchange';
import type { Token } from '$lib/types/token';
import type { TokenToggleable } from '$lib/types/token-toggleable';
import { isDesktop } from '$lib/utils/device.utils';
import { replacePlaceholders } from '$lib/utils/i18n.utils';
import { filterTokensForSelectedNetwork } from '$lib/utils/network.utils';
import { filterTokens, pinEnabledTokensAtTop, sortTokens } from '$lib/utils/tokens.utils';
Expand Down Expand Up @@ -143,6 +144,7 @@
bind:filter
noMatch={noTokensMatch}
placeholder={$i18n.tokens.placeholder.search_token}
autofocus={isDesktop()}
/>
</div>

Expand Down
2 changes: 2 additions & 0 deletions src/frontend/src/lib/components/swap/SwapTokensList.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import { i18n } from '$lib/stores/i18n.store';
import { SWAP_CONTEXT_KEY, type SwapContext } from '$lib/stores/swap.store';
import type { Token } from '$lib/types/token';
import { isDesktop } from '$lib/utils/device.utils';
import { filterTokens, pinTokensWithBalanceAtTop } from '$lib/utils/tokens.utils';

const { sourceToken, destinationToken } = getContext<SwapContext>(SWAP_CONTEXT_KEY);
Expand Down Expand Up @@ -40,6 +41,7 @@
bind:filter
noMatch={noTokensMatch}
placeholder={$i18n.tokens.placeholder.search_token}
autofocus={isDesktop()}
/>

<div class="my-6 flex flex-col overflow-y-hidden sm:max-h-[26rem]">
Expand Down
3 changes: 2 additions & 1 deletion src/frontend/src/lib/components/ui/InputSearch.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@
export let filter = '';
export let noMatch = false;
export let placeholder: string;
export let autofocus = false;
</script>

<InputTextWithAction name="filter" required={false} bind:value={filter} {placeholder}>
<InputTextWithAction name="filter" required={false} bind:value={filter} {placeholder} {autofocus}>
<svelte:fragment slot="inner-end">
{#if noMatch}
<button on:click={() => (filter = '')} aria-label={$i18n.core.text.clear_filter}>
Expand Down
12 changes: 12 additions & 0 deletions src/frontend/src/lib/components/ui/InputTextWithAction.svelte
Original file line number Diff line number Diff line change
@@ -1,11 +1,22 @@
<script lang="ts">
import { Input } from '@dfinity/gix-components';
import { nonNullish } from '@dfinity/utils';
import { onMount } from 'svelte';

export let value = '';
export let name: string;
export let placeholder: string;
export let required = true;
export let testId: string | undefined = undefined;
export let autofocus = false;
peterpeterparker marked this conversation as resolved.
Show resolved Hide resolved

let inputElement: HTMLInputElement | undefined;

onMount(() => {
peterpeterparker marked this conversation as resolved.
Show resolved Hide resolved
if (autofocus && nonNullish(inputElement)) {
inputElement.focus();
Copy link
Member

Choose a reason for hiding this comment

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

Just a note—I assume you tested this after the change in Gix components.

Spontaneously, I would rather use an auto-subscriber, as I'm not sure the reference to the DOM element would always be established when the component is mounted. But I'm probably just being paranoid. ;)

}
});
</script>

<Input
Expand All @@ -18,6 +29,7 @@
autocomplete="off"
{testId}
on:nnsInput
bind:inputElement
>
<slot name="inner-end" slot="inner-end" />
</Input>