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: add validate input on blur #8091

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions packages/shared/components/SelectorInput.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import { Modal, TextInput, Text, TextType, FontWeight, IOption } from 'shared/components'
import { fade } from 'svelte/transition'
import { truncateString } from '@core/utils'
import { createEventDispatcher } from 'svelte'

export let labelLocale: string
export let options: IOption[]
Expand All @@ -16,6 +17,8 @@
// If the attribute is set to false, HTML interprets it as a readonly field.
export let readonly: boolean | null = null

const dispatch = createEventDispatcher()

let value: string = selected?.key ?? selected?.value ?? ''
let previousValue: string = value
let hasFocus: boolean
Expand Down Expand Up @@ -73,6 +76,7 @@
placeholder={localize(labelLocale)}
fontSize="sm"
{readonly}
on:blur={() => dispatch('blur')}
{...$$restProps}
>
<div slot="right">
Expand Down
4 changes: 4 additions & 0 deletions packages/shared/components/inputs/AmountInput.svelte
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<script lang="ts">
import { NumberInput, FontWeight } from 'shared/components'
import { createEventDispatcher } from 'svelte'

export let inputElement: HTMLInputElement | undefined = undefined
export let fontSize = 24
Expand All @@ -8,6 +9,8 @@
export let hasFocus = false
export let amount: string = ''

const dispatch = createEventDispatcher()

$: amount, addLeadingZeroToDecimalSeparator()

function addLeadingZeroToDecimalSeparator(): void {
Expand All @@ -26,5 +29,6 @@
{fontSize}
alignment="right"
{fontWeight}
on:blur={() => dispatch('blur')}
{...$$restProps}
/>
1 change: 1 addition & 0 deletions packages/shared/components/inputs/AssetAmountInput.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@
clearPadding
clearBorder
{disabled}
on:blur={() => validate()?.catch((err) => console.error(err))}
/>
{#if getUnitFromTokenMetadata(asset?.metadata)}
<UnitInput bind:unit bind:isFocused {disabled} tokenMetadata={asset?.metadata} />
Expand Down
5 changes: 4 additions & 1 deletion packages/shared/components/inputs/Input.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,10 @@
on:paste={onPaste}
on:contextmenu={handleContextMenu}
on:focus={() => (hasFocus = true)}
on:blur={() => (hasFocus = false)}
on:blur={() => {
hasFocus = false
dispatch('blur')
}}
on:change={() => dispatch('change')}
{disabled}
{placeholder}
Expand Down
4 changes: 4 additions & 0 deletions packages/shared/components/inputs/NumberInput.svelte
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
<script lang="ts">
import { TextInput } from 'shared/components'
import { localize } from '@core/i18n'
import { createEventDispatcher } from 'svelte'

export let inputElement: HTMLInputElement = undefined

export let disabled = false
export let hasFocus = false
export let value: string
export let isInteger: boolean

const dispatch = createEventDispatcher()
</script>

<TextInput
Expand All @@ -18,6 +21,7 @@
placeholder={localize('general.amount')}
float={!isInteger}
integer={isInteger}
on:blur={() => dispatch('blur')}
{...$$restProps}
>
<slot name="right-full-h" slot="right-full-h" />
Expand Down
1 change: 1 addition & 0 deletions packages/shared/components/inputs/RecipientInput.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@
{disabled}
options={accountOptions}
pickerHeight="max-h-48"
on:blur={() => validate()?.catch((err) => console.error(err))}
{...$$restProps}
let:option
>
Expand Down
15 changes: 14 additions & 1 deletion packages/shared/components/inputs/TextInput.svelte
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<script lang="ts">
import { createEventDispatcher } from 'svelte'
import Input from './Input.svelte'
import { FontWeight, InputType, TextPropTypes, TextType } from 'shared/components'

Expand All @@ -15,11 +16,23 @@
export let fontSize = 'sm'
export let lineHeight = '140'

const dispatch = createEventDispatcher()

let textProps: TextPropTypes
$: textProps = { type: textType, fontSize, lineHeight, fontWeight }
</script>

<Input bind:inputElement bind:value bind:hasFocus bind:error type={inputType} {textProps} {alignment} {...$$restProps}>
<Input
bind:inputElement
bind:value
bind:hasFocus
bind:error
type={inputType}
{textProps}
{alignment}
on:blur={() => dispatch('blur')}
{...$$restProps}
>
<slot name="left" slot="left" />
<slot name="right" slot="right" />
<slot name="right-full-h" slot="right-full-h" />
Expand Down