mirror of
https://github.com/carbon-design-system/carbon-components-svelte.git
synced 2025-09-14 18:01:06 +00:00
Merge pull request #50 from metonym/fix-text-input
fix(password-input): mark passwordIsVisible as reactive
This commit is contained in:
commit
422ac528a7
4 changed files with 19 additions and 41 deletions
|
@ -16,17 +16,14 @@
|
||||||
export let tooltipAlignment = 'center';
|
export let tooltipAlignment = 'center';
|
||||||
export let hidePasswordLabel = 'Hide password';
|
export let hidePasswordLabel = 'Hide password';
|
||||||
export let showPasswordLabel = 'Show password';
|
export let showPasswordLabel = 'Show password';
|
||||||
export let props = {};
|
export let style = undefined;
|
||||||
|
|
||||||
import { createEventDispatcher } from 'svelte';
|
|
||||||
import WarningFilled16 from 'carbon-icons-svelte/lib/WarningFilled16';
|
import WarningFilled16 from 'carbon-icons-svelte/lib/WarningFilled16';
|
||||||
import View16 from 'carbon-icons-svelte/lib/View16';
|
import View16 from 'carbon-icons-svelte/lib/View16';
|
||||||
import ViewOff16 from 'carbon-icons-svelte/lib/ViewOff16';
|
import ViewOff16 from 'carbon-icons-svelte/lib/ViewOff16';
|
||||||
import { cx } from '../../lib';
|
import { cx } from '../../lib';
|
||||||
|
|
||||||
const dispatch = createEventDispatcher();
|
|
||||||
const errorId = `${id}-error`;
|
const errorId = `${id}-error`;
|
||||||
const passwordIsVisible = type === 'text';
|
|
||||||
const _labelClass = cx(
|
const _labelClass = cx(
|
||||||
'--label',
|
'--label',
|
||||||
hideLabel && '--visually-hidden',
|
hideLabel && '--visually-hidden',
|
||||||
|
@ -48,13 +45,14 @@
|
||||||
tooltipPosition && `--tooltip--${tooltipPosition}`,
|
tooltipPosition && `--tooltip--${tooltipPosition}`,
|
||||||
tooltipAlignment && `--tooltip--align-${tooltipAlignment}`
|
tooltipAlignment && `--tooltip--align-${tooltipAlignment}`
|
||||||
);
|
);
|
||||||
|
|
||||||
|
$: passwordIsVisible = type === 'text';
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<div class={cx('--form-item', '--text-input-wrapper', '--password-input-wrapper')}>
|
<div class={cx('--form-item', '--text-input-wrapper', '--password-input-wrapper')} {style}>
|
||||||
{#if labelText}
|
{#if labelText}
|
||||||
<label for={id} class={_labelClass}>{labelText}</label>
|
<label for={id} class={_labelClass}>{labelText}</label>
|
||||||
{/if}
|
{/if}
|
||||||
|
|
||||||
{#if helperText}
|
{#if helperText}
|
||||||
<div class={_helperTextClass}>{helperText}</div>
|
<div class={_helperTextClass}>{helperText}</div>
|
||||||
{/if}
|
{/if}
|
||||||
|
@ -63,23 +61,12 @@
|
||||||
<WarningFilled16 class={cx('--text-input__invalid-icon')} />
|
<WarningFilled16 class={cx('--text-input__invalid-icon')} />
|
||||||
{/if}
|
{/if}
|
||||||
<input
|
<input
|
||||||
{...props}
|
|
||||||
class={_textInputClass}
|
class={_textInputClass}
|
||||||
on:click={event => {
|
on:click
|
||||||
if (!disabled) {
|
on:change
|
||||||
dispatch('click', event);
|
on:input
|
||||||
}
|
|
||||||
}}
|
|
||||||
on:change={event => {
|
|
||||||
if (!disabled) {
|
|
||||||
dispatch('change', event);
|
|
||||||
}
|
|
||||||
}}
|
|
||||||
on:input={event => {
|
on:input={event => {
|
||||||
value = event.target.value;
|
value = event.target.value;
|
||||||
if (!disabled) {
|
|
||||||
dispatch('input', event);
|
|
||||||
}
|
|
||||||
}}
|
}}
|
||||||
data-invalid={invalid || undefined}
|
data-invalid={invalid || undefined}
|
||||||
aria-invalid={invalid || undefined}
|
aria-invalid={invalid || undefined}
|
||||||
|
|
|
@ -2,14 +2,14 @@
|
||||||
let className = undefined;
|
let className = undefined;
|
||||||
export { className as class };
|
export { className as class };
|
||||||
export let hideLabel = false;
|
export let hideLabel = false;
|
||||||
export let props = {};
|
export let style = undefined;
|
||||||
|
|
||||||
import { cx } from '../../lib';
|
import { cx } from '../../lib';
|
||||||
|
|
||||||
const _class = cx('--form-item', className);
|
const _class = cx('--form-item', className);
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<div {...props} class={_class}>
|
<div on:click on:mouseover on:mouseenter on:mouseleave class={_class} {style}>
|
||||||
{#if !hideLabel}
|
{#if !hideLabel}
|
||||||
<span class={cx('--label', '--skeleton')} />
|
<span class={cx('--label', '--skeleton')} />
|
||||||
{/if}
|
{/if}
|
||||||
|
|
|
@ -36,6 +36,11 @@
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
{:else}
|
{:else}
|
||||||
<TextInput {...$$props} bind:value />
|
<TextInput
|
||||||
|
{...$$props}
|
||||||
|
bind:value
|
||||||
|
on:change={() => {
|
||||||
|
console.log('change');
|
||||||
|
}} />
|
||||||
{/if}
|
{/if}
|
||||||
</Layout>
|
</Layout>
|
||||||
|
|
|
@ -12,13 +12,11 @@
|
||||||
export let helperText = '';
|
export let helperText = '';
|
||||||
export let hideLabel = false;
|
export let hideLabel = false;
|
||||||
export let light = false;
|
export let light = false;
|
||||||
export let props = {};
|
export let style = undefined;
|
||||||
|
|
||||||
import { createEventDispatcher } from 'svelte';
|
|
||||||
import WarningFilled16 from 'carbon-icons-svelte/lib/WarningFilled16';
|
import WarningFilled16 from 'carbon-icons-svelte/lib/WarningFilled16';
|
||||||
import { cx } from '../../lib';
|
import { cx } from '../../lib';
|
||||||
|
|
||||||
const dispatch = createEventDispatcher();
|
|
||||||
const errorId = `${id}-error`;
|
const errorId = `${id}-error`;
|
||||||
const _labelClass = cx(
|
const _labelClass = cx(
|
||||||
'--label',
|
'--label',
|
||||||
|
@ -34,7 +32,7 @@
|
||||||
);
|
);
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<div class={cx('--form-item', '--text-input-wrapper')}>
|
<div class={cx('--form-item', '--text-input-wrapper')} {style}>
|
||||||
{#if labelText}
|
{#if labelText}
|
||||||
<label for={id} class={_labelClass}>{labelText}</label>
|
<label for={id} class={_labelClass}>{labelText}</label>
|
||||||
{/if}
|
{/if}
|
||||||
|
@ -46,23 +44,11 @@
|
||||||
<WarningFilled16 class={cx('--text-input__invalid-icon')} />
|
<WarningFilled16 class={cx('--text-input__invalid-icon')} />
|
||||||
{/if}
|
{/if}
|
||||||
<input
|
<input
|
||||||
{...props}
|
|
||||||
class={_textInputClass}
|
class={_textInputClass}
|
||||||
on:click={event => {
|
on:click
|
||||||
if (!disabled) {
|
on:change
|
||||||
dispatch('click', event);
|
|
||||||
}
|
|
||||||
}}
|
|
||||||
on:change={event => {
|
|
||||||
if (!disabled) {
|
|
||||||
dispatch('change', event);
|
|
||||||
}
|
|
||||||
}}
|
|
||||||
on:input={event => {
|
on:input={event => {
|
||||||
value = event.target.value;
|
value = event.target.value;
|
||||||
if (!disabled) {
|
|
||||||
dispatch('input', event);
|
|
||||||
}
|
|
||||||
}}
|
}}
|
||||||
data-invalid={invalid || undefined}
|
data-invalid={invalid || undefined}
|
||||||
aria-invalid={invalid || undefined}
|
aria-invalid={invalid || undefined}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue